Make WordPress Core

Changeset 54956

Timestamp:
12/11/2022 01:40:18 PM (20 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/post-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 $echo parameter to $display in the_title().
  • Renames the $class parameter to $css_class in:
    • post_class()
    • get_post_class()
    • body_class()
    • get_body_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], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952].

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

File:
1 edited

Legend:

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

    r54891 r54956  
    3535 * @since 0.71
    3636 *
    37  * @param string $before Optional. Markup to prepend to the title. Default empty.
    38  * @param string $after  Optional. Markup to append to the title. Default empty.
    39  * @param bool   $echo  Optional. Whether to echo or return the title. Default true for echo.
    40  * @return void|string Void if `$echo` argument is true, current post title if `$echo` is false.
    41  */
    42 function the_title( $before = '', $after = '', $echo = true ) {
     37 * @param string $before Optional. Markup to prepend to the title. Default empty.
     38 * @param string $after  Optional. Markup to append to the title. Default empty.
     39 * @param bool   $ Optional. Whether to echo or return the title. Default true for echo.
     40 * @return void|string Void if `$` is false.
     41 */
     42function the_title( $before = '', $after = '', $ = true ) {
    4343    $title = get_the_title();
    4444
     
    4949    $title = $before . $title . $after;
    5050
    51     if ( $echo ) {
     51    if ( $ ) {
    5252        echo $title;
    5353    } else {
     
    454454 * @since 2.7.0
    455455 *
    456  * @param string|string[] $class One or more classes to add to the class list.
    457  * @param int|WP_Post     $post  Optional. Post ID or post object. Defaults to the global `$post`.
    458  */
    459 function post_class( $class = '', $post = null ) {
     456 * @param string|string[] $css_class Optional. One or more classes to add to the class list.
     457 *                                   Default empty.
     458 * @param int|WP_Post     $post      Optional. Post ID or post object. Defaults to the global `$post`.
     459 */
     460function post_class( $css_class = '', $post = null ) {
    460461    // Separates classes with a single space, collates classes for post DIV.
    461     echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post ) ) ) . '"';
     462    echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post ) ) ) . '"';
    462463}
    463464
     
    474475 * case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
    475476 * passed through the filter, {@see 'post_class'}, with the list of class names, followed by
    476  * $class parameter value, with the post ID as the last parameter.
     477 * $class parameter value, with the post ID as the last parameter.
    477478 *
    478479 * @since 2.7.0
    479480 * @since 4.2.0 Custom taxonomy class names were added.
    480481 *
    481  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
    482  * @param int|WP_Post     $post  Optional. Post ID or post object.
     482 * @param string|string[] $css_class Optional. Space-separated string or array of class names
     483 *                                   to add to the class list. Default empty.
     484 * @param int|WP_Post     $post      Optional. Post ID or post object.
    483485 * @return string[] Array of class names.
    484486 */
    485 function get_post_class( $class = '', $post = null ) {
     487function get_post_class( $class = '', $post = null ) {
    486488    $post = get_post( $post );
    487489
    488490    $classes = array();
    489491
    490     if ( $class ) {
    491         if ( ! is_array( $class ) ) {
    492             $class = preg_split( '#\s+#', $class );
    493         }
    494         $classes = array_map( 'esc_attr', $class );
     492    if ( $class ) {
     493        if ( ! is_array( $class ) ) {
     494            $cclass );
     495        }
     496        $classes = array_map( 'esc_attr', $class );
    495497    } else {
    496498        // Ensure that we always coerce class to being an array.
    497         $class = array();
     499        $class = array();
    498500    }
    499501
     
    559561     * @param int      $post_id    The post ID.
    560562     * @param string[] $classes    An array of post class names.
    561      * @param string[] $class      An array of additional class names added to the post.
     563     * @param string[] $c  An array of additional class names added to the post.
    562564    */
    563     $taxonomies = apply_filters( 'post_class_taxonomies', $taxonomies, $post->ID, $classes, $class );
     565    $taxonomies = apply_filters( 'post_class_taxonomies', $taxonomies, $post->ID, $classes, $class );
    564566
    565567    foreach ( (array) $taxonomies as $taxonomy ) {
     
    592594     * @since 2.7.0
    593595     *
    594      * @param string[] $classes An array of post class names.
    595      * @param string[] $class  An array of additional class names added to the post.
    596      * @param int      $post_id The post ID.
     596     * @param string[] $classes An array of post class names.
     597     * @param string[] $c An array of additional class names added to the post.
     598     * @param int      $post_id The post ID.
    597599     */
    598     $classes = apply_filters( 'post_class', $classes, $class, $post->ID );
     600    $classes = apply_filters( 'post_class', $classes, $class, $post->ID );
    599601
    600602    return array_unique( $classes );
     
    606608 * @since 2.8.0
    607609 *
    608  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
    609  */
    610 function body_class( $class = '' ) {
     610 * @param string|string[] $css_class Optional. Space-separated string or array of class names
     611 *                                   to add to the class list. Default empty.
     612 */
     613function body_class( $css_class = '' ) {
    611614    // Separates class names with a single space, collates class names for body element.
    612     echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"';
     615    echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"';
    613616}
    614617
     
    620623 * @global WP_Query $wp_query WordPress Query object.
    621624 *
    622  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
     625 * @param string|string[] $css_class Optional. Space-separated string or array of class names
     626 *                                   to add to the class list. Default empty.
    623627 * @return string[] Array of class names.
    624628 */
    625 function get_body_class( $class = '' ) {
     629function get_body_class( $class = '' ) {
    626630    global $wp_query;
    627631
     
    831835    }
    832836
    833     if ( ! empty( $class ) ) {
    834         if ( ! is_array( $class ) ) {
    835             $class = preg_split( '#\s+#', $class );
    836         }
    837         $classes = array_merge( $classes, $class );
     837    if ( ! empty( $class ) ) {
     838        if ( ! is_array( $class ) ) {
     839            $cclass );
     840        }
     841        $classes = array_merge( $classes, $class );
    838842    } else {
    839843        // Ensure that we always coerce class to being an array.
    840         $class = array();
     844        $class = array();
    841845    }
    842846
     
    848852     * @since 2.8.0
    849853     *
    850      * @param string[] $classes An array of body class names.
    851      * @param string[] $class  An array of additional class names added to the body.
     854     * @param string[] $classes An array of body class names.
     855     * @param string[] $c An array of additional class names added to the body.
    852856     */
    853     $classes = apply_filters( 'body_class', $classes, $class );
     857    $classes = apply_filters( 'body_class', $classes, $class );
    854858
    855859    return array_unique( $classes );
Note: See TracChangeset for help on using the changeset viewer.