25% off ProSNIPC25OFF

Hold Comments With Many Links

Automatically queues comments for moderation when they contain more than a configurable number of hyperlinks.

PHPby SnipCraft
php
<?php
add_filter( 'pre_comment_approved', 'scseed_hold_link_heavy_comments', 10, 2 );
if ( ! function_exists( 'scseed_hold_link_heavy_comments' ) ) {
    function scseed_hold_link_heavy_comments( $approved, $commentdata ) {
        // Maximum number of links before a comment is held for moderation.
        $max_links  = 2;
        $content    = isset( $commentdata['comment_content'] ) ? $commentdata['comment_content'] : '';
        $link_count = substr_count( strtolower( $content ), 'http' );
        if ( $link_count > $max_links ) {
            return '0'; // Hold in moderation queue.
        }
        return $approved;
    }
}
#comments#moderation#security#spam