bbPress: Hold Posts From New Members for Moderation
Puts topics and replies from members who joined recently, or who have few approved posts, into the pending queue until a moderator approves them.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_get_pending_status_id' ) ) {
return;
}
// Hold posts until the member is this many days old or has this many approved replies.
$wpide_bbp_trust_days = 3;
$wpide_bbp_trust_replies = 2;
$wpide_bbp_hold = function ( $data ) use ( $wpide_bbp_trust_days, $wpide_bbp_trust_replies ) {
$author = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
if ( ! $author || user_can( $author, 'moderate' ) ) {
return $data;
}
$user = get_userdata( $author );
if ( ! $user || time() - strtotime( $user->user_registered . ' UTC' ) > $wpide_bbp_trust_days * DAY_IN_SECONDS ) {
return $data;
}
if ( (int) bbp_get_user_reply_count( $author, true ) >= $wpide_bbp_trust_replies ) {
return $data;
}
$data['post_status'] = bbp_get_pending_status_id();
return $data;
};
add_filter( 'bbp_new_topic_pre_insert', $wpide_bbp_hold );
add_filter( 'bbp_new_reply_pre_insert', $wpide_bbp_hold );
Notes
Members are trusted once they pass either limit. Moderators and keymasters are never held.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.