几天来,我一直在尝试将刚刚注册到我的WordPress站点的用户自动登录,然后将他们重定向到我选择的URL。
默认情况下,WordPress向您发送用户名和密码,然后您必须手动登录。这是一种完全的痛苦。我怎样才能克服这一切。
我有自己的注册页面(core页面),它成功地将用户添加到DB中。但关键是,我应该避免用户再次登录。
一旦注册完成,它应该自动redirects到主页或配置文件页面。
我是一个新的wordpress功能。如果有人(了解wordpress的核心功能)至少能给出一个解决方案,我会很感激的。
展望未来。
谢谢
发布于 2013-11-18 06:59:38
感谢你们的支持,我用下面的code..thanks为你们提供了时间和支持:)
<i>$getdetails= mysql_fetch_array(mysql_query("SELECT * FROM `wp_users` WHERE `ID`='$user_id'"));
$username=$getdetails['user_login'];
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ){
echo $user->get_error_message();
}else{
wp_redirect( home_url() );
}发布于 2013-11-15 09:39:51
注册并重定向到主页后,//添加用于自动登录的function.php。改变了这个代码
function auto_login_new_user( $user_id ) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
$user = get_user_by( 'id', $user_id );
do_action( 'wp_login', $user->user_login );//`[Codex Ref.][1]
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' );发布于 2013-11-13 14:07:22
以下是WooCommerce如何创建新用户并将其登录的方式:
$user_pass = esc_attr( $_POST['account_password'] );
$new_user_data = array(
'user_login' => $_POST['account_username'],
'user_pass' => $user_pass,
'user_email' => $_POST['account_email'],
'role' => 'subscriber'
);
$user_id = wp_insert_user( $new_user_data );
// Set the global user object
$current_user = get_user_by( 'id', $user_id );
// set the WP login cookie
$secure_cookie = is_ssl() ? true : false;
wp_set_auth_cookie( $user_id, true, $secure_cookie );要重定向使用wp_safe_redirect,例如:
wp_safe_redirect( home_url( '/' ) );
exit;https://stackoverflow.com/questions/19949876
复制相似问题