为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
qq_笑_17 2021-06-08 17:47:13
我使用 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。我希望有人能以这种方式帮助和调整功能。
查看完整描述

2 回答

?
临摹微笑

TA贡献1982条经验 获得超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 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*/


}

测试代码放入您的活动主题功能文件中


查看完整回答
反对 回复 2021-06-13
  • 2 回答
  • 0 关注
  • 231 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信