bbPress: Email Moderators About Posts Waiting for Approval
Emails forum moderators and keymasters when a topic or reply lands in the pending queue (for example from Akismet or moderation rules), so nothing waits for days.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_get_pending_status_id' ) ) {
return;
}
$wpide_bbp_pending_alert = function ( $post_id ) {
if ( bbp_get_pending_status_id() !== get_post_status( $post_id ) || get_transient( 'wpide_bbp_pending_alert' ) ) {
return;
}
set_transient( 'wpide_bbp_pending_alert', 1, 15 * MINUTE_IN_SECONDS );
$emails = get_users( array( 'role__in' => array( 'bbp_keymaster', 'bbp_moderator' ), 'fields' => array( 'user_email' ), 'number' => 20 ) );
$emails = wp_list_pluck( $emails, 'user_email' );
if ( ! $emails ) {
$emails = array( get_option( 'admin_email' ) );
}
wp_mail(
$emails,
'Forum posts are waiting for approval',
sprintf( "A new forum post is waiting for moderation:\n%s\n\nAll pending topics: %s", get_permalink( $post_id ), admin_url( 'edit.php?post_type=' . bbp_get_topic_post_type() . '&post_status=' . bbp_get_pending_status_id() ) )
);
};
add_action( 'bbp_new_topic', $wpide_bbp_pending_alert );
add_action( 'bbp_new_reply', $wpide_bbp_pending_alert );
Notes
Sends at most one email every 15 minutes to avoid floods during spam waves.
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.