Make WordPress Core

Changeset 53285


Ignore:
Timestamp:
04/26/2022 03:06:32 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/comment-template.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit:

  • Renames the $class parameter to $css_class in comment_class() and get_comment_class().
  • Renames the $echo parameter to $display in comment_class().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.

File:
1 edited

Legend:

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

    r53265 r53285  
    424424 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
    425425 *
    426  * @param string|string[] $class    Optional. One or more classes to add to the class list.
    427  *                                  Default empty.
    428  * @param int|WP_Comment  $comment  Comment ID or WP_Comment object. Default current comment.
    429  * @param int|WP_Post     $post_id  Post ID or WP_Post object. Default current post.
    430  * @param bool            $echo     Optional. Whether to echo or return the output.
    431  *                                  Default true.
    432  * @return void|string Void if `$echo` argument is true, comment classes if `$echo` is false.
    433  */
    434 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {
     426 * @param string|string[] $css_class Optional. One or more classes to add to the class list.
     427 *                                   Default empty.
     428 * @param int|WP_Comment  $comment   Comment ID or WP_Comment object. Default current comment.
     429 * @param int|WP_Post     $post_id   Post ID or WP_Post object. Default current post.
     430 * @param bool            $display   Optional. Whether to print or return the output.
     431 *                                   Default true.
     432 * @return void|string Void if `$display` argument is true, comment classes if `$display` is false.
     433 */
     434function comment_class( $css_class = '', $comment = null, $post_id = null, $display = true ) {
    435435    // Separates classes with a single space, collates classes for comment DIV.
    436     $class = 'class="' . implode( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
    437 
    438     if ( $echo ) {
    439         echo $class;
     436    $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post_id ) ) . '"';
     437
     438    if ( $display ) {
     439        echo $css_class;
    440440    } else {
    441         return $class;
     441        return $css_class;
    442442    }
    443443}
     
    453453 * @global int $comment_thread_alt
    454454 *
    455  * @param string|string[] $class      Optional. One or more classes to add to the class list. Default empty.
     455 * @param string|string[] $css_class  Optional. One or more classes to add to the class list. Default empty.
    456456 * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
    457457 * @param int|WP_Post     $post_id    Post ID or WP_Post object. Default current post.
    458458 * @return string[] An array of classes.
    459459 */
    460 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
     460function get_comment_class( $css_class = '', $comment_id = null, $post_id = null ) {
    461461    global $comment_alt, $comment_depth, $comment_thread_alt;
    462462
     
    517517    $classes[] = "depth-$comment_depth";
    518518
    519     if ( ! empty( $class ) ) {
    520         if ( ! is_array( $class ) ) {
    521             $class = preg_split( '#\s+#', $class );
     519    if ( ! empty( $css_class ) ) {
     520        if ( ! is_array( $css_class ) ) {
     521            $css_class = preg_split( '#\s+#', $css_class );
    522522        }
    523         $classes = array_merge( $classes, $class );
     523        $classes = array_merge( $classes, $css_class );
    524524    }
    525525
     
    532532     *
    533533     * @param string[]    $classes    An array of comment classes.
    534      * @param string[]    $class      An array of additional classes added to the list.
     534     * @param string[]    $css_class  An array of additional classes added to the list.
    535535     * @param string      $comment_id The comment ID as a numeric string.
    536536     * @param WP_Comment  $comment    The comment object.
    537537     * @param int|WP_Post $post_id    The post ID or WP_Post object.
    538538     */
    539     return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id );
     539    return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post_id );
    540540}
    541541
Note: See TracChangeset for help on using the changeset viewer.