Make WordPress Core


Ignore:
Timestamp:
04/19/2023 02:38:34 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use more meaningful variable names in various comment functions.

This aims to bring more consistency between the functions, as well as in filter parameters.

Includes minor code layout fixes for better readability.

Follow-up to [45667], [47287], [48579], [53719], [53723], [55308].

See #57839.

File:
1 edited

Legend:

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

    r55632 r55660  
    2323 */
    2424function get_comment_author( $comment_id = 0 ) {
    25     $comment    = get_comment( $comment_id );
     25    $comment = get_comment( $comment_id );
     26
    2627    $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_id;
    2728
     
    2930        $user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
    3031        if ( $user ) {
    31             $author = $user->display_name;
     32            $comment_author = $user->display_name;
    3233        } else {
    33             $author = __( 'Anonymous' );
     34            $comment_author = __( 'Anonymous' );
    3435        }
    3536    } else {
    36         $author = $comment->comment_author;
     37        $comment_author = $comment->comment_author;
    3738    }
    3839
     
    4344     * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
    4445     *
    45      * @param string     $author    The comment author's username.
    46      * @param string     $comment_id The comment ID as a numeric string.
    47      * @param WP_Comment $comment    The comment object.
    48      */
    49     return apply_filters( 'get_comment_author', $author, $comment_id, $comment );
     46     * @param string     $comment_author The comment author's username.
     47     * @param string     $comment_id     The comment ID as a numeric string.
     48     * @param WP_Comment $comment        The comment object.
     49     */
     50    return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment );
    5051}
    5152
     
    6162function comment_author( $comment_id = 0 ) {
    6263    $comment = get_comment( $comment_id );
    63     $author  = get_comment_author( $comment );
     64
     65    $comment_author = get_comment_author( $comment );
    6466
    6567    /**
     
    6971     * @since 4.1.0 The `$comment_id` parameter was added.
    7072     *
    71      * @param string $author    The comment author's username.
    72      * @param string $comment_id The comment ID as a numeric string.
    73      */
    74     echo apply_filters( 'comment_author', $author, $comment->comment_ID );
     73     * @param string $comment_author The comment author's username.
     74     * @param string $comment_id     The comment ID as a numeric string.
     75     */
     76    echo apply_filters( 'comment_author', $comment_author, $comment->comment_ID );
    7577}
    7678
     
    117119 */
    118120function comment_author_email( $comment_id = 0 ) {
    119     $comment      = get_comment( $comment_id );
    120     $author_email = get_comment_author_email( $comment );
     121    $comment = get_comment( $comment_id );
     122
     123    $comment_author_email = get_comment_author_email( $comment );
    121124
    122125    /**
     
    126129     * @since 4.1.0 The `$comment_id` parameter was added.
    127130     *
    128      * @param string $author_email The comment author's email address.
    129      * @param string $comment_id   The comment ID as a numeric string.
    130      */
    131     echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
     131     * @param string $comment_author_email The comment author's email address.
     132     * @param string $comment_id           The comment ID as a numeric string.
     133     */
     134    echo apply_filters( 'author_email', $comment_author_email, $comment->comment_ID );
    132135}
    133136
     
    144147 * @since 4.6.0 Added the `$comment` parameter.
    145148 *
    146  * @param string         $linktext Optional. Text to display instead of the comment author's email address.
    147  *                                 Default empty.
    148  * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
    149  * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
    150  * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
    151  */
    152 function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
    153     $link = get_comment_author_email_link( $linktext, $before, $after, $comment );
     149 * @param string         $link_text Optional. Text to display instead of the comment author's email address.
     150 *                                  Default empty.
     151 * @param string         $before    Optional. Text or HTML to display before the email link. Default empty.
     152 * @param string         $after     Optional. Text or HTML to display after the email link. Default empty.
     153 * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object. Default is the current comment.
     154 */
     155function comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
     156    $link = get_comment_author_email_link( $link_text, $before, $after, $comment );
    154157    if ( $link ) {
    155158        echo $link;
     
    169172 * @since 4.6.0 Added the `$comment` parameter.
    170173 *
    171  * @param string         $linktext Optional. Text to display instead of the comment author's email address.
    172  *                                 Default empty.
    173  * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
    174  * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
    175  * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
     174 * @param string         $link_text Optional. Text to display instead of the comment author's email address.
     175 *                                  Default empty.
     176 * @param string         $before    Optional. Text or HTML to display before the email link. Default empty.
     177 * @param string         $after     Optional. Text or HTML to display after the email link. Default empty.
     178 * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object. Default is the current comment.
    176179 * @return string HTML markup for the comment author email link. By default, the email address is obfuscated
    177180 *                via the {@see 'comment_email'} filter with antispambot().
    178181 */
    179 function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
     182function get_comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
    180183    $comment = get_comment( $comment );
    181184
     
    192195     * @param WP_Comment $comment              The comment object.
    193196     */
    194     $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
    195 
    196     if ( ( ! empty( $email ) ) && ( '@' !== $email ) ) {
    197         $display = ( '' !== $linktext ) ? $linktext : $email;
    198         $return  = $before;
    199         $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
    200         $return .= $after;
    201         return $return;
     197    $comment_author_email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
     198
     199    if ( ( ! empty( $comment_author_email ) ) && ( '@' !== $comment_author_email ) ) {
     200        $display = ( '' !== $link_text ) ? $link_text : $comment_author_email;
     201
     202        $comment_author_email_link = $before . sprintf(
     203            '<a href="%1$s">%2$s</a>',
     204            esc_url( 'mailto:' . $comment_author_email ),
     205            esc_html( $display )
     206        ) . $after;
     207
     208        return $comment_author_email_link;
    202209    } else {
    203210        return '';
     
    219226 */
    220227function get_comment_author_link( $comment_id = 0 ) {
    221     $comment    = get_comment( $comment_id );
     228    $comment = get_comment( $comment_id );
     229
    222230    $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_id;
    223     $url        = get_comment_author_url( $comment );
    224     $author     = get_comment_author( $comment );
    225 
    226     if ( empty( $url ) || 'http://' === $url ) {
    227         $return = $author;
     231
     232    $comment_author_url = get_comment_author_url( $comment );
     233    $comment_author     = get_comment_author( $comment );
     234
     235    if ( empty( $comment_author_url ) || 'http://' === $comment_author_url ) {
     236        $comment_author_link = $comment_author;
    228237    } else {
    229238        $rel_parts = array( 'ugc' );
    230         if ( ! wp_is_internal_link( $url ) ) {
     239        if ( ! wp_is_internal_link( $comment_author_url ) ) {
    231240            $rel_parts = array_merge(
    232241                $rel_parts,
     
    251260        $rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : '';
    252261
    253         $return = sprintf(
     262        $comment_author_link = sprintf(
    254263            '<a href="%1$s" class="url"%2$s>%3$s</a>',
    255             $url,
     264            $comment_author_url,
    256265            $rel,
    257             $author
     266            $comment_author
    258267        );
    259268    }
     
    263272     *
    264273     * @since 1.5.0
    265      * @since 4.1.0 The `$author` and `$comment_id` parameters were added.
    266      *
    267      * @param string $return    The HTML-formatted comment author link.
    268      *                           Empty for an invalid URL.
    269      * @param string $author     The comment author's username.
    270      * @param string $comment_id The comment ID as a numeric string.
    271      */
    272     return apply_filters( 'get_comment_author_link', $return, $author, $comment_id );
     274     * @since 4.1.0 The `$comment_author` and `$comment_id` parameters were added.
     275     *
     276     * @param string $comment_author_link The HTML-formatted comment author link.
     277     *                                    Empty for an invalid URL.
     278     * @param string $comment_author      The comment author's username.
     279     * @param string $comment_id          The comment ID as a numeric string.
     280     */
     281    return apply_filters( 'get_comment_author_link', $comment_author_link, $comment_author, $comment_id );
    273282}
    274283
     
    337346function get_comment_author_url( $comment_id = 0 ) {
    338347    $comment = get_comment( $comment_id );
    339     $url     = '';
    340     $id      = 0;
     348
     349    $comment_author_url = '';
     350    $comment_id         = 0;
    341351
    342352    if ( ! empty( $comment ) ) {
    343         $author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url;
    344         $url        = esc_url( $author_url, array( 'http', 'https' ) );
    345         $id         = $comment->comment_ID;
     353        $comment_author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url;
     354        $comment_author_url = esc_url( $comment_author_url, array( 'http', 'https' ) );
     355
     356        $comment_id = $comment->comment_ID;
    346357    }
    347358
     
    352363     * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
    353364     *
    354      * @param string          $url        The comment author's URL, or an empty string.
    355      * @param string|int      $comment_id The comment ID as a numeric string, or 0 if not found.
    356      * @param WP_Comment|null $comment    The comment object, or null if not found.
    357      */
    358     return apply_filters( 'get_comment_author_url', $url, $id, $comment );
     365     * @param string          $comment_author_url The comment author's URL, or an empty string.
     366     * @param string|int      $comment_id         The comment ID as a numeric string, or 0 if not found.
     367     * @param WP_Comment|null $comment            The comment object, or null if not found.
     368     */
     369    return apply_filters( 'get_comment_author_url', $comment_author_url, $comment_id, $comment );
    359370}
    360371
     
    369380 */
    370381function comment_author_url( $comment_id = 0 ) {
    371     $comment    = get_comment( $comment_id );
    372     $author_url = get_comment_author_url( $comment );
     382    $comment = get_comment( $comment_id );
     383
     384    $comment_author_url = get_comment_author_url( $comment );
    373385
    374386    /**
     
    378390     * @since 4.1.0 The `$comment_id` parameter was added.
    379391     *
    380      * @param string $author_url The comment author's URL.
    381      * @param string $comment_id The comment ID as a numeric string.
    382      */
    383     echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
     392     * @param string $comment_author_url The comment author's URL.
     393     * @param string $comment_id         The comment ID as a numeric string.
     394     */
     395    echo apply_filters( 'comment_url', $comment_author_url, $comment->comment_ID );
    384396}
    385397
     
    387399 * Retrieves the HTML link of the URL of the author of the current comment.
    388400 *
    389  * $linktext parameter is only used if the URL does not exist for the comment
    390  * author. If the URL does exist then the URL will be used and the $linktext
     401 * $link_text parameter is only used if the URL does not exist for the comment
     402 * author. If the URL does exist then the URL will be used and the $link_text
    391403 * will be ignored.
    392404 *
     
    397409 * @since 4.6.0 Added the `$comment` parameter.
    398410 *
    399  * @param string         $linktext Optional. The text to display instead of the comment
    400  *                                 author's email address. Default empty.
    401  * @param string         $before   Optional. The text or HTML to display before the email link.
    402  *                                 Default empty.
    403  * @param string         $after    Optional. The text or HTML to display after the email link.
    404  *                                 Default empty.
    405  * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object.
    406  *                                 Default is the current comment.
     411 * @param string         $link_text Optional. The text to display instead of the comment
     412 *                                  author's email address. Default empty.
     413 * @param string         $before    Optional. The text or HTML to display before the email link.
     414 *                                  Default empty.
     415 * @param string         $after     Optional. The text or HTML to display after the email link.
     416 *                                  Default empty.
     417 * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object.
     418 *                                  Default is the current comment.
    407419 * @return string The HTML link between the $before and $after parameters.
    408420 */
    409 function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
    410     $url     = get_comment_author_url( $comment );
    411     $display = ( '' !== $linktext ) ? $linktext : $url;
     421function get_comment_author_url_link( $link_text = '', $before = '', $after = '', $comment = 0 ) {
     422    $comment_author_url = get_comment_author_url( $comment );
     423
     424    $display = ( '' !== $link_text ) ? $link_text : $comment_author_url;
    412425    $display = str_replace( 'http://www.', '', $display );
    413426    $display = str_replace( 'http://', '', $display );
     
    417430    }
    418431
    419     $return = "$before<a href='$url' rel='external'>$display</a>$after";
     432    $comment_author_url_link = $before . sprintf(
     433        '<a href="%1$s" rel="external">%2$s</a>',
     434        $comment_author_url,
     435        $display
     436    ) . $after;
    420437
    421438    /**
     
    424441     * @since 1.5.0
    425442     *
    426      * @param string $return The HTML-formatted comment author URL link.
    427      */
    428     return apply_filters( 'get_comment_author_url_link', $return );
     443     * @param string $comment_author_url_link The HTML-formatted comment author URL link.
     444     */
     445    return apply_filters( 'get_comment_author_url_link', $comment_author_url_link );
    429446}
    430447
     
    435452 * @since 4.6.0 Added the `$comment` parameter.
    436453 *
    437  * @param string         $linktext Optional. Text to display instead of the comment author's
    438  *                                 email address. Default empty.
    439  * @param string         $before   Optional. Text or HTML to display before the email link.
    440  *                                 Default empty.
    441  * @param string         $after    Optional. Text or HTML to display after the email link.
    442  *                                 Default empty.
    443  * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object.
    444  *                                 Default is the current comment.
    445  */
    446 function comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
    447     echo get_comment_author_url_link( $linktext, $before, $after, $comment );
     454 * @param string         $link_text Optional. Text to display instead of the comment author's
     455 *                                  email address. Default empty.
     456 * @param string         $before    Optional. Text or HTML to display before the email link.
     457 *                                  Default empty.
     458 * @param string         $after     Optional. Text or HTML to display after the email link.
     459 *                                  Default empty.
     460 * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object.
     461 *                                  Default is the current comment.
     462 */
     463function comment_author_url_link( $link_text = '', $before = '', $after = '', $comment = 0 ) {
     464    echo get_comment_author_url_link( $link_text, $before, $after, $comment );
    448465}
    449466
     
    587604    $_format = ! empty( $format ) ? $format : get_option( 'date_format' );
    588605
    589     $date = mysql2date( $_format, $comment->comment_date );
     606    $comment_date = mysql2date( $_format, $comment->comment_date );
    590607
    591608    /**
     
    594611     * @since 1.5.0
    595612     *
    596      * @param string|int $date    Formatted date string or Unix timestamp.
    597      * @param string     $format  PHP date format.
    598      * @param WP_Comment $comment The comment object.
    599      */
    600     return apply_filters( 'get_comment_date', $date, $format, $comment );
     613     * @param string|int $comment_date Formatted date string or Unix timestamp.
     614     * @param string     $format       PHP date format.
     615     * @param WP_Comment $comment      The comment object.
     616     */
     617    return apply_filters( 'get_comment_date', $comment_date, $format, $comment );
    601618}
    602619
     
    648665    $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
    649666
    650     $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );
     667    $comment_excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );
    651668
    652669    /**
     
    656673     * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
    657674     *
    658      * @param string     $excerpt    The comment excerpt text.
    659      * @param string     $comment_id The comment ID as a numeric string.
    660      * @param WP_Comment $comment    The comment object.
    661      */
    662     return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
     675     * @param string     $comment_excerpt The comment excerpt text.
     676     * @param string     $comment_id      The comment ID as a numeric string.
     677     * @param WP_Comment $comment         The comment object.
     678     */
     679    return apply_filters( 'get_comment_excerpt', $comment_excerpt, $comment->comment_ID, $comment );
    663680}
    664681
     
    673690 */
    674691function comment_excerpt( $comment_id = 0 ) {
    675     $comment         = get_comment( $comment_id );
     692    $comment = get_comment( $comment_id );
     693
    676694    $comment_excerpt = get_comment_excerpt( $comment );
    677695
     
    696714 */
    697715function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    698     $comment    = get_comment();
     716    $comment = get_comment();
     717
    699718    $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';
    700719
     
    762781        'cpage'     => null,
    763782    );
    764     $args     = wp_parse_args( $args, $defaults );
    765 
    766     $link = get_permalink( $comment->comment_post_ID );
     783
     784    $args = wp_parse_args( $args, $defaults );
     785
     786    $comment_link = get_permalink( $comment->comment_post_ID );
    767787
    768788    // The 'cpage' param takes precedence.
     
    804824        if ( $wp_rewrite->using_permalinks() ) {
    805825            if ( $cpage ) {
    806                 $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
     826                $comment_link = trailingslashit( $comment_link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
    807827            }
    808828
    809             $link = user_trailingslashit( $link, 'comment' );
     829            $comment_link = user_trailingslashit( $comment_link, 'comment' );
    810830        } elseif ( $cpage ) {
    811             $link = add_query_arg( 'cpage', $cpage, $link );
     831            $comment_link = add_query_arg( 'cpage', $cpage, $comment_link );
    812832        }
    813833    }
    814834
    815835    if ( $wp_rewrite->using_permalinks() ) {
    816         $link = user_trailingslashit( $link, 'comment' );
    817     }
    818 
    819     $link = $link . '#comment-' . $comment->comment_ID;
     836        $comment_link = user_trailingslashit( $comment_link, 'comment' );
     837    }
     838
     839    $comment_link = $comment_link . '#comment-' . $comment->comment_ID;
    820840
    821841    /**
     
    827847     * @see get_page_of_comment()
    828848     *
    829      * @param string     $link    The comment permalink with '#comment-$id' appended.
    830      * @param WP_Comment $comment The current comment object.
    831      * @param array      $args    An array of arguments to override the defaults.
    832      * @param int        $cpage   The calculated 'cpage' value.
    833      */
    834     return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage );
     849     * @param string     $comment_link The comment permalink with '#comment-$id' appended.
     850     * @param WP_Comment $comment      The current comment object.
     851     * @param array      $args         An array of arguments to override the defaults.
     852     * @param int        $cpage        The calculated 'cpage' value.
     853     */
     854    return apply_filters( 'get_comment_link', $comment_link, $comment, $args, $cpage );
    835855}
    836856
     
    888908    $post = get_post( $post );
    889909
    890     $count  = $post ? $post->comment_count : 0;
    891     $post_id = $post ? $post->ID : 0;
     910    $comments_number = $post ? $post->comment_count : 0;
     911    $post_id         = $post ? $post->ID : 0;
    892912
    893913    /**
     
    896916     * @since 1.5.0
    897917     *
    898      * @param string|int $count  A string representing the number of comments a post has, otherwise 0.
     918     * @param string|int $comments_number A string representing the number of comments a post has, otherwise 0.
    899919     * @param int        $post_id Post ID.
    900920     */
    901     return apply_filters( 'get_comments_number', $count, $post_id );
     921    return apply_filters( 'get_comments_number', $comments_number, $post_id );
    902922}
    903923
     
    930950 */
    931951function get_comments_number_text( $zero = false, $one = false, $more = false, $post = 0 ) {
    932     $number = get_comments_number( $post );
    933 
    934     if ( $number > 1 ) {
     952    $comments_number = get_comments_number( $post );
     953
     954    if ( $comments_number > 1 ) {
    935955        if ( false === $more ) {
    936             /* translators: %s: Number of comments. */
    937             $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) );
     956            $comments_number_text = sprintf(
     957                /* translators: %s: Number of comments. */
     958                _n( '%s Comment', '%s Comments', $comments_number ),
     959                number_format_i18n( $comments_number )
     960            );
    938961        } else {
    939962            // % Comments
     
    950973                if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
    951974                    /* translators: %s: Number of comments. */
    952                     $new_text = _n( '%s Comment', '%s Comments', $number );
     975                    $new_text = _n( '%s Comment', '%s Comments', $comments_number );
    953976                    $new_text = trim( sprintf( $new_text, '' ) );
    954977
     
    960983            }
    961984
    962             $output = str_replace( '%', number_format_i18n( $number ), $more );
     985            $comments_number_text = str_replace( '%', number_format_i18n( $comments_number ), $more );
    963986        }
    964     } elseif ( 0 == $number ) {
    965         $output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
     987    } elseif ( 0 == $comments_number ) {
     988        $comments_number_text = ( false === $zero ) ? __( 'No Comments' ) : $zero;
    966989    } else { // Must be one.
    967         $output = ( false === $one ) ? __( '1 Comment' ) : $one;
    968     }
     990        $comments_number_text = ( false === $one ) ? __( '1 Comment' ) : $one;
     991    }
     992
    969993    /**
    970994     * Filters the comments count for display.
     
    974998     * @see _n()
    975999     *
    976      * @param string $output A translatable string formatted based on whether the count
    977      *                       is equal to 0, 1, or 1+.
    978      * @param int    $number The number of post comments.
    979      */
    980     return apply_filters( 'comments_number', $output, $number );
     1000     * @param string $comments_number_text A translatable string formatted based on whether the count
     1001     *                                     is equal to 0, 1, or 1+.
     1002     * @param int    $comments_number      The number of post comments.
     1003     */
     1004    return apply_filters( 'comments_number', $comments_number_text, $comments_number );
    9811005}
    9821006
     
    9981022    $comment = get_comment( $comment_id );
    9991023
    1000     $comment_content = $comment->comment_content;
     1024    $comment_text = $comment->comment_content;
    10011025
    10021026    if ( is_comment_feed() && $comment->comment_parent ) {
     
    10061030            $name        = get_comment_author( $parent );
    10071031
    1008             $comment_content = sprintf(
     1032            $comment_text = sprintf(
    10091033                /* translators: %s: Comment link. */
    10101034                ent2ncr( __( 'In reply to %s.' ) ),
    10111035                '<a href="' . $parent_link . '">' . $name . '</a>'
    1012             ) . "\n\n" . $comment_content;
     1036            ) . "\n\n" . $comment_text;
    10131037        }
    10141038    }
     
    10211045     * @see Walker_Comment::comment()
    10221046     *
    1023      * @param string     $comment_content Text of the comment.
    1024      * @param WP_Comment $comment         The comment object.
    1025      * @param array      $args            An array of arguments.
    1026      */
    1027     return apply_filters( 'get_comment_text', $comment_content, $comment, $args );
     1047     * @param string     $comment_text Text of the comment.
     1048     * @param WP_Comment $comment      The comment object.
     1049     * @param array      $args         An array of arguments.
     1050     */
     1051    return apply_filters( 'get_comment_text', $comment_text, $comment, $args );
    10281052}
    10291053
     
    10441068
    10451069    $comment_text = get_comment_text( $comment, $args );
     1070
    10461071    /**
    10471072     * Filters the text of a comment to be displayed.
     
    10511076     * @see Walker_Comment::comment()
    10521077     *
    1053      * @param string          $comment_text Text of the current comment.
     1078     * @param string          $comment_text Text of the comment.
    10541079     * @param WP_Comment|null $comment      The comment object. Null if not found.
    10551080     * @param array           $args         An array of arguments.
     
    10831108    $_format = ! empty( $format ) ? $format : get_option( 'time_format' );
    10841109
    1085     $date = mysql2date( $_format, $comment_date, $translate );
     1110    $comment_time = mysql2date( $_format, $comment_date, $translate );
    10861111
    10871112    /**
     
    10901115     * @since 1.5.0
    10911116     *
    1092      * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
    1093      * @param string     $format    PHP date format.
    1094      * @param bool       $gmt       Whether the GMT date is in use.
    1095      * @param bool       $translate Whether the time is translated.
    1096      * @param WP_Comment $comment   The comment object.
    1097      */
    1098     return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment );
     1117     * @param string|int $comment_time The comment time, formatted as a date string or Unix timestamp.
     1118     * @param string     $format       PHP date format.
     1119     * @param bool       $gmt          Whether the GMT date is in use.
     1120     * @param bool       $translate    Whether the time is translated.
     1121     * @param WP_Comment $comment      The comment object.
     1122     */
     1123    return apply_filters( 'get_comment_time', $comment_time, $format, $gmt, $translate, $comment );
    10991124}
    11001125
     
    12791304    $_post = get_post( $post );
    12801305
    1281     $post_id = $_post ? $_post->ID : 0;
    1282     $open    = ( $_post && ( 'open' === $_post->comment_status ) );
     1306    $post_id       = $_post ? $_post->ID : 0;
     1307    $comments_open = ( $_post && ( 'open' === $_post->comment_status ) );
    12831308
    12841309    /**
     
    12871312     * @since 2.5.0
    12881313     *
    1289      * @param bool $open    Whether the current post is open for comments.
    1290      * @param int  $post_id The post ID.
    1291      */
    1292     return apply_filters( 'comments_open', $open, $post_id );
     1314     * @param bool $comments_open Whether the current post is open for comments.
     1315     * @param int  $post_id       The post ID.
     1316     */
     1317    return apply_filters( 'comments_open', $comments_open, $post_id );
    12931318}
    12941319
     
    13081333    $_post = get_post( $post );
    13091334
    1310     $post_id = $_post ? $_post->ID : 0;
    1311     $open    = ( $_post && ( 'open' === $_post->ping_status ) );
     1335    $post_id    = $_post ? $_post->ID : 0;
     1336    $pings_open = ( $_post && ( 'open' === $_post->ping_status ) );
    13121337
    13131338    /**
     
    13161341     * @since 2.5.0
    13171342     *
    1318      * @param bool $open    Whether the current post is open for pings.
    1319      * @param int  $post_id The post ID.
    1320      */
    1321     return apply_filters( 'pings_open', $open, $post_id );
     1343     * @param bool $pings_open Whether the current post is open for pings.
     1344     * @param int  $post_id    The post ID.
     1345     */
     1346    return apply_filters( 'pings_open', $pings_open, $post_id );
    13221347}
    13231348
     
    16091634 */
    16101635function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
    1611     $post_id    = get_the_ID();
    1612     $post_title = get_the_title();
    1613     $number    = get_comments_number( $post_id );
     1636    $post_id         = get_the_ID();
     1637    $post_title      = get_the_title();
     1638    $comments_number = get_comments_number( $post_id );
    16141639
    16151640    if ( false === $zero ) {
     
    16251650    if ( false === $more ) {
    16261651        /* translators: 1: Number of comments, 2: Post title. */
    1627         $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number );
    1628         $more = sprintf( $more, number_format_i18n( $number ), $post_title );
     1652        $more = _n(
     1653            '%1$s Comment<span class="screen-reader-text"> on %2$s</span>',
     1654            '%1$s Comments<span class="screen-reader-text"> on %2$s</span>',
     1655            $comments_number
     1656        );
     1657        $more = sprintf( $more, number_format_i18n( $comments_number ), $post_title );
    16291658    }
    16301659
     
    16341663    }
    16351664
    1636     if ( 0 == $number && ! comments_open() && ! pings_open() ) {
    1637         echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
     1665    if ( 0 == $comments_number && ! comments_open() && ! pings_open() ) {
     1666        printf(
     1667            '<span%1$s>%2$s</span>',
     1668            ! empty( $css_class ) ? ' class="' . esc_attr( $css_class ) . '"' : '',
     1669            $none
     1670        );
    16381671        return;
    16391672    }
     
    16441677    }
    16451678
    1646     echo '<a href="';
    1647     if ( 0 == $number ) {
     1679    if ( 0 == $comments_number ) {
    16481680        $respond_link = get_permalink() . '#respond';
    16491681        /**
     
    16551687         * @param int    $post_id      The post ID.
    16561688         */
    1657         echo apply_filters( 'respond_link', $respond_link, $post_id );
     1689        $comments_link = apply_filters( 'respond_link', $respond_link, $post_id );
    16581690    } else {
    1659         comments_link();
    1660     }
    1661     echo '"';
    1662 
    1663     if ( ! empty( $css_class ) ) {
    1664         echo ' class="' . $css_class . '" ';
    1665     }
    1666 
    1667     $attributes = '';
     1691        $comments_link = get_comments_link();
     1692    }
     1693
     1694    $link_attributes = '';
     1695
    16681696    /**
    16691697     * Filters the comments link attributes for display.
     
    16711699     * @since 2.5.0
    16721700     *
    1673      * @param string $attributes The comments link attributes. Default empty.
    1674      */
    1675     echo apply_filters( 'comments_popup_link_attributes', $attributes );
    1676 
    1677     echo '>';
    1678     comments_number( $zero, $one, $more );
    1679     echo '</a>';
     1701     * @param string $link_attributes The comments link attributes. Default empty.
     1702     */
     1703    $link_attributes = apply_filters( 'comments_popup_link_attributes', $link_attributes );
     1704
     1705    printf(
     1706        '<a href="%1$s"%2$s%3$s>%4$s</a>',
     1707        esc_url( $comments_link ),
     1708        ! empty( $css_class ) ? ' class="' . $css_class . '" ' : '',
     1709        $link_attributes,
     1710        get_comments_number_text( $zero, $one, $more )
     1711    );
    16801712}
    16811713
     
    18031835    }
    18041836
     1837    $comment_reply_link = $args['before'] . $link . $args['after'];
     1838
    18051839    /**
    18061840     * Filters the comment reply link.
     
    18081842     * @since 2.7.0
    18091843     *
    1810      * @param string     $link    The HTML markup for the comment reply link.
    1811      * @param array      $args    An array of arguments overriding the defaults.
    1812      * @param WP_Comment $comment The object of the comment being replied.
    1813      * @param WP_Post    $post    The WP_Post object.
    1814      */
    1815     return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
     1844     * @param string     $comment_reply_link The HTML markup for the comment reply link.
     1845     * @param array      $args               An array of arguments overriding the defaults.
     1846     * @param WP_Comment $comment            The object of the comment being replied.
     1847     * @param WP_Post    $post               The WP_Post object.
     1848     */
     1849    return apply_filters( 'comment_reply_link', $comment_reply_link, $args, $comment, $post );
    18161850}
    18171851
     
    18941928        );
    18951929    }
    1896     $formatted_link = $args['before'] . $link . $args['after'];
     1930
     1931    $post_reply_link = $args['before'] . $link . $args['after'];
    18971932
    18981933    /**
     
    19011936     * @since 2.7.0
    19021937     *
    1903      * @param string      $formatted The HTML-formatted post comments link.
    1904      * @param int|WP_Post $post      The post ID or WP_Post object.
    1905      */
    1906     return apply_filters( 'post_comments_link', $formatted_link, $post );
     1938     * @param string      $post_reply_link The HTML-formatted post comments link.
     1939     * @param int|WP_Post $post            The post ID or WP_Post object.
     1940     */
     1941    return apply_filters( 'post_comments_link', $post_reply_link, $post );
    19071942}
    19081943
     
    19281963 * @since 6.2.0 Added the `$post` parameter.
    19291964 *
    1930  * @param string           $text Optional. Text to display for cancel reply link. If empty,
    1931  *                               defaults to 'Click here to cancel reply'. Default empty.
    1932  * @param int|WP_Post|null $post Optional. The post the comment thread is being
    1933  *                               displayed for. Defaults to the current global post.
     1965 * @param string           $link_text Optional. Text to display for cancel reply link. If empty,
     1966 *                                    defaults to 'Click here to cancel reply'. Default empty.
     1967 * @param int|WP_Post|null $post      Optional. The post the comment thread is being
     1968 *                                    displayed for. Defaults to the current global post.
    19341969 * @return string
    19351970 */
    1936 function get_cancel_comment_reply_link( $text = '', $post = null ) {
    1937     if ( empty( $text ) ) {
    1938         $text = __( 'Click here to cancel reply.' );
     1971function get_cancel_comment_reply_link( $link_text = '', $post = null ) {
     1972    if ( empty( $link_text ) ) {
     1973        $link_text = __( 'Click here to cancel reply.' );
    19391974    }
    19401975
    19411976    $post        = get_post( $post );
    19421977    $reply_to_id = $post ? _get_comment_reply_id( $post->ID ) : 0;
    1943     $style       = 0 !== $reply_to_id ? '' : ' style="display:none;"';
    1944     $link        = esc_url( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';
    1945 
    1946     $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
     1978    $link_style  = 0 !== $reply_to_id ? '' : ' style="display:none;"';
     1979    $link_url    = esc_url( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';
     1980
     1981    $cancel_comment_reply_link = sprintf(
     1982        '<a rel="nofollow" id="cancel-comment-reply-link" href="%1$s"%2$s>%3$s</a>',
     1983        $link_url,
     1984        $link_style,
     1985        $link_text
     1986    );
    19471987
    19481988    /**
     
    19511991     * @since 2.7.0
    19521992     *
    1953      * @param string $formatted_link The HTML-formatted cancel comment reply link.
    1954      * @param string $link           Cancel comment reply link URL.
    1955      * @param string $text           Cancel comment reply link text.
    1956      */
    1957     return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
     1993     * @param string $cancel_comment_reply_link The HTML-formatted cancel comment reply link.
     1994     * @param string $link_url                  Cancel comment reply link URL.
     1995     * @param string $link_text                 Cancel comment reply link text.
     1996     */
     1997    return apply_filters( 'cancel_comment_reply_link', $cancel_comment_reply_link, $link_url, $link_text );
    19581998}
    19591999
     
    19632003 * @since 2.7.0
    19642004 *
    1965  * @param string $text Optional. Text to display for cancel reply link. If empty,
     2005 * @param string $link_text Optional. Text to display for cancel reply link. If empty,
    19662006 *                     defaults to 'Click here to cancel reply'. Default empty.
    19672007 */
    1968 function cancel_comment_reply_link( $text = '' ) {
    1969     echo get_cancel_comment_reply_link( $text );
     2008function cancel_comment_reply_link( $link_text = '' ) {
     2009    echo get_cancel_comment_reply_link( $link_text );
    19702010}
    19712011
     
    19882028    $post_id     = $post->ID;
    19892029    $reply_to_id = _get_comment_reply_id( $post_id );
    1990     $result      = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
    1991     $result     .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";
     2030
     2031    $comment_id_fields  = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
     2032    $comment_id_fields .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";
    19922033
    19932034    /**
     
    19962037     * @since 3.0.0
    19972038     *
    1998      * @param string $result      The HTML-formatted hidden ID field comment elements.
    1999      * @param int    $post_id     The post ID.
    2000      * @param int    $reply_to_id The ID of the comment being replied to.
    2001      */
    2002     return apply_filters( 'comment_id_fields', $result, $post_id, $reply_to_id );
     2039     * @param string $comment_id_fields The HTML-formatted hidden ID field comment elements.
     2040     * @param int    $post_id           The post ID.
     2041     * @param int    $reply_to_id       The ID of the comment being replied to.
     2042     */
     2043    return apply_filters( 'comment_id_fields', $comment_id_fields, $post_id, $reply_to_id );
    20032044}
    20042045
     
    20752116
    20762117    if ( $link_to_parent ) {
    2077         $author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $reply_to_id ) . '</a>';
     2118        $comment_author = sprintf(
     2119            '<a href="#comment-%1$s">%2$s</a>',
     2120            get_comment_ID(),
     2121            get_comment_author( $reply_to_id )
     2122        );
    20782123    } else {
    2079         $author = get_comment_author( $reply_to_id );
    2080     }
    2081 
    2082     printf( $reply_text, $author );
     2124        $comment_author = get_comment_author( $reply_to_id );
     2125    }
     2126
     2127    printf( $reply_text, $comment_author );
    20832128}
    20842129
Note: See TracChangeset for help on using the changeset viewer.