BuddyBoss(BuddyPress/bbPress)审核过滤器不执行任何操作

时间:2021-08-09 作者:MarkPraschan

我正在努力prevent moderation of forum posts 适用于具有“中等”能力或积极的“高级”会员计划(WC会员资格)的用户。

我希望这些作者的回复不受我们的限制(链接数量、封锁词等)。

我尝试过使用以下过滤器,但没有成功:

add_filter( \'bbp_bypass_check_for_moderation\', \'bbp_bypass_if_user_can_moderate\', 10, 4 );

function bbp_bypass_if_user_can_moderate( $anonymous_data, $author_id, $title, $content ){
    if( user_can( $author_id, \'moderate\' ) || wc_memberships_is_user_active_member( $author_id, \'premium\' ) ){
        return true;
    } else {
        return false;
    }
}

add_filter( \'bp_bypass_check_for_moderation\', \'bp_bypass_if_user_can_moderate\', 10, 3 );

function bp_bypass_if_user_can_moderate( $user_id, $title, $content ){
    if( user_can( $user_id, \'moderate\' ) || wc_memberships_is_user_active_member( $user_id, \'premium\' ) ){
        return true;
    } else {
        return false;
    }
}
看起来上面的代码应该可以工作。我是否忽视了什么?

参考文献:

  • https://www.buddyboss.com/resources/reference/functions/bbp_check_for_moderation/
  • https://www.buddyboss.com/resources/reference/hooks/bp_bypass_check_for_moderation/
  • https://developer.wordpress.org/reference/functions/user_can/
  • https://docs.woocommerce.com/document/woocommerce-memberships-function-reference/#wc_memberships_is_user_active_member

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

经过多次尝试和错误,我终于找到了答案。

的文档bbp_bypass_check_for_moderation 是否缺少第一个参数($value). 以下是所有参数的工作代码:

/* Bypass moderation (bbPress) */
add_filter( \'bbp_bypass_check_for_moderation\', \'bbp_bypass_if_user_can_moderate\', 5, 5 );
function bbp_bypass_if_user_can_moderate( $value, $anonymous_data, $author_id, $title, $content ){
    if( user_can( $author_id, \'moderate\' ) || wc_memberships_is_user_active_member( $author_id, \'premium\' ) ){
        return true;
    } 
    return false;
}

/* Bypass moderation (BuddyPress) */
add_filter( \'bp_bypass_check_for_moderation\', \'bp_bypass_if_user_can_moderate\', 5, 4 );
function bp_bypass_if_user_can_moderate( $value, $user_id, $title, $content ){
    if( user_can( $author_id, \'moderate\' ) || wc_memberships_is_user_active_member( $author_id, \'premium\' ) ){
        return true;
    } 
    return false;
}

SO网友:Rup

bp\\u bypass\\u if\\u user\\u can\\u mediate参数错误。从…起the documentation you linked to 它应该是bool$value、int$user\\u id、string$title、string$content,对于过滤器来说,如果不打算更改它,则应该像往常一样传递$value。e、 g.以下是您的过滤器的固定版本:

add_filter( \'bp_bypass_check_for_moderation\',
            \'bbp_bypass_if_user_can_moderate\', 10, 4 );

function bbp_bypass_if_user_can_moderate( $value, $user_id, $title, $content ) {
    if ( ( !$value ) && ( user_can( $user_id, \'moderate\' ) ||
         wc_memberships_is_user_active_member( $user_id, \'premium\' ) ) ) {
        return true;
    }

    return $value;
}
但我不能肯定这会奏效。

相关推荐

BuddyPress返回错误的xprofile日期

一切正常,但突然间BuddyPress xprofiledate 字段之前给出一个日期。然而,我已经检查了数据库,输入是正确的。它只是返回了错误的日期。这意味着,如果我将日期设置为1920-12-12,它将存储正确的(相同),但返回1920-12-11。我使用以下BuddyPress函数获取日期。// tried by field id bp_get_profile_field_data([ \'field\' => 5, \'user_id\' =>