Php 将用户重定向到用户名为wordpress的url
我想根据用户名在登录后重定向用户Php 将用户重定向到用户名为wordpress的url,php,wordpress,authentication,redirect,Php,Wordpress,Authentication,Redirect,我想根据用户名在登录后重定向用户 add_filter( 'login_redirect', 'wppbc_custom_login_redirect', 99, 3 ); function wppbc_custom_login_redirect( $redirect_to, $requested_redirect_to, $user ) { if( is_wp_error( $user ) ) { return $redirect_to; } $username
add_filter( 'login_redirect', 'wppbc_custom_login_redirect', 99, 3 );
function wppbc_custom_login_redirect( $redirect_to, $requested_redirect_to,
$user ) {
if( is_wp_error( $user ) ) {
return $redirect_to;
}
$username = $user->user_login;
if ( is_array( $form_args ) ) {
switch ( $username ) {
case 'User1':
$redirect_to = 'https://www.example.com/User1';
break;
case 'User2':
$redirect_to = 'https://www.example.com/User2';
break;
default:
$redirect_to = 'https://www.example.com';
}
}
return $redirect_to;
}
唯一的问题是,不,我必须手动将每个用户添加到此列表中,并在成功登录后将其重定向到该域。我想要一个单一的代码,我可以添加用户名变量到域
用户名x已成功登录,并将重定向到www.example.com/x
用户名y成功登录,并将重定向到www.example.com/y
有人能帮我写这段代码吗?你不能这样做
在服务器处理该值之前,必须将javascript变量发回服务器。为此,您可以编写一个提交表单的javascript函数,也可以使用ajax/jquery。jQuery.post
也许对你来说最简单的方法就是这样
function myJavascriptFunction() {
var javascriptVariable = "John";
window.location.href = "myphpfile.php?name=" + javascriptVariable;
}
在myphpfile.php上,可以在执行javascript后使用$\u GET['name']https://www.example.com/' . $用户名代码>仅在url末尾添加用户名