I have a custom WP registration script that works nicely, although I can't get it to automatically login the user. I can confirm that it creates the user profile. I've also tried triggering wp_signon() with no luck. Any suggestions?
<?php
function complete_registration() {
global $reg_errors, $username, $password, $email;
if ( 1 > count( $reg_errors->get_error_messages() ) ) {
$data = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password
);
$user = wp_insert_user( $data );
if(!is_wp_error($user))
wp_set_current_user($user);
wp_set_auth_cookie($user);
}
}
?>
函数在执行链中触发太晚。
对本教程中的自定义注册表具有相同的功能,并希望对自动登录使用相同的选项,但它也不起作用,因为标头已经发送..所以只需添加此代码,它就会起作用..
add_action('init', 'custom_registration_shortcode');
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.