简体   繁体   English

自定义注册后WordPress自动登录

[英]WordPress Auto Login After Custom Registration

I have a custom WP registration script that works nicely, although I can't get it to automatically login the user.我有一个很好用的自定义 WP 注册脚本,尽管我无法让它自动登录用户。 I can confirm that it creates the user profile.我可以确认它创建了用户配置文件。 I've also tried triggering wp_signon() with no luck.我也试过在没有运气的情况下触发 wp_signon() 。 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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM