我使用 BuddyPress 插件運行 WordPress 5.1.1。基本上我想要做的是,將用戶從自定義登錄鏈接重定向到他們在 BuddyPress 中的個人資料頁面。我已經(jīng)閱讀并檢查了 Stackoverflow 上為我的類似查詢提供的幾乎所有代碼,但沒有人在我的網(wǎng)站上工作過。唯一的代碼在下面起作用,但它對我的站點設置和設置有一個問題。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);問題是,當我想在網(wǎng)站主頁上重定向時,它一直在 BuddyPress 個人資料上重定向我。類別和帖子部分正在正確加載。所以,我需要的是,當?shù)卿浟髦囟ㄏ蛴脩粼谒麄兊?BuddyPress 個人資料頁面上時,在用戶點擊網(wǎng)站主頁加載網(wǎng)站主頁后,而不是 BuddyPress。我希望有人能以這種方式幫助和調(diào)整功能。
2 回答

臨摹微笑
TA貢獻1982條經(jīng)驗 獲得超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*/
}
測試代碼放入您的活動主題功能文件中
- 2 回答
- 0 關(guān)注
- 249 瀏覽
添加回答
舉報
0/150
提交
取消