好的,我有代码可以将登录用户重定向到他们的 BuddyPress 个人资料;但是,我还需要:
问题如何:
为同一页面添加重定向#78,以便未登录的用户转到:/login
function buddyforms_redirect_a_page_to_the_buddypress_profile() {
if( is_page( 78 ) ) {
if(is_user_logged_in()){
wp_safe_redirect( bp_loggedin_user_domain() );
exit;
}
}
}
add_action( 'wp', 'buddyforms_redirect_a_page_to_the_buddypress_profile' );
请查看下面我的示例。我为未登录的用户添加了 else 条件。
function buddyforms_redirect_a_page_to_the_buddypress_profile() {
if( is_page( 78 ) ) {
if(is_user_logged_in()){
wp_safe_redirect( bp_loggedin_user_domain() );
exit;
} else {
wp_safe_redirect( wp_login_url() );
exit;
}
}
}
add_action( 'wp', 'buddyforms_redirect_a_page_to_the_buddypress_profile' );