Daily Digest of Comments Awaiting Moderation
Replaces the one-email-per-comment moderation notices with a single daily email listing every comment waiting for approval, with a link to the moderation screen.
Opens WPIDE on
Code
$wpide_digest_hour = 8; // Hour of the day (0-23, site time).
add_filter( 'notify_moderator', '__return_false' );
add_action( 'init', function () use ( $wpide_digest_hour ) {
if ( wp_next_scheduled( 'wpide_pending_comments_digest' ) ) {
return;
}
$next = new DateTime( 'today ' . $wpide_digest_hour . ':00', wp_timezone() );
if ( $next->getTimestamp() <= time() ) {
$next->modify( '+1 day' );
}
wp_schedule_event( $next->getTimestamp(), 'daily', 'wpide_pending_comments_digest' );
} );
add_action( 'wpide_pending_comments_digest', function () {
$comments = get_comments( array( 'status' => 'hold', 'type' => 'comment', 'number' => 50, 'orderby' => 'comment_date_gmt', 'order' => 'DESC' ) );
if ( ! $comments ) {
return;
}
$total = (int) get_comments( array( 'status' => 'hold', 'type' => 'comment', 'count' => true ) );
$lines = array( sprintf( '%d comment(s) are waiting for your approval:', $total ), '' );
foreach ( $comments as $comment ) {
$lines[] = sprintf( '• %s on "%s": %s', $comment->comment_author, wp_strip_all_tags( get_the_title( $comment->comment_post_ID ) ), wp_html_excerpt( wp_strip_all_tags( $comment->comment_content ), 120, '…' ) );
}
$lines[] = '';
$lines[] = 'Moderate them: ' . admin_url( 'edit-comments.php?comment_status=moderated' );
wp_mail( get_option( 'admin_email' ), sprintf( '[%s] %d comment(s) awaiting moderation', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $total ), implode( "\n", $lines ) );
} );
Notes
Sent at the hour set at the top (site time) only when comments are waiting; goes to the admin email address.
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.