check_comment [ WordPress Function ]
| Parameters: |
|
| Uses: |
|
| Returns: |
|
| Defined at: |
|
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.
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.
If the comment author was approved before, then the comment is automatically whitelisted.
If none of the checks fail, then the failback is to set the check to pass (return true).
Source
<?php
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;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/check comment « WordPress Codex
Description. check_comment() checks whether a comment passes internal checks set by WordPress Comment_Moderation.
codex.wordpress.org - check_comment() WordPress function reference, arguments and ...
Checks whether a comment passes internal checks to be allowed to add.
queryposts.com - check_comment | A HitchHackers guide through WordPress
Feb 11, 2011 ... Checks whether a comment passes internal checks to be allowed to add. If comment moderation is set in the administration, then all comments, ...
hitchhackerguide.com - How to show hook output in Tortoise Hg log window? - Stack Overflow
usr/bin/env python # # save as .hg/check_whitespace.py and make executable import re def check_comment(comment): # print 'Checking ...
stackoverflow.com