i使用BuddyPress插件运行WordPress 5.1.1。
基本上我想做的是,将用户从自定义登录链接重定向到Buddypress中的个人资料页面。
我已经阅读并检查了我类似查询的Stackoverflow上提供的几乎所有代码,但Non在我的网站上也有效。
唯一工作的代码在下面,但我的网站设置和设置有一个问题。
function bp_help_redirect_to_profile(){
global $bp;
if( is_user_logged_in() && is_front_page() ) {
bp_core_redirect( get_option('home') . '/members/' .
bp_core_get_username( bp_loggedin_user_id() ) . '/profile' );
}
}
add_action( 'get_header', 'bp_help_redirect_to_profile',1);
问题是,当我想重定向网站的主页时,它一直在将我重定向到BuddyPress个人资料。类别和帖子部分正正确加载。
所以,我需要的是,当登录流量重定向用户在其BuddyPress配置文件页面上,当用户登录网站以加载网站的主页以加载网站而不是BuddyPress时。
我希望有人可以以这种方式提供帮助并调整功能。
谢谢
add_filter( 'bp_login_redirect', 'bpdev_redirect_to_profile', 11, 3 );
function bpdev_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user )
{
if( empty( $redirect_to_calculated ) )
$redirect_to_calculated = admin_url();
//if the user is not site admin,redirect to his/her profile
if( isset( $user->ID) && ! is_super_admin( $user->ID ) )
return bp_core_get_user_domain( $user->ID );
else
return $redirect_to_calculated; /*if site admin or not logged in,do not do
anything much*/
}
测试的代码放入活动主题功能文件
您可以为此使用wp_login
操作。请检查以下示例。bp_core_get_user_domain()
将获取配置文件URL,成功登录后将被重定向到该配置文件URL。
function wpso_take_to_profile( $user_login, $user ) {
if ( function_exists( 'bp_core_get_user_domain' ) ) {
$url = bp_core_get_user_domain( $user->ID );
wp_redirect( $url );
die();
}
}
add_action('wp_login', 'wpso_take_to_profile', 10, 2);