Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 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-template.php

    r42228 r42343  
    1919 *
    2020 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author.
    21  *                                  Default current comment.
     21 *                                  Default current comment.
    2222 * @return string The comment author
    2323 */
     
    2626
    2727    if ( empty( $comment->comment_author ) ) {
    28         if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )
     28        if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) {
    2929            $author = $user->display_name;
    30         else
    31             $author = __('Anonymous');
     30        } else {
     31            $author = __( 'Anonymous' );
     32        }
    3233    } else {
    3334        $author = $comment->comment_author;
     
    5455 *
    5556 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author.
    56  *                                  Default current comment.
     57 *                                  Default current comment.
    5758 */
    5859function comment_author( $comment_ID = 0 ) {
     
    7980 *
    8081 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.
    81  *                                  Default current comment.
     82 *                                  Default current comment.
    8283 * @return string The current comment author's email
    8384 */
     
    111112 *
    112113 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email.
    113  *                                  Default current comment.
     114 *                                  Default current comment.
    114115 */
    115116function comment_author_email( $comment_ID = 0 ) {
     
    190191    $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
    191192
    192     if ((!empty($email)) && ($email != '@')) {
    193     $display = ($linktext != '') ? $linktext : $email;
     193    if ( ( ! empty( $email ) ) && ( $email != '@' ) ) {
     194        $display = ( $linktext != '' ) ? $linktext : $email;
    194195        $return  = $before;
    195196        $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
    196         $return .= $after;
     197        $return .= $after;
    197198        return $return;
    198199    } else {
     
    211212 *
    212213 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
    213  *                                  Default current comment.
     214 *                                  Default current comment.
    214215 * @return string The comment author name or HTML link for author's URL.
    215216 */
     
    219220    $author  = get_comment_author( $comment );
    220221
    221     if ( empty( $url ) || 'http://' == $url )
     222    if ( empty( $url ) || 'http://' == $url ) {
    222223        $return = $author;
    223     else
     224    } else {
    224225        $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
     226    }
    225227
    226228    /**
     
    245247 *
    246248 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link.
    247  *                                  Default current comment.
     249 *                                  Default current comment.
    248250 */
    249251function comment_author_link( $comment_ID = 0 ) {
     
    258260 *
    259261 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address.
    260  *                                  Default current comment.
     262 *                                  Default current comment.
    261263 * @return string Comment author's IP address.
    262264 */
     
    284286 *
    285287 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address.
    286  *                                  Default current comment.
     288 *                                  Default current comment.
    287289 */
    288290function comment_author_IP( $comment_ID = 0 ) {
     
    297299 *
    298300 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL.
    299  *                                  Default current comment.
     301 *                                  Default current comment.
    300302 * @return string Comment author URL.
    301303 */
    302304function get_comment_author_url( $comment_ID = 0 ) {
    303305    $comment = get_comment( $comment_ID );
    304     $url = '';
    305     $id = 0;
     306    $url     = '';
     307    $id      = 0;
    306308    if ( ! empty( $comment ) ) {
    307309        $author_url = ( 'http://' == $comment->comment_author_url ) ? '' : $comment->comment_author_url;
    308         $url = esc_url( $author_url, array( 'http', 'https' ) );
    309         $id = $comment->comment_ID;
     310        $url        = esc_url( $author_url, array( 'http', 'https' ) );
     311        $id         = $comment->comment_ID;
    310312    }
    311313
     
    330332 *
    331333 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL.
    332  *                                  Default current comment.
     334 *                                  Default current comment.
    333335 */
    334336function comment_author_url( $comment_ID = 0 ) {
     
    372374 */
    373375function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
    374     $url = get_comment_author_url( $comment );
    375     $display = ($linktext != '') ? $linktext : $url;
     376    $url     = get_comment_author_url( $comment );
     377    $display = ( $linktext != '' ) ? $linktext : $url;
    376378    $display = str_replace( 'http://www.', '', $display );
    377379    $display = str_replace( 'http://', '', $display );
    378380
    379     if ( '/' == substr($display, -1) ) {
    380         $display = substr($display, 0, -1);
     381    if ( '/' == substr( $display, -1 ) ) {
     382        $display = substr( $display, 0, -1 );
    381383    }
    382384
     
    429431    // Separates classes with a single space, collates classes for comment DIV
    430432    $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
    431     if ( $echo)
     433    if ( $echo ) {
    432434        echo $class;
    433     else
     435    } else {
    434436        return $class;
     437    }
    435438}
    436439
     
    468471        $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
    469472        // For comment authors who are the author of the post
    470         if ( $post = get_post($post_id) ) {
     473        if ( $post = get_post( $post_id ) ) {
    471474            if ( $comment->user_id === $post->post_author ) {
    472475                $classes[] = 'bypostauthor';
     
    475478    }
    476479
    477     if ( empty($comment_alt) )
     480    if ( empty( $comment_alt ) ) {
    478481        $comment_alt = 0;
    479     if ( empty($comment_depth) )
     482    }
     483    if ( empty( $comment_depth ) ) {
    480484        $comment_depth = 1;
    481     if ( empty($comment_thread_alt) )
     485    }
     486    if ( empty( $comment_thread_alt ) ) {
    482487        $comment_thread_alt = 0;
     488    }
    483489
    484490    if ( $comment_alt % 2 ) {
     
    504510    $classes[] = "depth-$comment_depth";
    505511
    506     if ( !empty($class) ) {
    507         if ( !is_array( $class ) )
    508             $class = preg_split('#\s+#', $class);
    509         $classes = array_merge($classes, $class);
    510     }
    511 
    512     $classes = array_map('esc_attr', $classes);
     512    if ( ! empty( $class ) ) {
     513        if ( ! is_array( $class ) ) {
     514            $class = preg_split( '#\s+#', $class );
     515        }
     516        $classes = array_merge( $classes, $class );
     517    }
     518
     519    $classes = array_map( 'esc_attr', $classes );
    513520
    514521    /**
     
    539546function get_comment_date( $d = '', $comment_ID = 0 ) {
    540547    $comment = get_comment( $comment_ID );
    541     if ( '' == $d )
    542         $date = mysql2date(get_option('date_format'), $comment->comment_date);
    543     else
    544         $date = mysql2date($d, $comment->comment_date);
     548    if ( '' == $d ) {
     549        $date = mysql2date( get_option( 'date_format' ), $comment->comment_date );
     550    } else {
     551        $date = mysql2date( $d, $comment->comment_date );
     552    }
    545553    /**
    546554     * Filters the returned comment date.
     
    584592 */
    585593function get_comment_excerpt( $comment_ID = 0 ) {
    586     $comment = get_comment( $comment_ID );
     594    $comment      = get_comment( $comment_ID );
    587595    $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
    588     $words = explode( ' ', $comment_text );
     596    $words        = explode( ' ', $comment_text );
    589597
    590598    /**
     
    703711    global $wp_rewrite, $in_comment_loop;
    704712
    705     $comment = get_comment($comment);
     713    $comment = get_comment( $comment );
    706714
    707715    // Back-compat.
     
    717725        'cpage'     => null,
    718726    );
    719     $args = wp_parse_args( $args, $defaults );
     727    $args     = wp_parse_args( $args, $defaults );
    720728
    721729    $link = get_permalink( $comment->comment_post_ID );
     
    725733        $cpage = $args['cpage'];
    726734
    727     // No 'cpage' is provided, so we calculate one.
     735        // No 'cpage' is provided, so we calculate one.
    728736    } else {
    729737        if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
    730             $args['per_page'] = get_option('comments_per_page');
     738            $args['per_page'] = get_option( 'comments_per_page' );
    731739        }
    732740
    733741        if ( empty( $args['per_page'] ) ) {
    734742            $args['per_page'] = 0;
    735             $args['page'] = 0;
     743            $args['page']     = 0;
    736744        }
    737745
     
    766774            $link = add_query_arg( 'cpage', $cpage, $link );
    767775        }
    768 
    769776    }
    770777
     
    800807 */
    801808function get_comments_link( $post_id = 0 ) {
    802     $hash = get_comments_number( $post_id ) ? '#comments' : '#respond';
     809    $hash          = get_comments_number( $post_id ) ? '#comments' : '#respond';
    803810    $comments_link = get_permalink( $post_id ) . $hash;
    804811
     
    823830 */
    824831function comments_link( $deprecated = '', $deprecated_2 = '' ) {
    825     if ( !empty( $deprecated ) )
     832    if ( ! empty( $deprecated ) ) {
    826833        _deprecated_argument( __FUNCTION__, '0.72' );
    827     if ( !empty( $deprecated_2 ) )
     834    }
     835    if ( ! empty( $deprecated_2 ) ) {
    828836        _deprecated_argument( __FUNCTION__, '1.3.0' );
     837    }
    829838    echo esc_url( get_comments_link() );
    830839}
     
    845854        $count = 0;
    846855    } else {
    847         $count = $post->comment_count;
     856        $count   = $post->comment_count;
    848857        $post_id = $post->ID;
    849858    }
     
    10121021
    10131022    $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    1014     if ( '' == $d )
    1015         $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    1016     else
    1017         $date = mysql2date($d, $comment_date, $translate);
     1023    if ( '' == $d ) {
     1024        $date = mysql2date( get_option( 'time_format' ), $comment_date, $translate );
     1025    } else {
     1026        $date = mysql2date( $d, $comment_date, $translate );
     1027    }
    10181028
    10191029    /**
     
    10391049 */
    10401050function comment_time( $d = '' ) {
    1041     echo get_comment_time($d);
     1051    echo get_comment_time( $d );
    10421052}
    10431053
     
    10541064function get_comment_type( $comment_ID = 0 ) {
    10551065    $comment = get_comment( $comment_ID );
    1056     if ( '' == $comment->comment_type )
     1066    if ( '' == $comment->comment_type ) {
    10571067        $comment->comment_type = 'comment';
     1068    }
    10581069
    10591070    /**
     
    10641075     *
    10651076     * @param string     $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
    1066      * @param int        $comment_ID   The comment ID.
     1077     * @param int        $comment_ID   The comment ID.
    10671078     * @param WP_Comment $comment      The comment object.
    10681079     */
     
    10801091 */
    10811092function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
    1082     if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
    1083     if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
    1084     if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
     1093    if ( false === $commenttxt ) {
     1094        $commenttxt = _x( 'Comment', 'noun' );
     1095    }
     1096    if ( false === $trackbacktxt ) {
     1097        $trackbacktxt = __( 'Trackback' );
     1098    }
     1099    if ( false === $pingbacktxt ) {
     1100        $pingbacktxt = __( 'Pingback' );
     1101    }
    10851102    $type = get_comment_type();
    1086     switch( $type ) {
    1087         case 'trackback' :
     1103    switch ( $type ) {
     1104        case 'trackback':
    10881105            echo $trackbacktxt;
    10891106            break;
    1090         case 'pingback' :
     1107        case 'pingback':
    10911108            echo $pingbacktxt;
    10921109            break;
    1093         default :
     1110        default:
    10941111            echo $commenttxt;
    10951112    }
     
    11081125 */
    11091126function get_trackback_url() {
    1110     if ( '' != get_option('permalink_structure') )
    1111         $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
    1112     else
    1113         $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
     1127    if ( '' != get_option( 'permalink_structure' ) ) {
     1128        $tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
     1129    } else {
     1130        $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
     1131    }
    11141132
    11151133    /**
     
    11341152function trackback_url( $deprecated_echo = true ) {
    11351153    if ( true !== $deprecated_echo ) {
    1136         _deprecated_argument( __FUNCTION__, '2.5.0',
     1154        _deprecated_argument(
     1155            __FUNCTION__, '2.5.0',
    11371156            /* translators: %s: get_trackback_url() */
    1138             sprintf( __( 'Use %s instead if you do not want the value echoed.' ),
     1157            sprintf(
     1158                __( 'Use %s instead if you do not want the value echoed.' ),
    11391159                '<code>get_trackback_url()</code>'
    11401160            )
     
    11721192        <rdf:Description rdf:about="';
    11731193    the_permalink();
    1174     echo '"'."\n";
     1194    echo '"' . "\n";
    11751195    echo '    dc:identifier="';
    11761196    the_permalink();
    1177     echo '"'."\n";
    1178     echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
    1179     echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
     1197    echo '"' . "\n";
     1198    echo '    dc:title="' . str_replace( '--', '&#x2d;&#x2d;', wptexturize( strip_tags( get_the_title() ) ) ) . '"' . "\n";
     1199    echo '    trackback:ping="' . get_trackback_url() . '"' . " />\n";
    11801200    echo '</rdf:RDF>';
    11811201}
     
    11911211function comments_open( $post_id = null ) {
    11921212
    1193     $_post = get_post($post_id);
     1213    $_post = get_post( $post_id );
    11941214
    11951215    $post_id = $_post ? $_post->ID : 0;
    1196     $open = ( 'open' == $_post->comment_status );
     1216    $open    = ( 'open' == $_post->comment_status );
    11971217
    11981218    /**
     
    12171237function pings_open( $post_id = null ) {
    12181238
    1219     $_post = get_post($post_id);
     1239    $_post = get_post( $post_id );
    12201240
    12211241    $post_id = $_post ? $_post->ID : 0;
    1222     $open = ( 'open' == $_post->ping_status );
     1242    $open    = ( 'open' == $_post->ping_status );
    12231243
    12241244    /**
     
    12481268 */
    12491269function wp_comment_form_unfiltered_html_nonce() {
    1250     $post = get_post();
     1270    $post    = get_post();
    12511271    $post_id = $post ? $post->ID : 0;
    12521272
     
    12951315    global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
    12961316
    1297     if ( !(is_single() || is_page() || $withcomments) || empty($post) )
     1317    if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
    12981318        return;
    1299 
    1300     if ( empty($file) )
     1319    }
     1320
     1321    if ( empty( $file ) ) {
    13011322        $file = '/comments.php';
    1302 
    1303     $req = get_option('require_name_email');
     1323    }
     1324
     1325    $req = get_option( 'require_name_email' );
    13041326
    13051327    /*
     
    13231345     * The url of the current comment author escaped for use in attributes.
    13241346     */
    1325     $comment_author_url = esc_url($commenter['comment_author_url']);
     1347    $comment_author_url = esc_url( $commenter['comment_author_url'] );
    13261348
    13271349    $comment_args = array(
    1328         'orderby' => 'comment_date_gmt',
    1329         'order' => 'ASC',
    1330         'status'  => 'approve',
    1331         'post_id' => $post->ID,
    1332         'no_found_rows' => false,
     1350        'orderby'                   => 'comment_date_gmt',
     1351        'order'                     => 'ASC',
     1352        'status'                    => 'approve',
     1353        'post_id'                   => $post->ID,
     1354        'no_found_rows'             => false,
    13331355        'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
    13341356    );
    13351357
    1336     if ( get_option('thread_comments') ) {
     1358    if ( get_option( 'thread_comments' ) ) {
    13371359        $comment_args['hierarchical'] = 'threaded';
    13381360    } else {
     
    13541376
    13551377        $comment_args['number'] = $per_page;
    1356         $page = (int) get_query_var( 'cpage' );
     1378        $page                   = (int) get_query_var( 'cpage' );
    13571379
    13581380        if ( $page ) {
     
    14071429     * }
    14081430     */
    1409     $comment_args = apply_filters( 'comments_template_query_args', $comment_args );
     1431    $comment_args  = apply_filters( 'comments_template_query_args', $comment_args );
    14101432    $comment_query = new WP_Comment_Query( $comment_args );
    1411     $_comments = $comment_query->comments;
     1433    $_comments     = $comment_query->comments;
    14121434
    14131435    // Trees must be flattened before they're passed to the walker.
     
    14161438        foreach ( $_comments as $_comment ) {
    14171439            $comments_flat[]  = $_comment;
    1418             $comment_children = $_comment->get_children( array(
    1419                 'format' => 'flat',
    1420                 'status' => $comment_args['status'],
    1421                 'orderby' => $comment_args['orderby']
    1422             ) );
     1440            $comment_children = $_comment->get_children(
     1441                array(
     1442                    'format'  => 'flat',
     1443                    'status'  => $comment_args['status'],
     1444                    'orderby' => $comment_args['orderby'],
     1445                )
     1446            );
    14231447
    14241448            foreach ( $comment_children as $comment_child ) {
     
    14401464    $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
    14411465
    1442     $comments = &$wp_query->comments;
    1443     $wp_query->comment_count = count($wp_query->comments);
     1466    $comments                        = &$wp_query->comments;
     1467    $wp_query->comment_count         = count( $wp_query->comments );
    14441468    $wp_query->max_num_comment_pages = $comment_query->max_num_pages;
    14451469
    14461470    if ( $separate_comments ) {
    1447         $wp_query->comments_by_type = separate_comments($comments);
    1448         $comments_by_type = &$wp_query->comments_by_type;
     1471        $wp_query->comments_by_type = separate_comments( $comments );
     1472        $comments_by_type           = &$wp_query->comments_by_type;
    14491473    } else {
    14501474        $wp_query->comments_by_type = array();
     
    14531477    $overridden_cpage = false;
    14541478    if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
    1455         set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
     1479        set_query_var( 'cpage', 'newest' == get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 );
    14561480        $overridden_cpage = true;
    14571481    }
    14581482
    1459     if ( !defined('COMMENTS_TEMPLATE') )
    1460         define('COMMENTS_TEMPLATE', true);
     1483    if ( ! defined( 'COMMENTS_TEMPLATE' ) ) {
     1484        define( 'COMMENTS_TEMPLATE', true );
     1485    }
    14611486
    14621487    $theme_template = STYLESHEETPATH . $file;
     
    14691494     */
    14701495    $include = apply_filters( 'comments_template', $theme_template );
    1471     if ( file_exists( $include ) )
     1496    if ( file_exists( $include ) ) {
    14721497        require( $include );
    1473     elseif ( file_exists( TEMPLATEPATH . $file ) )
     1498    } elseif ( file_exists( TEMPLATEPATH . $file ) ) {
    14741499        require( TEMPLATEPATH . $file );
    1475     else // Backward compat code will be removed in a future release
    1476         require( ABSPATH . WPINC . '/theme-compat/comments.php');
     1500    } else { // Backward compat code will be removed in a future release
     1501        require( ABSPATH . WPINC . '/theme-compat/comments.php' );
     1502    }
    14771503}
    14781504
     
    14921518 */
    14931519function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
    1494     $id = get_the_ID();
    1495     $title = get_the_title();
     1520    $id     = get_the_ID();
     1521    $title  = get_the_title();
    14961522    $number = get_comments_number( $id );
    14971523
     
    15171543    }
    15181544
    1519     if ( 0 == $number && !comments_open() && !pings_open() ) {
    1520         echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
     1545    if ( 0 == $number && ! comments_open() && ! pings_open() ) {
     1546        echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
    15211547        return;
    15221548    }
     
    15441570    echo '"';
    15451571
    1546     if ( !empty( $css_class ) ) {
    1547         echo ' class="'.$css_class.'" ';
     1572    if ( ! empty( $css_class ) ) {
     1573        echo ' class="' . $css_class . '" ';
    15481574    }
    15491575
     
    16021628        'depth'         => 0,
    16031629        'before'        => '',
    1604         'after'         => ''
     1630        'after'         => '',
    16051631    );
    16061632
     
    16361662
    16371663    if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
    1638         $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
     1664        $link = sprintf(
     1665            '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
    16391666            esc_url( wp_login_url( get_permalink() ) ),
    16401667            $args['login_text']
    16411668        );
    16421669    } else {
    1643         $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
     1670        $onclick = sprintf(
     1671            'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
    16441672            $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
    16451673        );
    16461674
    1647         $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
    1648             esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'],
     1675        $link = sprintf(
     1676            "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
     1677            esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . '#' . $args['respond_id'],
    16491678            $onclick,
    16501679            esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
     
    16791708 * @return mixed Link to show comment form, if successful. False, if comments are closed.
    16801709 */
    1681 function comment_reply_link($args = array(), $comment = null, $post = null) {
    1682     echo get_comment_reply_link($args, $comment, $post);
     1710function comment_reply_link( $args = array(), $comment = null, $post = null ) {
     1711    echo get_comment_reply_link( $args, $comment, $post );
    16831712}
    16841713
     
    17061735 * @return false|null|string Link to show comment form, if successful. False, if comments are closed.
    17071736 */
    1708 function get_post_reply_link($args = array(), $post = null) {
     1737function get_post_reply_link( $args = array(), $post = null ) {
    17091738    $defaults = array(
    17101739        'add_below'  => 'post',
    17111740        'respond_id' => 'respond',
    1712         'reply_text' => __('Leave a Comment'),
    1713         'login_text' => __('Log in to leave a Comment'),
     1741        'reply_text' => __( 'Leave a Comment' ),
     1742        'login_text' => __( 'Log in to leave a Comment' ),
    17141743        'before'     => '',
    17151744        'after'      => '',
    17161745    );
    17171746
    1718     $args = wp_parse_args($args, $defaults);
    1719 
    1720     $post = get_post($post);
     1747    $args = wp_parse_args( $args, $defaults );
     1748
     1749    $post = get_post( $post );
    17211750
    17221751    if ( ! comments_open( $post->ID ) ) {
     
    17241753    }
    17251754
    1726     if ( get_option('comment_registration') && ! is_user_logged_in() ) {
    1727         $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
     1755    if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
     1756        $link = sprintf(
     1757            '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
    17281758            wp_login_url( get_permalink() ),
    17291759            $args['login_text']
    17301760        );
    17311761    } else {
    1732         $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
     1762        $onclick = sprintf(
     1763            'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
    17331764            $args['add_below'], $post->ID, $args['respond_id']
    17341765        );
    17351766
    1736         $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>",
     1767        $link = sprintf(
     1768            "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>",
    17371769            get_permalink( $post->ID ) . '#' . $args['respond_id'],
    17381770            $onclick,
     
    17651797 * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
    17661798 */
    1767 function post_reply_link($args = array(), $post = null) {
    1768     echo get_post_reply_link($args, $post);
     1799function post_reply_link( $args = array(), $post = null ) {
     1800    echo get_post_reply_link( $args, $post );
    17691801}
    17701802
     
    17781810 */
    17791811function get_cancel_comment_reply_link( $text = '' ) {
    1780     if ( empty($text) )
    1781         $text = __('Click here to cancel reply.');
    1782 
    1783     $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
    1784     $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
     1812    if ( empty( $text ) ) {
     1813        $text = __( 'Click here to cancel reply.' );
     1814    }
     1815
     1816    $style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"';
     1817    $link  = esc_html( remove_query_arg( 'replytocom' ) ) . '#respond';
    17851818
    17861819    $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
     
    18061839 */
    18071840function cancel_comment_reply_link( $text = '' ) {
    1808     echo get_cancel_comment_reply_link($text);
     1841    echo get_cancel_comment_reply_link( $text );
    18091842}
    18101843
     
    18181851 */
    18191852function get_comment_id_fields( $id = 0 ) {
    1820     if ( empty( $id ) )
     1853    if ( empty( $id ) ) {
    18211854        $id = get_the_ID();
    1822 
    1823     $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    1824     $result  = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
    1825     $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
     1855    }
     1856
     1857    $replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
     1858    $result    = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
     1859    $result   .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
    18261860
    18271861    /**
     
    18711905    global $comment;
    18721906
    1873     if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
    1874     if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
    1875 
    1876     $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    1877 
    1878     if ( 0 == $replytoid )
     1907    if ( false === $noreplytext ) {
     1908        $noreplytext = __( 'Leave a Reply' );
     1909    }
     1910    if ( false === $replytext ) {
     1911        $replytext = __( 'Leave a Reply to %s' );
     1912    }
     1913
     1914    $replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
     1915
     1916    if ( 0 == $replytoid ) {
    18791917        echo $noreplytext;
    1880     else {
     1918    } else {
    18811919        // Sets the global so that template tags can be used in the comment form.
    1882         $comment = get_comment($replytoid);
    1883         $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment );
     1920        $comment = get_comment( $replytoid );
     1921        $author  = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment );
    18841922        printf( $replytext, $author );
    18851923    }
     
    19291967    $in_comment_loop = true;
    19301968
    1931     $comment_alt = $comment_thread_alt = 0;
     1969    $comment_alt   = $comment_thread_alt = 0;
    19321970    $comment_depth = 1;
    19331971
     
    19652003    if ( null !== $comments ) {
    19662004        $comments = (array) $comments;
    1967         if ( empty($comments) )
     2005        if ( empty( $comments ) ) {
    19682006            return;
     2007        }
    19692008        if ( 'all' != $r['type'] ) {
    1970             $comments_by_type = separate_comments($comments);
    1971             if ( empty($comments_by_type[$r['type']]) )
     2009            $comments_by_type = separate_comments( $comments );
     2010            if ( empty( $comments_by_type[ $r['type'] ] ) ) {
    19722011                return;
    1973             $_comments = $comments_by_type[$r['type']];
     2012            }
     2013            $_comments = $comments_by_type[ $r['type'] ];
    19742014        } else {
    19752015            $_comments = $comments;
     
    19912031                    'post_id' => get_the_ID(),
    19922032                    'orderby' => 'comment_date_gmt',
    1993                     'order' => 'ASC',
    1994                     'status' => 'approve',
     2033                    'order'   => 'ASC',
     2034                    'status'  => 'approve',
    19952035                );
    19962036
     
    20182058            }
    20192059
    2020         // Otherwise, fall back on the comments from `$wp_query->comments`.
     2060            // Otherwise, fall back on the comments from `$wp_query->comments`.
    20212061        } else {
    2022             if ( empty($wp_query->comments) )
     2062            if ( empty( $wp_query->comments ) ) {
    20232063                return;
     2064            }
    20242065            if ( 'all' != $r['type'] ) {
    2025                 if ( empty($wp_query->comments_by_type) )
    2026                     $wp_query->comments_by_type = separate_comments($wp_query->comments);
    2027                 if ( empty($wp_query->comments_by_type[$r['type']]) )
     2066                if ( empty( $wp_query->comments_by_type ) ) {
     2067                    $wp_query->comments_by_type = separate_comments( $wp_query->comments );
     2068                }
     2069                if ( empty( $wp_query->comments_by_type[ $r['type'] ] ) ) {
    20282070                    return;
    2029                 $_comments = $wp_query->comments_by_type[$r['type']];
     2071                }
     2072                $_comments = $wp_query->comments_by_type[ $r['type'] ];
    20302073            } else {
    20312074                $_comments = $wp_query->comments;
     
    20342077            if ( $wp_query->max_num_comment_pages ) {
    20352078                $default_comments_page = get_option( 'default_comments_page' );
    2036                 $cpage = get_query_var( 'cpage' );
     2079                $cpage                 = get_query_var( 'cpage' );
    20372080                if ( 'newest' === $default_comments_page ) {
    20382081                    $r['cpage'] = $cpage;
    20392082
    2040                 /*
    2041                  * When first page shows oldest comments, post permalink is the same as
    2042                  * the comment permalink.
    2043                  */
     2083                    /*
     2084                    * When first page shows oldest comments, post permalink is the same as
     2085                    * the comment permalink.
     2086                    */
    20442087                } elseif ( $cpage == 1 ) {
    20452088                    $r['cpage'] = '';
     
    20482091                }
    20492092
    2050                 $r['page'] = 0;
     2093                $r['page']     = 0;
    20512094                $r['per_page'] = 0;
    20522095            }
     
    20552098
    20562099    if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) {
    2057         $r['per_page'] = get_query_var('comments_per_page');
    2058     }
    2059 
    2060     if ( empty($r['per_page']) ) {
     2100        $r['per_page'] = get_query_var( 'comments_per_page' );
     2101    }
     2102
     2103    if ( empty( $r['per_page'] ) ) {
    20612104        $r['per_page'] = 0;
    2062         $r['page'] = 0;
     2105        $r['page']     = 0;
    20632106    }
    20642107
    20652108    if ( '' === $r['max_depth'] ) {
    2066         if ( get_option('thread_comments') )
    2067             $r['max_depth'] = get_option('thread_comments_depth');
    2068         else
     2109        if ( get_option( 'thread_comments' ) ) {
     2110            $r['max_depth'] = get_option( 'thread_comments_depth' );
     2111        } else {
    20692112            $r['max_depth'] = -1;
     2113        }
    20702114    }
    20712115
    20722116    if ( '' === $r['page'] ) {
    2073         if ( empty($overridden_cpage) ) {
    2074             $r['page'] = get_query_var('cpage');
     2117        if ( empty( $overridden_cpage ) ) {
     2118            $r['page'] = get_query_var( 'cpage' );
    20752119        } else {
    2076             $threaded = ( -1 != $r['max_depth'] );
    2077             $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
     2120            $threaded  = ( -1 != $r['max_depth'] );
     2121            $r['page'] = ( 'newest' == get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $r['per_page'], $threaded ) : 1;
    20782122            set_query_var( 'cpage', $r['page'] );
    20792123        }
    20802124    }
    20812125    // Validation check
    2082     $r['page'] = intval($r['page']);
    2083     if ( 0 == $r['page'] && 0 != $r['per_page'] )
     2126    $r['page'] = intval( $r['page'] );
     2127    if ( 0 == $r['page'] && 0 != $r['per_page'] ) {
    20842128        $r['page'] = 1;
    2085 
    2086     if ( null === $r['reverse_top_level'] )
    2087         $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
     2129    }
     2130
     2131    if ( null === $r['reverse_top_level'] ) {
     2132        $r['reverse_top_level'] = ( 'desc' == get_option( 'comment_order' ) );
     2133    }
    20882134
    20892135    wp_queue_comments_for_comment_meta_lazyload( $_comments );
     
    21692215 */
    21702216function comment_form( $args = array(), $post_id = null ) {
    2171     if ( null === $post_id )
     2217    if ( null === $post_id ) {
    21722218        $post_id = get_the_ID();
     2219    }
    21732220
    21742221    // Exit the function when comments for the post are closed.
     
    21842231    }
    21852232
    2186     $commenter = wp_get_current_commenter();
    2187     $user = wp_get_current_user();
     2233    $commenter     = wp_get_current_commenter();
     2234    $user          = wp_get_current_user();
    21882235    $user_identity = $user->exists() ? $user->display_name : '';
    21892236
    21902237    $args = wp_parse_args( $args );
    2191     if ( ! isset( $args['format'] ) )
     2238    if ( ! isset( $args['format'] ) ) {
    21922239        $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
     2240    }
    21932241
    21942242    $req      = get_option( 'require_name_email' );
     
    21962244    $html_req = ( $req ? " required='required'" : '' );
    21972245    $html5    = 'html5' === $args['format'];
    2198     $fields   =  array(
     2246    $fields   = array(
    21992247        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    2200                     '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>',
     2248                    '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>',
    22012249        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    2202                     '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>',
     2250                    '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>',
    22032251        'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
    2204                     '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
     2252                    '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
    22052253    );
    22062254
    2207     $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
     2255    $required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' );
    22082256
    22092257    /**
     
    22142262     * @param array $fields The default comment fields.
    22152263     */
    2216     $fields = apply_filters( 'comment_form_default_fields', $fields );
     2264    $fields   = apply_filters( 'comment_form_default_fields', $fields );
    22172265    $defaults = array(
    22182266        'fields'               => $fields,
     
    22202268        /** This filter is documented in wp-includes/link-template.php */
    22212269        'must_log_in'          => '<p class="must-log-in">' . sprintf(
    2222                                     /* translators: %s: login URL */
     2270            /* translators: %s: login URL */
    22232271                                    __( 'You must be <a href="%s">logged in</a> to post a comment.' ),
    2224                                     wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
    2225                                 ) . '</p>',
     2272            wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
     2273        ) . '</p>',
    22262274        /** This filter is documented in wp-includes/link-template.php */
    22272275        'logged_in_as'         => '<p class="logged-in-as">' . sprintf(
    2228                                     /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
     2276            /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
    22292277                                    __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
    2230                                     get_edit_user_link(),
    2231                                     /* translators: %s: user name */
     2278            get_edit_user_link(),
     2279            /* translators: %s: user name */
    22322280                                    esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
    2233                                     $user_identity,
    2234                                     wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
    2235                                 ) . '</p>',
    2236         'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>',
     2281            $user_identity,
     2282            wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
     2283        ) . '</p>',
     2284        'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>',
    22372285        'comment_notes_after'  => '',
    22382286        'action'               => site_url( '/wp-comments-post.php' ),
     
    22902338        echo $args['title_reply_after'];
    22912339
    2292         if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) :
     2340        if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :
    22932341            echo $args['must_log_in'];
    22942342            /**
     
    22982346             */
    22992347            do_action( 'comment_form_must_log_in_after' );
    2300         else : ?>
     2348        else :
     2349        ?>
    23012350            <form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>>
    23022351                <?php
Note: See TracChangeset for help on using the changeset viewer.