I am trying to make custom registration form in my wordpress site , the form is registered successfully but i couldn\'t login the user after registration and redirect to a custom url.
this is the code i have used
<?php
$err = \'\';
$success = \'\';
global $wpdb, $PasswordHash, $current_user, $user_ID;
if(isset($_POST[\'submit\']) ) {
$pwd1 = $wpdb->escape(trim($_POST[\'pwd1\']));
$pwd2 = $wpdb->escape(trim($_POST[\'pwd2\']));
$email = $wpdb->escape(trim($_POST[\'email\']));
$username = $wpdb->escape(trim($_POST[\'username\']));
if( $email == "" || $pwd1 == "" || $pwd2 == "" || $username == "") {
$err = \'Please don\\\'t leave the required fields.\';
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$err = \'Invalid email address.\';
} else if(email_exists($email) ) {
$err = \'Email already exist.\';
} else if($pwd1 <> $pwd2 ){
$err = \'Password do not match.\';
} else {
$user_id = wp_insert_user( array (\'user_pass\' => apply_filters(\'pre_user_user_pass\', $pwd1), \'user_login\' => apply_filters(\'pre_user_user_login\', $username), \'user_email\' => apply_filters(\'pre_user_user_email\', $email), \'role\' => \'subscriber\' ) );
if( is_wp_error($user_id) ) {
$error_string = $user_id->get_error_message();
$err = $error_string;
} else {
do_action(\'user_register\', $user_id);
wp_set_current_user($user_id); // set the current wp user
wp_set_auth_cookie($user_id); // start the cookie for the current registered user
wp_redirect( get_home_url() );
$success = \'You\\\'re successfully registered\';
}
}
}
?>
- I have tried using javascript for redirecting ,it doesn\'t help.
- what i\'am missing here?
I want redirect by login the user after registration