我有一个WordPress注册过程插件。没有密码字段,但我创建了密码字段并插入密码,而不是在电子邮件中发送随机密码。它使用wp_create_user函数来创建用户。WordPress插件注册后自动登录
现在,我正在尝试使注册后自动登录,但失败了。
我试了下面的功能,但是失败了。请有人帮忙。
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(home_url());
这是我一直在使用的过程,它并不完整,但我认为它必须工作。
$status = wp_create_user($username, $user_pass, $email);
$user_data = $wpdb->get_row("SELECT * FROM $users_table where user_login='$username' ");
$user_id = isset($user_data) ? $user_data->ID : 0;
if (is_wp_error($status)) {
$errors[] = language_code('USER_NAME_ALREADY_EXIST_PLEASE_TRY_ANOTHER_ONE');
} else {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
wp_redirect(home_url());
}
你可以分享你的代码,它很难检测到您试过怎么样了。 –
我已经在上面分享了一些代码。这不完整,但我已经做了如何显示。 – Nikx