Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42228 r42343  
    3434 * @param string $user_agent   Comment author User-Agent.
    3535 * @param string $comment_type Comment type, either user-submitted comment,
    36  *                                     trackback, or pingback.
     36 *                             trackback, or pingback.
    3737 * @return bool If all checks pass, true, otherwise false.
    3838 */
    39 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
     39function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type ) {
    4040        global $wpdb;
    4141
    4242        // If manual moderation is enabled, skip all checks and return false.
    43         if ( 1 == get_option('comment_moderation') )
     43        if ( 1 == get_option( 'comment_moderation' ) ) {
    4444                return false;
     45        }
    4546
    4647        /** This filter is documented in wp-includes/comment-template.php */
     
    6768                 * fail the check by returning false.
    6869                 */
    69                 if ( $num_links >= $max_links )
     70                if ( $num_links >= $max_links ) {
    7071                        return false;
    71         }
    72 
    73         $mod_keys = trim(get_option('moderation_keys'));
     72                }
     73        }
     74
     75        $mod_keys = trim( get_option( 'moderation_keys' ) );
    7476
    7577        // If moderation 'keys' (keywords) are set, process them.
    76         if ( !empty($mod_keys) ) {
    77                 $words = explode("\n", $mod_keys );
    78 
    79                 foreach ( (array) $words as $word) {
    80                         $word = trim($word);
     78        if ( ! empty( $mod_keys ) ) {
     79                $words = explode( "\n", $mod_keys );
     80
     81                foreach ( (array) $words as $word ) {
     82                        $word = trim( $word );
    8183
    8284                        // Skip empty lines.
    83                         if ( empty($word) )
     85                        if ( empty( $word ) ) {
    8486                                continue;
     87                        }
    8588
    8689                        /*
     
    8891                         * words don't break things:
    8992                         */
    90                         $word = preg_quote($word, '#');
     93                        $word = preg_quote( $word, '#' );
    9194
    9295                        /*
     
    9598                         */
    9699                        $pattern = "#$word#i";
    97                         if ( preg_match($pattern, $author) ) return false;
    98                         if ( preg_match($pattern, $email) ) return false;
    99                         if ( preg_match($pattern, $url) ) return false;
    100                         if ( preg_match($pattern, $comment) ) return false;
    101                         if ( preg_match($pattern, $user_ip) ) return false;
    102                         if ( preg_match($pattern, $user_agent) ) return false;
     100                        if ( preg_match( $pattern, $author ) ) {
     101                                return false;
     102                        }
     103                        if ( preg_match( $pattern, $email ) ) {
     104                                return false;
     105                        }
     106                        if ( preg_match( $pattern, $url ) ) {
     107                                return false;
     108                        }
     109                        if ( preg_match( $pattern, $comment ) ) {
     110                                return false;
     111                        }
     112                        if ( preg_match( $pattern, $user_ip ) ) {
     113                                return false;
     114                        }
     115                        if ( preg_match( $pattern, $user_agent ) ) {
     116                                return false;
     117                        }
    103118                }
    104119        }
     
    111126         * email address. If both checks pass, return true. Otherwise, return false.
    112127         */
    113         if ( 1 == get_option('comment_whitelist')) {
     128        if ( 1 == get_option( 'comment_whitelist' ) ) {
    114129                if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {
    115130                        $comment_user = get_user_by( 'email', wp_unslash( $email ) );
     
    121136                        }
    122137                        if ( ( 1 == $ok_to_comment ) &&
    123                                 ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) )
     138                                ( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) ) {
    124139                                        return true;
    125                         else
     140                        } else {
    126141                                return false;
     142                        }
    127143                } else {
    128144                        return false;
     
    153169                'order'   => 'ASC',
    154170        );
    155         $r = wp_parse_args( $args, $defaults );
     171        $r        = wp_parse_args( $args, $defaults );
    156172
    157173        $query = new WP_Comment_Query;
     
    239255function get_comment_statuses() {
    240256        $status = array(
    241                 'hold'          => __( 'Unapproved' ),
    242                 'approve'       => _x( 'Approved', 'comment status' ),
    243                 'spam'          => _x( 'Spam', 'comment status' ),
    244                 'trash'         => _x( 'Trash', 'comment status' ),
     257                'hold'    => __( 'Unapproved' ),
     258                'approve' => _x( 'Approved', 'comment status' ),
     259                'spam'    => _x( 'Spam', 'comment status' ),
     260                'trash'   => _x( 'Trash', 'comment status' ),
    245261        );
    246262
     
    259275function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) {
    260276        switch ( $comment_type ) {
    261                 case 'pingback' :
    262                 case 'trackback' :
     277                case 'pingback':
     278                case 'trackback':
    263279                        $supports = 'trackbacks';
    264                         $option = 'ping';
     280                        $option   = 'ping';
    265281                        break;
    266                 default :
     282                default:
    267283                        $supports = 'comments';
    268                         $option = 'comment';
     284                        $option   = 'comment';
    269285        }
    270286
     
    288304         * @param string $comment_type Type of comment. Default is `comment`.
    289305         */
    290         return apply_filters( 'get_default_comment_status' , $status, $post_type, $comment_type );
     306        return apply_filters( 'get_default_comment_status', $status, $post_type, $comment_type );
    291307}
    292308
     
    307323
    308324        $timezone = strtolower( $timezone );
    309         $key = "lastcommentmodified:$timezone";
     325        $key      = "lastcommentmodified:$timezone";
    310326
    311327        $comment_modified_date = wp_cache_get( $key, 'timeinfo' );
     
    357373        $where = '';
    358374        if ( $post_id > 0 ) {
    359                 $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id);
    360         }
    361 
    362         $totals = (array) $wpdb->get_results("
     375                $where = $wpdb->prepare( 'WHERE comment_post_ID = %d', $post_id );
     376        }
     377
     378        $totals = (array) $wpdb->get_results(
     379                "
    363380                SELECT comment_approved, COUNT( * ) AS total
    364381                FROM {$wpdb->comments}
    365382                {$where}
    366383                GROUP BY comment_approved
    367         ", ARRAY_A);
     384        ", ARRAY_A
     385        );
    368386
    369387        $comment_count = array(
     
    386404                                break;
    387405                        case 'spam':
    388                                 $comment_count['spam'] = $row['total'];
     406                                $comment_count['spam']            = $row['total'];
    389407                                $comment_count['total_comments'] += $row['total'];
    390408                                break;
    391409                        case '1':
    392                                 $comment_count['approved'] = $row['total'];
     410                                $comment_count['approved']        = $row['total'];
    393411                                $comment_count['total_comments'] += $row['total'];
    394                                 $comment_count['all'] += $row['total'];
     412                                $comment_count['all']            += $row['total'];
    395413                                break;
    396414                        case '0':
    397415                                $comment_count['awaiting_moderation'] = $row['total'];
    398                                 $comment_count['total_comments'] += $row['total'];
    399                                 $comment_count['all'] += $row['total'];
     416                                $comment_count['total_comments']     += $row['total'];
     417                                $comment_count['all']                += $row['total'];
    400418                                break;
    401419                        default:
     
    423441 * @return int|bool Meta ID on success, false on failure.
    424442 */
    425 function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) {
     443function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
    426444        $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    427445        if ( $added ) {
     
    446464 * @return bool True on success, false on failure.
    447465 */
    448 function delete_comment_meta($comment_id, $meta_key, $meta_value = '') {
     466function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
    449467        $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    450468        if ( $deleted ) {
     
    466484 *  is true.
    467485 */
    468 function get_comment_meta($comment_id, $key = '', $single = false) {
    469         return get_metadata('comment', $comment_id, $key, $single);
     486function get_comment_meta( $comment_id, $key = '', $single = false ) {
     487        return get_metadata( 'comment', $comment_id, $key, $single );
    470488}
    471489
     
    487505 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
    488506 */
    489 function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') {
     507function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
    490508        $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    491509        if ( $updated ) {
     
    528546 * @since 3.4.0
    529547 */
    530 function wp_set_comment_cookies($comment, $user) {
    531         if ( $user->exists() )
     548function wp_set_comment_cookies( $comment, $user ) {
     549        if ( $user->exists() ) {
    532550                return;
     551        }
    533552
    534553        /**
     
    540559         */
    541560        $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 );
    542         $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
     561        $secure                  = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
    543562        setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
    544563        setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
    545         setcookie( 'comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
     564        setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
    546565}
    547566
     
    555574 */
    556575function sanitize_comment_cookies() {
    557         if ( isset( $_COOKIE['comment_author_' . COOKIEHASH] ) ) {
     576        if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) {
    558577                /**
    559578                 * Filters the comment author's name cookie before it is set.
     
    566585                 * @param string $author_cookie The comment author name cookie.
    567586                 */
    568                 $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE['comment_author_' . COOKIEHASH] );
    569                 $comment_author = wp_unslash($comment_author);
    570                 $comment_author = esc_attr($comment_author);
    571                 $_COOKIE['comment_author_' . COOKIEHASH] = $comment_author;
    572         }
    573 
    574         if ( isset( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) {
     587                $comment_author                            = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] );
     588                $comment_author                            = wp_unslash( $comment_author );
     589                $comment_author                            = esc_attr( $comment_author );
     590                $_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author;
     591        }
     592
     593        if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
    575594                /**
    576595                 * Filters the comment author's email cookie before it is set.
     
    583602                 * @param string $author_email_cookie The comment author email cookie.
    584603                 */
    585                 $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE['comment_author_email_' . COOKIEHASH] );
    586                 $comment_author_email = wp_unslash($comment_author_email);
    587                 $comment_author_email = esc_attr($comment_author_email);
    588                 $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email;
    589         }
    590 
    591         if ( isset( $_COOKIE['comment_author_url_' . COOKIEHASH] ) ) {
     604                $comment_author_email                            = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] );
     605                $comment_author_email                            = wp_unslash( $comment_author_email );
     606                $comment_author_email                            = esc_attr( $comment_author_email );
     607                $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email;
     608        }
     609
     610        if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) {
    592611                /**
    593612                 * Filters the comment author's URL cookie before it is set.
     
    600619                 * @param string $author_url_cookie The comment author URL cookie.
    601620                 */
    602                 $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE['comment_author_url_' . COOKIEHASH] );
    603                 $comment_author_url = wp_unslash($comment_author_url);
    604                 $_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url;
     621                $comment_author_url                            = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] );
     622                $comment_author_url                            = wp_unslash( $comment_author_url );
     623                $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url;
    605624        }
    606625}
     
    635654        if ( $commentdata['comment_author_email'] ) {
    636655                $dupe .= $wpdb->prepare(
    637                         "AND comment_author_email = %s ",
     656                        'AND comment_author_email = %s ',
    638657                        wp_unslash( $commentdata['comment_author_email'] )
    639658                );
    640659        }
    641660        $dupe .= $wpdb->prepare(
    642                 ") AND comment_content = %s LIMIT 1",
     661                ') AND comment_content = %s LIMIT 1',
    643662                wp_unslash( $commentdata['comment_content'] )
    644663        );
     
    671690                } else {
    672691                        if ( wp_doing_ajax() ) {
    673                                 die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
     692                                die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) );
    674693                        }
    675694
     
    728747
    729748        if ( ! empty( $commentdata['user_id'] ) ) {
    730                 $user = get_userdata( $commentdata['user_id'] );
    731                 $post_author = $wpdb->get_var( $wpdb->prepare(
    732                         "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
    733                         $commentdata['comment_post_ID']
    734                 ) );
     749                $user        = get_userdata( $commentdata['user_id'] );
     750                $post_author = $wpdb->get_var(
     751                        $wpdb->prepare(
     752                                "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
     753                                $commentdata['comment_post_ID']
     754                        )
     755                );
    735756        }
    736757
     
    829850
    830851        if ( is_user_logged_in() ) {
    831                 $user = get_current_user_id();
     852                $user         = get_current_user_id();
    832853                $check_column = '`user_id`';
    833854        } else {
    834                 $user = $ip;
     855                $user         = $ip;
    835856                $check_column = '`comment_author_IP`';
    836857        }
    837858
    838         $sql = $wpdb->prepare(
     859        $sql      = $wpdb->prepare(
    839860                "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1",
    840861                $hour_ago,
     
    844865        $lasttime = $wpdb->get_var( $sql );
    845866        if ( $lasttime ) {
    846                 $time_lastcomment = mysql2date('U', $lasttime, false);
    847                 $time_newcomment  = mysql2date('U', $date, false);
     867                $time_lastcomment = mysql2date( 'U', $lasttime, false );
     868                $time_newcomment  = mysql2date( 'U', $date, false );
    848869                /**
    849870                 * Filters the comment flood status.
     
    870891                        } else {
    871892                                if ( wp_doing_ajax() ) {
    872                                         die( __('You are posting comments too quickly. Slow down.') );
     893                                        die( __( 'You are posting comments too quickly. Slow down.' ) );
    873894                                }
    874895
     
    889910 * @return array Array of comments keyed by comment_type.
    890911 */
    891 function separate_comments(&$comments) {
    892         $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
    893         $count = count($comments);
     912function separate_comments( &$comments ) {
     913        $comments_by_type = array(
     914                'comment'   => array(),
     915                'trackback' => array(),
     916                'pingback'  => array(),
     917                'pings'     => array(),
     918        );
     919        $count            = count( $comments );
    894920        for ( $i = 0; $i < $count; $i++ ) {
    895                 $type = $comments[$i]->comment_type;
    896                 if ( empty($type) )
     921                $type = $comments[ $i ]->comment_type;
     922                if ( empty( $type ) ) {
    897923                        $type = 'comment';
    898                 $comments_by_type[$type][] = &$comments[$i];
    899                 if ( 'trackback' == $type || 'pingback' == $type )
    900                         $comments_by_type['pings'][] = &$comments[$i];
     924                }
     925                $comments_by_type[ $type ][] = &$comments[ $i ];
     926                if ( 'trackback' == $type || 'pingback' == $type ) {
     927                        $comments_by_type['pings'][] = &$comments[ $i ];
     928                }
    901929        }
    902930
     
    921949        global $wp_query;
    922950
    923         if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) )
     951        if ( null === $comments && null === $per_page && null === $threaded && ! empty( $wp_query->max_num_comment_pages ) ) {
    924952                return $wp_query->max_num_comment_pages;
    925 
    926         if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments )  )
     953        }
     954
     955        if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) {
    927956                $comments = $wp_query->comments;
    928 
    929         if ( empty($comments) )
     957        }
     958
     959        if ( empty( $comments ) ) {
    930960                return 0;
     961        }
    931962
    932963        if ( ! get_option( 'page_comments' ) ) {
     
    934965        }
    935966
    936         if ( !isset($per_page) )
    937                 $per_page = (int) get_query_var('comments_per_page');
    938         if ( 0 === $per_page )
    939                 $per_page = (int) get_option('comments_per_page');
    940         if ( 0 === $per_page )
     967        if ( ! isset( $per_page ) ) {
     968                $per_page = (int) get_query_var( 'comments_per_page' );
     969        }
     970        if ( 0 === $per_page ) {
     971                $per_page = (int) get_option( 'comments_per_page' );
     972        }
     973        if ( 0 === $per_page ) {
    941974                return 1;
    942 
    943         if ( !isset($threaded) )
    944                 $threaded = get_option('thread_comments');
     975        }
     976
     977        if ( ! isset( $threaded ) ) {
     978                $threaded = get_option( 'thread_comments' );
     979        }
    945980
    946981        if ( $threaded ) {
    947982                $walker = new Walker_Comment;
    948                 $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
     983                $count  = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
    949984        } else {
    950985                $count = ceil( count( $comments ) / $per_page );
     
    9791014        $page = null;
    9801015
    981         if ( !$comment = get_comment( $comment_ID ) )
     1016        if ( ! $comment = get_comment( $comment_ID ) ) {
    9821017                return;
    983 
    984         $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
    985         $args = wp_parse_args( $args, $defaults );
     1018        }
     1019
     1020        $defaults      = array(
     1021                'type'      => 'all',
     1022                'page'      => '',
     1023                'per_page'  => '',
     1024                'max_depth' => '',
     1025        );
     1026        $args          = wp_parse_args( $args, $defaults );
    9861027        $original_args = $args;
    9871028
     
    9971038        }
    9981039
    999         if ( empty($args['per_page']) ) {
     1040        if ( empty( $args['per_page'] ) ) {
    10001041                $args['per_page'] = 0;
    1001                 $args['page'] = 0;
     1042                $args['page']     = 0;
    10021043        }
    10031044
     
    10081049        if ( null === $page ) {
    10091050                if ( '' === $args['max_depth'] ) {
    1010                         if ( get_option('thread_comments') )
    1011                                 $args['max_depth'] = get_option('thread_comments_depth');
    1012                         else
     1051                        if ( get_option( 'thread_comments' ) ) {
     1052                                $args['max_depth'] = get_option( 'thread_comments_depth' );
     1053                        } else {
    10131054                                $args['max_depth'] = -1;
     1055                        }
    10141056                }
    10151057
    10161058                // Find this comment's top level parent if threading is enabled
    1017                 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
     1059                if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) {
    10181060                        return get_page_of_comment( $comment->comment_parent, $args );
     1061                }
    10191062
    10201063                $comment_args = array(
     
    10291072                                        'column' => "$wpdb->comments.comment_date_gmt",
    10301073                                        'before' => $comment->comment_date_gmt,
    1031                                 )
     1074                                ),
    10321075                        ),
    10331076                );
    10341077
    1035                 $comment_query = new WP_Comment_Query();
     1078                $comment_query       = new WP_Comment_Query();
    10361079                $older_comment_count = $comment_query->query( $comment_args );
    10371080
     
    10401083                        $page = 1;
    10411084
    1042                 // Divide comments older than this one by comments per page to get this comment's page number
     1085                        // Divide comments older than this one by comments per page to get this comment's page number
    10431086                } else {
    10441087                        $page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] );
     
    11751218 * @return bool True if comment contains blacklisted content, false if comment does not
    11761219 */
    1177 function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
     1220function wp_blacklist_check( $author, $email, $url, $comment, $user_ip, $user_agent ) {
    11781221        /**
    11791222         * Fires before the comment is tested for blacklisted characters or words.
     
    11901233        do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent );
    11911234
    1192         $mod_keys = trim( get_option('blacklist_keys') );
    1193         if ( '' == $mod_keys )
     1235        $mod_keys = trim( get_option( 'blacklist_keys' ) );
     1236        if ( '' == $mod_keys ) {
    11941237                return false; // If moderation keys are empty
     1238        }
    11951239
    11961240        // Ensure HTML tags are not being used to bypass the blacklist.
    11971241        $comment_without_html = wp_strip_all_tags( $comment );
    11981242
    1199         $words = explode("\n", $mod_keys );
     1243        $words = explode( "\n", $mod_keys );
    12001244
    12011245        foreach ( (array) $words as $word ) {
    1202                 $word = trim($word);
     1246                $word = trim( $word );
    12031247
    12041248                // Skip empty lines
    1205                 if ( empty($word) ) { continue; }
     1249                if ( empty( $word ) ) {
     1250                        continue; }
    12061251
    12071252                // Do some escaping magic so that '#' chars in the
    12081253                // spam words don't break things:
    1209                 $word = preg_quote($word, '#');
     1254                $word = preg_quote( $word, '#' );
    12101255
    12111256                $pattern = "#$word#i";
    1212                 if ( preg_match($pattern, $author)
    1213                         || preg_match($pattern, $email)
    1214                         || preg_match($pattern, $url)
    1215                         || preg_match($pattern, $comment)
    1216                         || preg_match($pattern, $comment_without_html)
    1217                         || preg_match($pattern, $user_ip)
    1218                         || preg_match($pattern, $user_agent)
    1219                 )
     1257                if ( preg_match( $pattern, $author )
     1258                        || preg_match( $pattern, $email )
     1259                        || preg_match( $pattern, $url )
     1260                        || preg_match( $pattern, $comment )
     1261                        || preg_match( $pattern, $comment_without_html )
     1262                        || preg_match( $pattern, $user_ip )
     1263                        || preg_match( $pattern, $user_agent )
     1264                ) {
    12201265                        return true;
     1266                }
    12211267        }
    12221268        return false;
     
    12601306        }
    12611307
    1262         $stats = get_comment_count( $post_id );
     1308        $stats              = get_comment_count( $post_id );
    12631309        $stats['moderated'] = $stats['awaiting_moderation'];
    12641310        unset( $stats['awaiting_moderation'] );
     
    12871333 * @return bool True on success, false on failure.
    12881334 */
    1289 function wp_delete_comment($comment_id, $force_delete = false) {
     1335function wp_delete_comment( $comment_id, $force_delete = false ) {
    12901336        global $wpdb;
    1291         if (!$comment = get_comment($comment_id))
     1337        if ( ! $comment = get_comment( $comment_id ) ) {
    12921338                return false;
    1293 
    1294         if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) )
    1295                 return wp_trash_comment($comment_id);
     1339        }
     1340
     1341        if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) {
     1342                return wp_trash_comment( $comment_id );
     1343        }
    12961344
    12971345        /**
     
    13071355
    13081356        // Move children up a level.
    1309         $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) );
    1310         if ( !empty($children) ) {
    1311                 $wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID));
    1312                 clean_comment_cache($children);
     1357        $children = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID ) );
     1358        if ( ! empty( $children ) ) {
     1359                $wpdb->update( $wpdb->comments, array( 'comment_parent' => $comment->comment_parent ), array( 'comment_parent' => $comment->comment_ID ) );
     1360                clean_comment_cache( $children );
    13131361        }
    13141362
    13151363        // Delete metadata
    13161364        $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) );
    1317         foreach ( $meta_ids as $mid )
     1365        foreach ( $meta_ids as $mid ) {
    13181366                delete_metadata_by_mid( 'comment', $mid );
    1319 
    1320         if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) )
     1367        }
     1368
     1369        if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) {
    13211370                return false;
     1371        }
    13221372
    13231373        /**
     
    13331383
    13341384        $post_id = $comment->comment_post_ID;
    1335         if ( $post_id && $comment->comment_approved == 1 )
    1336                 wp_update_comment_count($post_id);
     1385        if ( $post_id && $comment->comment_approved == 1 ) {
     1386                wp_update_comment_count( $post_id );
     1387        }
    13371388
    13381389        clean_comment_cache( $comment->comment_ID );
     
    13411392        do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' );
    13421393
    1343         wp_transition_comment_status('delete', $comment->comment_approved, $comment);
     1394        wp_transition_comment_status( 'delete', $comment->comment_approved, $comment );
    13441395        return true;
    13451396}
     
    13551406 * @return bool True on success, false on failure.
    13561407 */
    1357 function wp_trash_comment($comment_id) {
    1358         if ( !EMPTY_TRASH_DAYS )
    1359                 return wp_delete_comment($comment_id, true);
    1360 
    1361         if ( !$comment = get_comment($comment_id) )
     1408function wp_trash_comment( $comment_id ) {
     1409        if ( ! EMPTY_TRASH_DAYS ) {
     1410                return wp_delete_comment( $comment_id, true );
     1411        }
     1412
     1413        if ( ! $comment = get_comment( $comment_id ) ) {
    13621414                return false;
     1415        }
    13631416
    13641417        /**
     
    14031456 * @return bool True on success, false on failure.
    14041457 */
    1405 function wp_untrash_comment($comment_id) {
     1458function wp_untrash_comment( $comment_id ) {
    14061459        $comment = get_comment( $comment_id );
    14071460        if ( ! $comment ) {
     
    14211474
    14221475        $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true );
    1423         if ( empty($status) )
     1476        if ( empty( $status ) ) {
    14241477                $status = '0';
     1478        }
    14251479
    14261480        if ( wp_set_comment_status( $comment, $status ) ) {
     
    15151569
    15161570        $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true );
    1517         if ( empty($status) )
     1571        if ( empty( $status ) ) {
    15181572                $status = '0';
     1573        }
    15191574
    15201575        if ( wp_set_comment_status( $comment, $status ) ) {
     
    15451600 * @return false|string Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure.
    15461601 */
    1547 function wp_get_comment_status($comment_id) {
    1548         $comment = get_comment($comment_id);
    1549         if ( !$comment )
     1602function wp_get_comment_status( $comment_id ) {
     1603        $comment = get_comment( $comment_id );
     1604        if ( ! $comment ) {
    15501605                return false;
     1606        }
    15511607
    15521608        $approved = $comment->comment_approved;
    15531609
    1554         if ( $approved == null )
     1610        if ( $approved == null ) {
    15551611                return false;
    1556         elseif ( $approved == '1' )
     1612        } elseif ( $approved == '1' ) {
    15571613                return 'approved';
    1558         elseif ( $approved == '0' )
     1614        } elseif ( $approved == '0' ) {
    15591615                return 'unapproved';
    1560         elseif ( $approved == 'spam' )
     1616        } elseif ( $approved == 'spam' ) {
    15611617                return 'spam';
    1562         elseif ( $approved == 'trash' )
     1618        } elseif ( $approved == 'trash' ) {
    15631619                return 'trash';
    1564         else
     1620        } else {
    15651621                return false;
     1622        }
    15661623}
    15671624
     
    15841641 * @param object $comment Comment data.
    15851642 */
    1586 function wp_transition_comment_status($new_status, $old_status, $comment) {
     1643function wp_transition_comment_status( $new_status, $old_status, $comment ) {
    15871644        /*
    15881645         * Translate raw statuses to human readable formats for the hooks.
     
    15961653                'approve' => 'approved', // wp_set_comment_status() uses "approve"
    15971654        );
    1598         if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];
    1599         if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];
     1655        if ( isset( $comment_statuses[ $new_status ] ) ) {
     1656                $new_status = $comment_statuses[ $new_status ];
     1657        }
     1658        if ( isset( $comment_statuses[ $old_status ] ) ) {
     1659                $old_status = $comment_statuses[ $old_status ];
     1660        }
    16001661
    16011662        // Call the hooks
     
    16761737
    16771738        $comment_author = '';
    1678         if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) )
    1679                 $comment_author = $_COOKIE['comment_author_'.COOKIEHASH];
     1739        if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) {
     1740                $comment_author = $_COOKIE[ 'comment_author_' . COOKIEHASH ];
     1741        }
    16801742
    16811743        $comment_author_email = '';
    1682         if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) )
    1683                 $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH];
     1744        if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
     1745                $comment_author_email = $_COOKIE[ 'comment_author_email_' . COOKIEHASH ];
     1746        }
    16841747
    16851748        $comment_author_url = '';
    1686         if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) )
    1687                 $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH];
     1749        if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) {
     1750                $comment_author_url = $_COOKIE[ 'comment_author_url_' . COOKIEHASH ];
     1751        }
    16881752
    16891753        /**
     
    17001764         * }
    17011765         */
    1702         return apply_filters( 'wp_get_current_commenter', compact('comment_author', 'comment_author_email', 'comment_author_url') );
     1766        return apply_filters( 'wp_get_current_commenter', compact( 'comment_author', 'comment_author_email', 'comment_author_url' ) );
    17031767}
    17041768
     
    17421806        $data = wp_unslash( $commentdata );
    17431807
    1744         $comment_author       = ! isset( $data['comment_author'] )       ? '' : $data['comment_author'];
     1808        $comment_author       = ! isset( $data['comment_author'] ) ? '' : $data['comment_author'];
    17451809        $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
    1746         $comment_author_url   = ! isset( $data['comment_author_url'] )   ? '' : $data['comment_author_url'];
    1747         $comment_author_IP    = ! isset( $data['comment_author_IP'] )    ? '' : $data['comment_author_IP'];
    1748 
    1749         $comment_date     = ! isset( $data['comment_date'] )     ? current_time( 'mysql' )            : $data['comment_date'];
     1810        $comment_author_url   = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
     1811        $comment_author_IP    = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
     1812
     1813        $comment_date     = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
    17501814        $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
    17511815
    1752         $comment_post_ID  = ! isset( $data['comment_post_ID'] )  ? 0 : $data['comment_post_ID'];
    1753         $comment_content  = ! isset( $data['comment_content'] )  ? '' : $data['comment_content'];
    1754         $comment_karma    = ! isset( $data['comment_karma'] )    ? 0 : $data['comment_karma'];
    1755         $comment_approved = ! isset( $data['comment_approved'] ) ? 1  : $data['comment_approved'];
    1756         $comment_agent    = ! isset( $data['comment_agent'] )    ? '' : $data['comment_agent'];
    1757         $comment_type     = ! isset( $data['comment_type'] )     ? '' : $data['comment_type'];
    1758         $comment_parent   = ! isset( $data['comment_parent'] )   ? 0 : $data['comment_parent'];
    1759 
    1760         $user_id  = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
     1816        $comment_post_ID  = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
     1817        $comment_content  = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
     1818        $comment_karma    = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
     1819        $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
     1820        $comment_agent    = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
     1821        $comment_type     = ! isset( $data['comment_type'] ) ? '' : $data['comment_type'];
     1822        $comment_parent   = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
     1823
     1824        $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
    17611825
    17621826        $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
     
    18111875 * @return array Parsed comment information.
    18121876 */
    1813 function wp_filter_comment($commentdata) {
     1877function wp_filter_comment( $commentdata ) {
    18141878        if ( isset( $commentdata['user_ID'] ) ) {
    18151879                /**
     
    18591923        /** This filter is documented in wp-includes/comment.php */
    18601924        $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] );
    1861         $commentdata['filtered'] = true;
     1925        $commentdata['filtered']             = true;
    18621926        return $commentdata;
    18631927}
     
    18731937 * @return bool Whether comment should be blocked.
    18741938 */
    1875 function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {
    1876         if ( $block ) // a plugin has already blocked... we'll let that decision stand
     1939function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment ) {
     1940        if ( $block ) { // a plugin has already blocked... we'll let that decision stand
    18771941                return $block;
    1878         if ( ($time_newcomment - $time_lastcomment) < 15 )
     1942        }
     1943        if ( ( $time_newcomment - $time_lastcomment ) < 15 ) {
    18791944                return true;
     1945        }
    18801946        return false;
    18811947}
     
    19502016        }
    19512017
    1952         $commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
    1953         $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
     2018        $commentdata['comment_parent'] = isset( $commentdata['comment_parent'] ) ? absint( $commentdata['comment_parent'] ) : 0;
     2019        $parent_status                 = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status( $commentdata['comment_parent'] ) : '';
    19542020        $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;
    19552021
     
    19602026
    19612027        if ( ! isset( $commentdata['comment_agent'] ) ) {
    1962                 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT']: '';
     2028                $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
    19632029        }
    19642030        $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 );
    19652031
    19662032        if ( empty( $commentdata['comment_date'] ) ) {
    1967                 $commentdata['comment_date'] = current_time('mysql');
     2033                $commentdata['comment_date'] = current_time( 'mysql' );
    19682034        }
    19692035
     
    19722038        }
    19732039
    1974         $commentdata = wp_filter_comment($commentdata);
     2040        $commentdata = wp_filter_comment( $commentdata );
    19752041
    19762042        $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die );
     
    19792045        }
    19802046
    1981         $comment_ID = wp_insert_comment($commentdata);
     2047        $comment_ID = wp_insert_comment( $commentdata );
    19822048        if ( ! $comment_ID ) {
    19832049                $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' );
     
    20992165 * @return bool|WP_Error True on success, false or WP_Error on failure.
    21002166 */
    2101 function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
     2167function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false ) {
    21022168        global $wpdb;
    21032169
     
    21222188        }
    21232189
    2124         $comment_old = clone get_comment($comment_id);
    2125 
    2126         if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {
    2127                 if ( $wp_error )
    2128                         return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error);
    2129                 else
     2190        $comment_old = clone get_comment( $comment_id );
     2191
     2192        if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {
     2193                if ( $wp_error ) {
     2194                        return new WP_Error( 'db_update_error', __( 'Could not update comment status' ), $wpdb->last_error );
     2195                } else {
    21302196                        return false;
     2197                }
    21312198        }
    21322199
     
    21472214        do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status );
    21482215
    2149         wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment);
    2150 
    2151         wp_update_comment_count($comment->comment_post_ID);
     2216        wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment );
     2217
     2218        wp_update_comment_count( $comment->comment_post_ID );
    21522219
    21532220        return true;
     
    21672234 * @return int Comment was updated if value is 1, or was not updated if value is 0.
    21682235 */
    2169 function wp_update_comment($commentarr) {
     2236function wp_update_comment( $commentarr ) {
    21702237        global $wpdb;
    21712238
    21722239        // First, get all of the original fields
    2173         $comment = get_comment($commentarr['comment_ID'], ARRAY_A);
     2240        $comment = get_comment( $commentarr['comment_ID'], ARRAY_A );
    21742241        if ( empty( $comment ) ) {
    21752242                return 0;
     
    21822249
    21832250        // Escape data pulled from DB.
    2184         $comment = wp_slash($comment);
     2251        $comment = wp_slash( $comment );
    21852252
    21862253        $old_status = $comment['comment_approved'];
    21872254
    21882255        // Merge old and new fields with new fields overwriting old ones.
    2189         $commentarr = array_merge($comment, $commentarr);
     2256        $commentarr = array_merge( $comment, $commentarr );
    21902257
    21912258        $commentarr = wp_filter_comment( $commentarr );
     
    22132280        }
    22142281
    2215         $comment_ID = $data['comment_ID'];
     2282        $comment_ID      = $data['comment_ID'];
    22162283        $comment_post_ID = $data['comment_post_ID'];
    22172284
     
    22552322         */
    22562323        do_action( 'edit_comment', $comment_ID, $data );
    2257         $comment = get_comment($comment_ID);
    2258         wp_transition_comment_status($comment->comment_approved, $old_status, $comment);
     2324        $comment = get_comment( $comment_ID );
     2325        wp_transition_comment_status( $comment->comment_approved, $old_status, $comment );
    22592326        return $rval;
    22602327}
     
    22742341 * @return bool
    22752342 */
    2276 function wp_defer_comment_counting($defer=null) {
     2343function wp_defer_comment_counting( $defer = null ) {
    22772344        static $_defer = false;
    22782345
    2279         if ( is_bool($defer) ) {
     2346        if ( is_bool( $defer ) ) {
    22802347                $_defer = $defer;
    22812348                // flush any deferred counts
    2282                 if ( !$defer )
     2349                if ( ! $defer ) {
    22832350                        wp_update_comment_count( null, true );
     2351                }
    22842352        }
    22852353
     
    23092377 *                   not exist.
    23102378 */
    2311 function wp_update_comment_count($post_id, $do_deferred=false) {
     2379function wp_update_comment_count( $post_id, $do_deferred = false ) {
    23122380        static $_deferred = array();
    23132381
     
    23172385
    23182386        if ( $do_deferred ) {
    2319                 $_deferred = array_unique($_deferred);
     2387                $_deferred = array_unique( $_deferred );
    23202388                foreach ( $_deferred as $i => $_post_id ) {
    2321                         wp_update_comment_count_now($_post_id);
    2322                         unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
     2389                        wp_update_comment_count_now( $_post_id );
     2390                        unset( $_deferred[ $i ] );
     2391                        /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
    23232392                }
    23242393        }
     
    23272396                $_deferred[] = $post_id;
    23282397                return true;
    2329         }
    2330         elseif ( $post_id ) {
    2331                 return wp_update_comment_count_now($post_id);
     2398        } elseif ( $post_id ) {
     2399                return wp_update_comment_count_now( $post_id );
    23322400        }
    23332401
     
    23442412 * @return bool True on success, false on '0' $post_id or if post with ID does not exist.
    23452413 */
    2346 function wp_update_comment_count_now($post_id) {
     2414function wp_update_comment_count_now( $post_id ) {
    23472415        global $wpdb;
    23482416        $post_id = (int) $post_id;
    2349         if ( !$post_id )
     2417        if ( ! $post_id ) {
    23502418                return false;
     2419        }
    23512420
    23522421        wp_cache_delete( 'comments-0', 'counts' );
    23532422        wp_cache_delete( "comments-{$post_id}", 'counts' );
    23542423
    2355         if ( !$post = get_post($post_id) )
     2424        if ( ! $post = get_post( $post_id ) ) {
    23562425                return false;
     2426        }
    23572427
    23582428        $old = (int) $post->comment_count;
     
    23752445        }
    23762446
    2377         $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
     2447        $wpdb->update( $wpdb->posts, array( 'comment_count' => $new ), array( 'ID' => $post_id ) );
    23782448
    23792449        clean_post_cache( $post );
     
    24132483 */
    24142484function discover_pingback_server_uri( $url, $deprecated = '' ) {
    2415         if ( !empty( $deprecated ) )
     2485        if ( ! empty( $deprecated ) ) {
    24162486                _deprecated_argument( __FUNCTION__, '2.7.0' );
     2487        }
    24172488
    24182489        $pingback_str_dquote = 'rel="pingback"';
     
    24202491
    24212492        /** @todo Should use Filter Extension or custom preg_match instead. */
    2422         $parsed_url = parse_url($url);
    2423 
    2424         if ( ! isset( $parsed_url['host'] ) ) // Not a URL. This should never happen.
     2493        $parsed_url = parse_url( $url );
     2494
     2495        if ( ! isset( $parsed_url['host'] ) ) { // Not a URL. This should never happen.
    24252496                return false;
     2497        }
    24262498
    24272499        //Do not search for a pingback server on our own uploads
    24282500        $uploads_dir = wp_get_upload_dir();
    2429         if ( 0 === strpos($url, $uploads_dir['baseurl']) )
     2501        if ( 0 === strpos( $url, $uploads_dir['baseurl'] ) ) {
    24302502                return false;
    2431 
    2432         $response = wp_safe_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) );
    2433 
    2434         if ( is_wp_error( $response ) )
     2503        }
     2504
     2505        $response = wp_safe_remote_head(
     2506                $url, array(
     2507                        'timeout'     => 2,
     2508                        'httpversion' => '1.0',
     2509                )
     2510        );
     2511
     2512        if ( is_wp_error( $response ) ) {
    24352513                return false;
    2436 
    2437         if ( wp_remote_retrieve_header( $response, 'x-pingback' ) )
     2514        }
     2515
     2516        if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) {
    24382517                return wp_remote_retrieve_header( $response, 'x-pingback' );
     2518        }
    24392519
    24402520        // Not an (x)html, sgml, or xml page, no use going further.
    2441         if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) )
     2521        if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' ) ) ) {
    24422522                return false;
     2523        }
    24432524
    24442525        // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    2445         $response = wp_safe_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) );
    2446 
    2447         if ( is_wp_error( $response ) )
     2526        $response = wp_safe_remote_get(
     2527                $url, array(
     2528                        'timeout'     => 2,
     2529                        'httpversion' => '1.0',
     2530                )
     2531        );
     2532
     2533        if ( is_wp_error( $response ) ) {
    24482534                return false;
     2535        }
    24492536
    24502537        $contents = wp_remote_retrieve_body( $response );
    24512538
    2452         $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    2453         $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
     2539        $pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote );
     2540        $pingback_link_offset_squote = strpos( $contents, $pingback_str_squote );
    24542541        if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
    2455                 $quote = ($pingback_link_offset_dquote) ? '"' : '\'';
    2456                 $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
    2457                 $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
    2458                 $pingback_href_start = $pingback_href_pos+6;
    2459                 $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
     2542                $quote                   = ( $pingback_link_offset_dquote ) ? '"' : '\'';
     2543                $pingback_link_offset    = ( $quote == '"' ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
     2544                $pingback_href_pos       = @strpos( $contents, 'href=', $pingback_link_offset );
     2545                $pingback_href_start     = $pingback_href_pos + 6;
     2546                $pingback_href_end       = @strpos( $contents, $quote, $pingback_href_start );
    24602547                $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
    2461                 $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
     2548                $pingback_server_url     = substr( $contents, $pingback_href_start, $pingback_server_url_len );
    24622549
    24632550                // We may find rel="pingback" but an incomplete pingback URL
     
    24812568
    24822569        // Do pingbacks
    2483         while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
     2570        while ( $ping = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1" ) ) {
    24842571                delete_metadata_by_mid( 'post', $ping->meta_id );
    24852572                pingback( $ping->post_content, $ping->ID );
     
    24872574
    24882575        // Do Enclosures
    2489         while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
     2576        while ( $enclosure = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1" ) ) {
    24902577                delete_metadata_by_mid( 'post', $enclosure->meta_id );
    24912578                do_enclose( $enclosure->post_content, $enclosure->ID );
     
    24932580
    24942581        // Do Trackbacks
    2495         $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'");
    2496         if ( is_array($trackbacks) )
    2497                 foreach ( $trackbacks as $trackback )
    2498                         do_trackbacks($trackback);
     2582        $trackbacks = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'" );
     2583        if ( is_array( $trackbacks ) ) {
     2584                foreach ( $trackbacks as $trackback ) {
     2585                        do_trackbacks( $trackback );
     2586                }
     2587        }
    24992588
    25002589        //Do Update Services/Generic Pings
     
    25222611        $pinged  = get_pung( $post );
    25232612        if ( empty( $to_ping ) ) {
    2524                 $wpdb->update($wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) );
     2613                $wpdb->update( $wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) );
    25252614                return;
    25262615        }
    25272616
    2528         if ( empty($post->post_excerpt) ) {
     2617        if ( empty( $post->post_excerpt ) ) {
    25292618                /** This filter is documented in wp-includes/post-template.php */
    25302619                $excerpt = apply_filters( 'the_content', $post->post_content, $post->ID );
     
    25342623        }
    25352624
    2536         $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
    2537         $excerpt = wp_html_excerpt($excerpt, 252, '&#8230;');
     2625        $excerpt = str_replace( ']]>', ']]&gt;', $excerpt );
     2626        $excerpt = wp_html_excerpt( $excerpt, 252, '&#8230;' );
    25382627
    25392628        /** This filter is documented in wp-includes/post-template.php */
    25402629        $post_title = apply_filters( 'the_title', $post->post_title, $post->ID );
    2541         $post_title = strip_tags($post_title);
     2630        $post_title = strip_tags( $post_title );
    25422631
    25432632        if ( $to_ping ) {
    25442633                foreach ( (array) $to_ping as $tb_ping ) {
    2545                         $tb_ping = trim($tb_ping);
    2546                         if ( !in_array($tb_ping, $pinged) ) {
     2634                        $tb_ping = trim( $tb_ping );
     2635                        if ( ! in_array( $tb_ping, $pinged ) ) {
    25472636                                trackback( $tb_ping, $post_title, $excerpt, $post->ID );
    25482637                                $pinged[] = $tb_ping;
    25492638                        } else {
    2550                                 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s,
    2551                                         '')) WHERE ID = %d", $tb_ping, $post->ID ) );
     2639                                $wpdb->query(
     2640                                        $wpdb->prepare(
     2641                                                "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s,
     2642                                        '')) WHERE ID = %d", $tb_ping, $post->ID
     2643                                        )
     2644                                );
    25522645                        }
    25532646                }
     
    25642657 */
    25652658function generic_ping( $post_id = 0 ) {
    2566         $services = get_option('ping_sites');
    2567 
    2568         $services = explode("\n", $services);
     2659        $services = get_option( 'ping_sites' );
     2660
     2661        $services = explode( "\n", $services );
    25692662        foreach ( (array) $services as $service ) {
    2570                 $service = trim($service);
    2571                 if ( '' != $service )
    2572                         weblog_ping($service);
     2663                $service = trim( $service );
     2664                if ( '' != $service ) {
     2665                        weblog_ping( $service );
     2666                }
    25732667        }
    25742668
     
    26182712        foreach ( (array) $post_links_temp as $link_test ) :
    26192713                if ( ! in_array( $link_test, $pung ) && ( url_to_postid( $link_test ) != $post->ID ) // If we haven't pung it already and it isn't a link to itself
    2620                                 && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
    2621                         if ( $test = @parse_url($link_test) ) {
    2622                                 if ( isset($test['query']) )
     2714                                && ! is_local_attachment( $link_test ) ) : // Also, let's never ping local attachments.
     2715                        if ( $test = @parse_url( $link_test ) ) {
     2716                                if ( isset( $test['query'] ) ) {
    26232717                                        $post_links[] = $link_test;
    2624                                 elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) )
     2718                                } elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) {
    26252719                                        $post_links[] = $link_test;
     2720                                }
    26262721                        }
    26272722                endif;
     
    26492744
    26502745                        // using a timeout of 3 seconds should be enough to cover slow servers
    2651                         $client = new WP_HTTP_IXR_Client($pingback_server_url);
     2746                        $client          = new WP_HTTP_IXR_Client( $pingback_server_url );
    26522747                        $client->timeout = 3;
    26532748                        /**
     
    26672762                        $client->debug = false;
    26682763
    2669                         if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered
     2764                        if ( $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto ) || ( isset( $client->error->code ) && 48 == $client->error->code ) ) { // Already registered
    26702765                                add_ping( $post, $pagelinkedto );
     2766                        }
    26712767                }
    26722768        }
     
    26812777 * @return mixed Empty string if blog is not public, returns $sites, if site is public.
    26822778 */
    2683 function privacy_ping_filter($sites) {
    2684         if ( '0' != get_option('blog_public') )
     2779function privacy_ping_filter( $sites ) {
     2780        if ( '0' != get_option( 'blog_public' ) ) {
    26852781                return $sites;
    2686         else
     2782        } else {
    26872783                return '';
     2784        }
    26882785}
    26892786
     
    27032800 * @return int|false|void Database query from update.
    27042801 */
    2705 function trackback($trackback_url, $title, $excerpt, $ID) {
     2802function trackback( $trackback_url, $title, $excerpt, $ID ) {
    27062803        global $wpdb;
    27072804
    2708         if ( empty($trackback_url) )
     2805        if ( empty( $trackback_url ) ) {
    27092806                return;
    2710 
    2711         $options = array();
     2807        }
     2808
     2809        $options            = array();
    27122810        $options['timeout'] = 10;
    2713         $options['body'] = array(
    2714                 'title' => $title,
    2715                 'url' => get_permalink($ID),
    2716                 'blog_name' => get_option('blogname'),
    2717                 'excerpt' => $excerpt
     2811        $options['body']    = array(
     2812                'title'     => $title,
     2813                'url'       => get_permalink( $ID ),
     2814                'blog_name' => get_option( 'blogname' ),
     2815                'excerpt'   => $excerpt,
    27182816        );
    27192817
    27202818        $response = wp_safe_remote_post( $trackback_url, $options );
    27212819
    2722         if ( is_wp_error( $response ) )
     2820        if ( is_wp_error( $response ) ) {
    27232821                return;
    2724 
    2725         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) );
    2726         return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) );
     2822        }
     2823
     2824        $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID ) );
     2825        return $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID ) );
    27272826}
    27282827
     
    27352834 * @param string $path Path to send the ping.
    27362835 */
    2737 function weblog_ping($server = '', $path = '') {
     2836function weblog_ping( $server = '', $path = '' ) {
    27382837        include_once( ABSPATH . WPINC . '/class-IXR.php' );
    27392838        include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' );
    27402839
    27412840        // using a timeout of 3 seconds should be enough to cover slow servers
    2742         $client = new WP_HTTP_IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));
    2743         $client->timeout = 3;
     2841        $client             = new WP_HTTP_IXR_Client( $server, ( ( ! strlen( trim( $path ) ) || ( '/' == $path ) ) ? false : $path ) );
     2842        $client->timeout    = 3;
    27442843        $client->useragent .= ' -- WordPress/' . get_bloginfo( 'version' );
    27452844
    27462845        // when set to true, this outputs debug messages by itself
    27472846        $client->debug = false;
    2748         $home = trailingslashit( home_url() );
    2749         if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping
    2750                 $client->query('weblogUpdates.ping', get_option('blogname'), $home);
     2847        $home          = trailingslashit( home_url() );
     2848        if ( ! $client->query( 'weblogUpdates.extendedPing', get_option( 'blogname' ), $home, get_bloginfo( 'rss2_url' ) ) ) { // then try a normal ping
     2849                $client->query( 'weblogUpdates.ping', get_option( 'blogname' ), $home );
     2850        }
    27512851}
    27522852
     
    27772877 */
    27782878function xmlrpc_pingback_error( $ixr_error ) {
    2779         if ( $ixr_error->code === 48 )
     2879        if ( $ixr_error->code === 48 ) {
    27802880                return $ixr_error;
     2881        }
    27812882        return new IXR_Error( 0, '' );
    27822883}
     
    27932894 * @param int|array $ids Comment ID or an array of comment IDs to remove from cache.
    27942895 */
    2795 function clean_comment_cache($ids) {
     2896function clean_comment_cache( $ids ) {
    27962897        foreach ( (array) $ids as $id ) {
    27972898                wp_cache_delete( $id, 'comment' );
     
    28242925 */
    28252926function update_comment_cache( $comments, $update_meta_cache = true ) {
    2826         foreach ( (array) $comments as $comment )
    2827                 wp_cache_add($comment->comment_ID, $comment, 'comment');
     2927        foreach ( (array) $comments as $comment ) {
     2928                wp_cache_add( $comment->comment_ID, $comment, 'comment' );
     2929        }
    28282930
    28292931        if ( $update_meta_cache ) {
     
    28532955
    28542956        $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
    2855         if ( !empty( $non_cached_ids ) ) {
    2856                 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     2957        if ( ! empty( $non_cached_ids ) ) {
     2958                $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) );
    28572959
    28582960                update_comment_cache( $fresh_comments, $update_meta_cache );
     
    28752977 */
    28762978function _close_comments_for_old_posts( $posts, $query ) {
    2877         if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
     2979        if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) {
    28782980                return $posts;
     2981        }
    28792982
    28802983        /**
     
    28862989         */
    28872990        $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
    2888         if ( ! in_array( $posts[0]->post_type, $post_types ) )
     2991        if ( ! in_array( $posts[0]->post_type, $post_types ) ) {
    28892992                return $posts;
     2993        }
    28902994
    28912995        $days_old = (int) get_option( 'close_comments_days_old' );
    2892         if ( ! $days_old )
     2996        if ( ! $days_old ) {
    28932997                return $posts;
     2998        }
    28942999
    28953000        if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
    28963001                $posts[0]->comment_status = 'closed';
    2897                 $posts[0]->ping_status = 'closed';
     3002                $posts[0]->ping_status    = 'closed';
    28983003        }
    28993004
     
    29123017 */
    29133018function _close_comments_for_old_post( $open, $post_id ) {
    2914         if ( ! $open )
     3019        if ( ! $open ) {
    29153020                return $open;
    2916 
    2917         if ( !get_option('close_comments_for_old_posts') )
     3021        }
     3022
     3023        if ( ! get_option( 'close_comments_for_old_posts' ) ) {
    29183024                return $open;
    2919 
    2920         $days_old = (int) get_option('close_comments_days_old');
    2921         if ( !$days_old )
     3025        }
     3026
     3027        $days_old = (int) get_option( 'close_comments_days_old' );
     3028        if ( ! $days_old ) {
    29223029                return $open;
    2923 
    2924         $post = get_post($post_id);
     3030        }
     3031
     3032        $post = get_post( $post_id );
    29253033
    29263034        /** This filter is documented in wp-includes/comment.php */
    29273035        $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
    2928         if ( ! in_array( $post->post_type, $post_types ) )
     3036        if ( ! in_array( $post->post_type, $post_types ) ) {
    29293037                return $open;
     3038        }
    29303039
    29313040        // Undated drafts should not show up as comments closed.
     
    29343043        }
    29353044
    2936         if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
     3045        if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
    29373046                return false;
     3047        }
    29383048
    29393049        return $open;
     
    29643074
    29653075        $comment_post_ID = $comment_parent = 0;
    2966         $comment_author = $comment_author_email = $comment_author_url = $comment_content = null;
     3076        $comment_author  = $comment_author_email = $comment_author_url = $comment_content = null;
    29673077
    29683078        if ( isset( $comment_data['comment_post_ID'] ) ) {
     
    30473157                 */
    30483158                do_action( 'comment_on_draft', $comment_post_ID );
    3049                
     3159
    30503160                if ( current_user_can( 'read_post', $comment_post_ID ) ) {
    30513161                        return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 );
     
    30533163                        return new WP_Error( 'comment_on_draft' );
    30543164                }
    3055 
    30563165        } elseif ( post_password_required( $comment_post_ID ) ) {
    30573166
     
    30843193        if ( $user->exists() ) {
    30853194                if ( empty( $user->display_name ) ) {
    3086                         $user->display_name=$user->user_login;
     3195                        $user->display_name = $user->user_login;
    30873196                }
    30883197                $comment_author       = $user->display_name;
Note: See TracChangeset for help on using the changeset viewer.