BuddyBoss (BuddyPress / bbPress) moderation filters not doing anything

I'm trying to prevent moderation of forum posts for users with the 'moderate' capability OR an active 'premium' membership plan (WC Memberships).

I want replies from such authors to not be subject to our moderation rules (number of links, blocklisted words, etc.).

I've tried using the following filters with no luck:

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;
    }
}

It seems like the above code should work. Am I overlooking something?

Reference:

  • 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

Topic bbpress buddypress moderation Wordpress

Category Web


After much trial and error, I was able to figure it out.

The documentation for bbp_bypass_check_for_moderation is missing the first parameter ($value). Here is the working code with all parameters:

/* 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;
}

You've got the bp_bypass_if_user_can_moderate arguments wrong. From the documentation you linked to it should be bool $value, int $user_id, string $title, string $content, and as normal for filters you should pass through $value if you're not going to change it. e.g. here's a fixed up version of your filter:

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;
}

I can't say for sure this will work though.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.