Definition:
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {}
Checks whether a comment passes internal checks to be allowed to add.
If comment moderation is set in the administration, then all comments, regardless of their type and whitelist will be set to false. If the number of links exceeds the amount in the administration, then the check fails. If any of the parameter contents match the blacklist of words, then the check fails.
Parameters
- string $author: Comment Author’s name
- string $email: Comment Author’s email
- string $url: Comment Author’s URL
- string $comment: Comment contents
- string $user_ip: Comment Author’s IP address
- string $user_agent: Comment Author’s User Agent
- string $comment_type: Comment type, either user submitted comment, trackback, or pingback
Return values
returns:Whether the checks passed (true) and the comments should be displayed or set to moderated
Defined filters
- comment_text
apply_filters( 'comment_text', $comment )
- comment_max_links_url
apply_filters( 'comment_max_links_url', $num_links, $url )
Source code
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { global $wpdb; if ( 1 == get_option('comment_moderation') ) return false; // If moderation is set to manual $comment = apply_filters( 'comment_text', $comment ); // Check # of external links if ( $max_links = get_option( 'comment_max_links' ) ) { $num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out ); $num_links = apply_filters( 'comment_max_links_url', $num_links, $url ); // provide for counting of $url as a link if ( $num_links >= $max_links ) return false; } $mod_keys = trim(get_option('moderation_keys')); if ( !empty($mod_keys) ) { $words = explode("\n", $mod_keys ); foreach ( (array) $words as $word) { $word = trim($word); // Skip empty lines if ( empty($word) ) continue; // Do some escaping magic so that '#' chars in the // spam words don't break things: $word = preg_quote($word, '#'); $pattern = "#$word#i"; if ( preg_match($pattern, $author) ) return false; if ( preg_match($pattern, $email) ) return false; if ( preg_match($pattern, $url) ) return false; if ( preg_match($pattern, $comment) ) return false; if ( preg_match($pattern, $user_ip) ) return false; if ( preg_match($pattern, $user_agent) ) return false; } } // Comment whitelisting: if ( 1 == get_option('comment_whitelist')) { if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) { // expected_slashed ($author, $email) $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1"); if ( ( 1 == $ok_to_comment ) && ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) return true; else return false; } else { return false; } } return true; }
601
No comments yet... Be the first to leave a reply!