I have built a registration form and I want make auto-login function code:
$query8="SELECT * FROM wpxr_users WHERE ID = '$user_id'";
$result8=mysqli_query($con,$query8);
if($result8) {
// here I want to login the user
}
You can check that:
function auto_login_new_user( $user_id ) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
wp_redirect( home_url() ); // You can change home_url() to the specific URL,such as "wp_redirect( 'http://www.wpcoke.com' )";
exit();
}
add_action( 'user_register', 'auto_login_new_user' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.