Improve and clarify inline commenting inside the check_comment()
function.
Adds logical explanations of what some of the various comment checks are checking for, as well as some general cleanup and syntax fixes. Fixes #29734. git-svn-id: https://develop.svn.wordpress.org/trunk@29763 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0adb5f14aa
commit
198db28c17
@ -39,15 +39,17 @@
|
|||||||
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
|
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
// If manual moderation is enabled, skip all checks and return false.
|
||||||
if ( 1 == get_option('comment_moderation') )
|
if ( 1 == get_option('comment_moderation') )
|
||||||
return false; // If moderation is set to manual
|
return false;
|
||||||
|
|
||||||
/** This filter is documented in wp-includes/comment-template.php */
|
/** This filter is documented in wp-includes/comment-template.php */
|
||||||
$comment = apply_filters( 'comment_text', $comment );
|
$comment = apply_filters( 'comment_text', $comment );
|
||||||
|
|
||||||
// Check # of external links
|
// Check for the number of external links if a max allowed number is set.
|
||||||
if ( $max_links = get_option( 'comment_max_links' ) ) {
|
if ( $max_links = get_option( 'comment_max_links' ) ) {
|
||||||
$num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out );
|
$num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the maximum number of links allowed in a comment.
|
* Filter the maximum number of links allowed in a comment.
|
||||||
*
|
*
|
||||||
@ -57,25 +59,38 @@ function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $
|
|||||||
* @param string $url Comment author's URL. Included in allowed links total.
|
* @param string $url Comment author's URL. Included in allowed links total.
|
||||||
*/
|
*/
|
||||||
$num_links = apply_filters( 'comment_max_links_url', $num_links, $url );
|
$num_links = apply_filters( 'comment_max_links_url', $num_links, $url );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the number of links in the comment exceeds the allowed amount,
|
||||||
|
* fail the check by returning false.
|
||||||
|
*/
|
||||||
if ( $num_links >= $max_links )
|
if ( $num_links >= $max_links )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mod_keys = trim(get_option('moderation_keys'));
|
$mod_keys = trim(get_option('moderation_keys'));
|
||||||
|
|
||||||
|
// If moderation 'keys' (keywords) are set, process them.
|
||||||
if ( !empty($mod_keys) ) {
|
if ( !empty($mod_keys) ) {
|
||||||
$words = explode("\n", $mod_keys );
|
$words = explode("\n", $mod_keys );
|
||||||
|
|
||||||
foreach ( (array) $words as $word) {
|
foreach ( (array) $words as $word) {
|
||||||
$word = trim($word);
|
$word = trim($word);
|
||||||
|
|
||||||
// Skip empty lines
|
// Skip empty lines.
|
||||||
if ( empty($word) )
|
if ( empty($word) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Do some escaping magic so that '#' chars in the
|
/*
|
||||||
// spam words don't break things:
|
* Do some escaping magic so that '#' (number of) characters in the spam
|
||||||
|
* words don't break things:
|
||||||
|
*/
|
||||||
$word = preg_quote($word, '#');
|
$word = preg_quote($word, '#');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check the comment fields for moderation keywords. If any are found,
|
||||||
|
* fail the check for the given field by returning false.
|
||||||
|
*/
|
||||||
$pattern = "#$word#i";
|
$pattern = "#$word#i";
|
||||||
if ( preg_match($pattern, $author) ) return false;
|
if ( preg_match($pattern, $author) ) return false;
|
||||||
if ( preg_match($pattern, $email) ) return false;
|
if ( preg_match($pattern, $email) ) return false;
|
||||||
@ -86,7 +101,13 @@ function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comment whitelisting:
|
/*
|
||||||
|
* Check if the option to approve comments by previously-approved authors is enabled.
|
||||||
|
*
|
||||||
|
* If it is enabled, check whether the comment author has a previously-approved comment,
|
||||||
|
* as well as whether there are any moderation keywords (if set) present in the author
|
||||||
|
* email address. If both checks pass, return true. Otherwise, return false.
|
||||||
|
*/
|
||||||
if ( 1 == get_option('comment_whitelist')) {
|
if ( 1 == get_option('comment_whitelist')) {
|
||||||
if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {
|
if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {
|
||||||
// expected_slashed ($author, $email)
|
// expected_slashed ($author, $email)
|
||||||
|
Loading…
Reference in New Issue
Block a user