Make WordPress Core

Changeset 29763


Ignore:
Timestamp:
09/23/2014 06:48:31 PM (12 years ago)
Author:
DrewAPicture
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r29762 r29763  
    4040        global $wpdb;
    4141
     42        // If manual moderation is enabled, skip all checks and return false.
    4243        if ( 1 == get_option('comment_moderation') )
    43                 return false; // If moderation is set to manual
     44                return false;
    4445
    4546        /** This filter is documented in wp-includes/comment-template.php */
    4647        $comment = apply_filters( 'comment_text', $comment );
    4748
    48         // Check # of external links
     49        // Check for the number of external links if a max allowed number is set.
    4950        if ( $max_links = get_option( 'comment_max_links' ) ) {
    5051                $num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out );
     52
    5153                /**
    5254                 * Filter the maximum number of links allowed in a comment.
    … …  
    5860                 */
    5961                $num_links = apply_filters( 'comment_max_links_url', $num_links, $url );
     62
     63                /*
     64                 * If the number of links in the comment exceeds the allowed amount,
     65                 * fail the check by returning false.
     66                 */
    6067                if ( $num_links >= $max_links )
    6168                        return false;
    … …  
    6370
    6471        $mod_keys = trim(get_option('moderation_keys'));
     72
     73        // If moderation 'keys' (keywords) are set, process them.
    6574        if ( !empty($mod_keys) ) {
    6675                $words = explode("\n", $mod_keys );
    … …  
    6978                        $word = trim($word);
    7079
    71                         // Skip empty lines
     80                        // Skip empty lines.
    7281                        if ( empty($word) )
    7382                                continue;
    7483
    75                         // Do some escaping magic so that '#' chars in the
    76                         // spam words don't break things:
     84                        /*
     85                         * Do some escaping magic so that '#' (number of) characters in the spam
     86                         * words don't break things:
     87                         */
    7788                        $word = preg_quote($word, '#');
    7889
     90                        /*
     91                         * Check the comment fields for moderation keywords. If any are found,
     92                         * fail the check for the given field by returning false.
     93                         */
    7994                        $pattern = "#$word#i";
    8095                        if ( preg_match($pattern, $author) ) return false;
    … …  
    87102        }
    88103
    89         // Comment whitelisting:
     104        /*
     105         * Check if the option to approve comments by previously-approved authors is enabled.
     106         *
     107         * If it is enabled, check whether the comment author has a previously-approved comment,
     108         * as well as whether there are any moderation keywords (if set) present in the author
     109         * email address. If both checks pass, return true. Otherwise, return false.
     110         */
    90111        if ( 1 == get_option('comment_whitelist')) {
    91112                if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {
Note: See TracChangeset for help on using the changeset viewer.