猿问

如何在登录到 WordPress 中的 BuddyPress 个人资料后重定向

我使用 BuddyPress 插件运行 WordPress 5.1.1。


基本上我想要做的是,将用户从自定义登录链接重定向到他们在 BuddyPress 中的个人资料页面。


我已经阅读并检查了 Stackoverflow 上为我的类似查询提供的几乎所有代码,但没有人在我的网站上工作过。


唯一的代码在下面起作用,但它对我的站点设置和设置有一个问题。


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。


我希望有人能以这种方式帮助和调整功能。


qq_笑_17
浏览 232回答 2
2回答

临摹微笑

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 profileif( 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*/}测试代码放入您的活动主题功能文件中
随时随地看视频慕课网APP
我要回答