重定向尝试查看组页面但不是组目录的未登录用户

时间:2021-08-18 作者:Nifty

我们希望将BuddyPress中未登录用户的所有组页面(但不是组目录页面/组/)重定向到/注册/页面。

我们目前正在函数中为成员概要文件使用此代码段。php文件:

/*** Redirect non logged-in users to registration page if they visit a profile page ***/
function gwangi_bp_logged_out_page_template_redirect()
{
    if( ! is_user_logged_in() && bp_is_user() ) {
        wp_redirect( home_url( \'/register/\' ) );
        exit();
    }
}
add_action( \'template_redirect\', \'gwangi_bp_logged_out_page_template_redirect\' );
是否有办法将其修改为也包括组页(不包括组目录/组/)?我们对如何进行这项工作既不确定也缺乏经验。

在此方面的任何帮助都将不胜感激!

谢谢

1 个回复
最合适的回答,由SO网友:Rup 整理而成

看起来像是bp_is_group() is“是”;当前页面是否属于单个组“;(与bp_is_groups_directory()):

/*** Redirect non logged-in users to registration page if they visit a profile page or a group page other than the groups directory ***/
function gwangi_bp_logged_out_page_template_redirect()
{
    if( ! is_user_logged_in() && ( bp_is_user() || bp_is_group() ) ) {
        wp_redirect( home_url( \'/register/\' ) );
        exit();
    }
}
add_action( \'template_redirect\', \'gwangi_bp_logged_out_page_template_redirect\' );
在src/bp-core/bp-core模板中有更多的bp\\u is\\u*函数。php。

相关推荐

BuddyPress活动流-删除/替换[...]摘自博客文章摘录

我正在寻找删除或替换[…]的方法在活动流上的博客文章摘录的末尾。我找到了替代[…]的方法在博客页面上使用以下代码。function new_excerpt_more( $more ) { return \'\'; } add_filter(\'excerpt_more\', \'new_excerpt_more\'); 摘录\\u more是WordPress过滤器。它对博客页面有帮助,但对BuddyPress活动流没有帮助。我找到了另一个过滤器,bp\\u ge