WordPress.org

Make WordPress Core

Changeset 51779


Ignore:
Timestamp:
09/09/2021 12:38:36 PM (3 weeks ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix last parameter name mismatches for parent/child classes in Walker::start_el().

The parent class uses $current_object_id while most of the child classes use $id. As the parent class' is more descriptive, renaming the last parameter in each of child class.

Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Changes for readability:

  • @since clearly specifies the original parameter name and its new name as well as why the change happened.
  • In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.
  • In cases where the original parameter name was too generic or misleading, renamed (when reassigning) to a more descriptive name for use within the method.

Follow-up to [7737], [8900], [8970], [14248], [15077], [16100], [25642], [25644], [37051], [37054], [37056], [46271], [47189], [51739].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-category-checklist.php

    r51739 r51779  
    6262     *
    6363     * @since 2.5.1
    64      * @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
     64     * @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
     65     *              to match parent class for PHP 8 named parameter support.
    6566     *
    66      * @param string  $output      Used to append additional content (passed by reference).
    67      * @param WP_Term $data_object The current term object.
    68      * @param int     $depth       Depth of the term in reference to parents. Default 0.
    69      * @param array   $args        An array of arguments. @see wp_terms_checklist()
    70      * @param int     $id          ID of the current term.
     67     * @param string  $output            Used to append additional content (passed by reference).
     68     * @param WP_Term $data_object       The current term object.
     69     * @param int     $depth             Depth of the term in reference to parents. Default 0.
     70     * @param array   $args              An array of arguments. @see wp_terms_checklist()
     71     * @param int     $current_object_id Optional. ID of the current term. Default 0.
    7172     */
    72     public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
     73    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    7374        // Restores the more descriptive, specific name for use within this method.
    7475        $category = $data_object;
  • trunk/src/wp-admin/includes/class-walker-nav-menu-checklist.php

    r51739 r51779  
    6262     *
    6363     * @since 3.0.0
    64      * @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
     64     * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
     65     *              to match parent class for PHP 8 named parameter support.
    6566     *
    6667     * @global int        $_nav_menu_placeholder
    6768     * @global int|string $nav_menu_selected_id
    6869     *
    69      * @param string   $output      Used to append additional content (passed by reference).
    70      * @param WP_Post  $data_object Menu item data object.
    71      * @param int      $depth       Depth of menu item. Used for padding.
    72      * @param stdClass $args        Not used.
    73      * @param int      $id          Not used.
     70     * @param string   $output            Used to append additional content (passed by reference).
     71     * @param WP_Post  $data_object       Menu item data object.
     72     * @param int      $depth             Depth of menu item. Used for padding.
     73     * @param stdClass $args              Not used.
     74     * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
    7475     */
    75     public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
     76    public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
    7677        global $_nav_menu_placeholder, $nav_menu_selected_id;
    7778
  • trunk/src/wp-admin/includes/class-walker-nav-menu-edit.php

    r51739 r51779  
    4747     * @see Walker_Nav_Menu::start_el()
    4848     * @since 3.0.0
    49      * @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
     49     * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
     50     *              to match parent class for PHP 8 named parameter support.
    5051     *
    5152     * @global int $_wp_nav_menu_max_depth
    5253     *
    53      * @param string   $output      Used to append additional content (passed by reference).
    54      * @param WP_Post  $data_object Menu item data object.
    55      * @param int      $depth       Depth of menu item. Used for padding.
    56      * @param stdClass $args        Not used.
    57      * @param int      $id          Not used.
     54     * @param string   $output            Used to append additional content (passed by reference).
     55     * @param WP_Post  $data_object       Menu item data object.
     56     * @param int      $depth             Depth of menu item. Used for padding.
     57     * @param stdClass $args              Not used.
     58     * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
    5859     */
    59     public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
     60    public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
    6061        global $_wp_nav_menu_max_depth;
    6162
     
    242243                 * @since 5.4.0
    243244                 *
    244                  * @param int      $item_id   Menu item ID.
    245                  * @param WP_Post  $menu_item Menu item data object.
    246                  * @param int      $depth     Depth of menu item. Used for padding.
    247                  * @param stdClass $args      An object of menu item arguments.
    248                  * @param int      $id        Nav menu ID.
     245                 * @param int      $item_id           Menu item ID.
     246                 * @param WP_Post  $menu_item         Menu item data object.
     247                 * @param int      $depth             Depth of menu item. Used for padding.
     248                 * @param stdClass $args              An object of menu item arguments.
     249                 * @param int      $current_object_id Nav menu ID.
    249250                 */
    250                 do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $id );
     251                do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
    251252                ?>
    252253
  • trunk/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-page.php

    r51739 r51779  
    2121         *
    2222         * @since Twenty Twenty 1.0
    23          * @since Twenty Twenty 1.9 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
     23         * @since Twenty Twenty 1.9 Renamed `$page` to `$data_object` and `$current_page` to `$current_object_id`
     24         *                          to match parent class for PHP 8 named parameter support.
    2425         *
    2526         * @see Walker::start_el()
    2627         *
    27          * @param string  $output       Used to append additional content. Passed by reference.
    28          * @param WP_Post $data_object  Page data object.
    29          * @param int     $depth        Optional. Depth of page. Used for padding. Default 0.
    30          * @param array   $args         Optional. Array of arguments. Default empty array.
    31          * @param int     $current_page Optional. Page ID. Default 0.
     28         * @param string  $output            Used to append additional content. Passed by reference.
     29         * @param WP_Post $data_object       Page data object.
     30         * @param int     $depth             Optional. Depth of page. Used for padding. Default 0.
     31         * @param array   $args              Optional. Array of arguments. Default empty array.
     32         * @param int     $current_object_id Optional. ID of the current page. Default 0.
    3233         */
    33         public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_page = 0 ) {
     34        public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    3435            // Restores the more descriptive, specific name for use within this method.
    35             $page = $data_object;
     36            $page            = $data_object;
     37            $current_page_id = $current_object_id;
    3638
    3739            if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
     
    5456            }
    5557
    56             if ( ! empty( $current_page ) ) {
    57                 $_current_page = get_post( $current_page );
     58            if ( ! empty( $current_page_id ) ) {
     59                $_current_page = get_post( $current_page_id );
    5860                if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
    5961                    $css_class[] = 'current_page_ancestor';
    6062                }
    61                 if ( $page->ID === $current_page ) {
     63                if ( $page->ID === $current_page_id ) {
    6264                    $css_class[] = 'current_page_item';
    6365                } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
     
    6971
    7072            /** This filter is documented in wp-includes/class-walker-page.php */
    71             $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
     73            $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) );
    7274            $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
    7375
     
    8284            $atts                 = array();
    8385            $atts['href']         = get_permalink( $page->ID );
    84             $atts['aria-current'] = ( $page->ID === $current_page ) ? 'page' : '';
     86            $atts['aria-current'] = ( $page->ID === $current_page_id ) ? 'page' : '';
    8587
    8688            /** This filter is documented in wp-includes/class-walker-page.php */
    87             $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
     89            $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );
    8890
    8991            $attributes = '';
  • trunk/src/wp-includes/class-walker-category-dropdown.php

    r51739 r51779  
    4545     *
    4646     * @since 2.1.0
    47      * @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
     47     * @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
     48     *              to match parent class for PHP 8 named parameter support.
    4849     *
    4950     * @see Walker::start_el()
    5051     *
    51      * @param string  $output      Used to append additional content (passed by reference).
    52      * @param WP_Term $data_object Category data object.
    53      * @param int     $depth       Depth of category. Used for padding.
    54      * @param array   $args        Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
    55      *                             See wp_dropdown_categories().
    56      * @param int     $id          Optional. ID of the current category. Default 0 (unused).
     52     * @param string  $output            Used to append additional content (passed by reference).
     53     * @param WP_Term $data_object       Category data object.
     54     * @param int     $depth             Depth of category. Used for padding.
     55     * @param array   $args              Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
     56     *                                   See wp_dropdown_categories().
     57     * @param int     $current_object_id Optional. ID of the current category. Default 0.
    5758     */
    58     public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
     59    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    5960        // Restores the more descriptive, specific name for use within this method.
    6061        $category = $data_object;
  • trunk/src/wp-includes/class-walker-category.php

    r51739 r51779  
    8787     *
    8888     * @since 2.1.0
    89      * @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
     89     * @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
     90     *              to match parent class for PHP 8 named parameter support.
    9091     *
    9192     * @see Walker::start_el()
    9293     *
    93      * @param string  $output      Used to append additional content (passed by reference).
    94      * @param WP_Term $data_object Category data object.
    95      * @param int     $depth       Optional. Depth of category in reference to parents. Default 0.
    96      * @param array   $args        Optional. An array of arguments. See wp_list_categories().
    97      *                             Default empty array.
    98      * @param int     $id          Optional. ID of the current category. Default 0.
    99      */
    100     public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
     94     * @param string  $output            Used to append additional content (passed by reference).
     95     * @param WP_Term $data_object       Category data object.
     96     * @param int     $depth             Optional. Depth of category in reference to parents. Default 0.
     97     * @param array   $args              Optional. An array of arguments. See wp_list_categories().
     98     *                                   Default empty array.
     99     * @param int     $current_object_id Optional. ID of the current category. Default 0.
     100     */
     101    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    101102        // Restores the more descriptive, specific name for use within this method.
    102103        $category = $data_object;
     
    136137         *     @type string $title The title attribute.
    137138         * }
    138          * @param WP_Term $category Term data object.
    139          * @param int     $depth    Depth of category, used for padding.
    140          * @param array   $args     An array of arguments.
    141          * @param int     $id      ID of the current category.
     139         * @param WP_Term $category          Term data object.
     140         * @param int     $depth             Depth of category, used for padding.
     141         * @param array   $args              An array of arguments.
     142         * @param int     $current_object_id ID of the current category.
    142143         */
    143         $atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id );
     144        $atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $current_object_id );
    144145
    145146        $attributes = '';
  • trunk/src/wp-includes/class-walker-comment.php

    r51739 r51779  
    158158     *
    159159     * @since 2.7.0
    160      * @since 5.9.0 Renamed `$comment` to `$data_object` to match parent class for PHP 8 named parameter support.
     160     * @since 5.9.0 Renamed `$comment` to `$data_object` and `$id` to `$current_object_id`
     161     *              to match parent class for PHP 8 named parameter support.
    161162     *
    162163     * @see Walker::start_el()
     
    165166     * @global WP_Comment $comment       Global comment object.
    166167     *
    167      * @param string     $output      Used to append additional content. Passed by reference.
    168      * @param WP_Comment $data_object Comment data object.
    169      * @param int        $depth       Optional. Depth of the current comment in reference to parents. Default 0.
    170      * @param array      $args        Optional. An array of arguments. Default empty array.
    171      * @param int        $id          Optional. ID of the current comment. Default 0 (unused).
    172      */
    173     public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
     168     * @param string     $output            Used to append additional content. Passed by reference.
     169     * @param WP_Comment $data_object       Comment data object.
     170     * @param int        $depth             Optional. Depth of the current comment in reference to parents. Default 0.
     171     * @param array      $args              Optional. An array of arguments. Default empty array.
     172     * @param int        $current_object_id Optional. ID of the current comment. Default 0.
     173     */
     174    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    174175        // Restores the more descriptive, specific name for use within this method.
    175176        $comment = $data_object;
  • trunk/src/wp-includes/class-walker-nav-menu.php

    r51739 r51779  
    107107     * @since 3.0.0
    108108     * @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added.
    109      * @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
     109     * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
     110     *              to match parent class for PHP 8 named parameter support.
    110111     *
    111112     * @see Walker::start_el()
    112113     *
    113      * @param string   $output      Used to append additional content (passed by reference).
    114      * @param WP_Post  $data_object Menu item data object.
    115      * @param int      $depth       Depth of menu item. Used for padding.
    116      * @param stdClass $args        An object of wp_nav_menu() arguments.
    117      * @param int      $id          Current item ID.
    118      */
    119     public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
     114     * @param string   $output            Used to append additional content (passed by reference).
     115     * @param WP_Post  $data_object       Menu item data object.
     116     * @param int      $depth             Depth of menu item. Used for padding.
     117     * @param stdClass $args              An object of wp_nav_menu() arguments.
     118     * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
     119     */
     120    public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
    120121        // Restores the more descriptive, specific name for use within this method.
    121122        $menu_item = $data_object;
  • trunk/src/wp-includes/class-walker-page-dropdown.php

    r51739 r51779  
    4545     *
    4646     * @since 2.1.0
    47      * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
     47     * @since 5.9.0 Renamed `$page` to `$data_object` and `$id` to `$current_object_id`
     48     *              to match parent class for PHP 8 named parameter support.
    4849     *
    4950     * @see Walker::start_el()
    5051     *
    51      * @param string  $output      Used to append additional content. Passed by reference.
    52      * @param WP_Post $data_object Page data object.
    53      * @param int     $depth       Optional. Depth of page in reference to parent pages. Used for padding.
    54      *                             Default 0.
    55      * @param array   $args        Optional. Uses 'selected' argument for selected page to set selected HTML
    56      *                             attribute for option element. Uses 'value_field' argument to fill "value"
    57      *                             attribute. See wp_dropdown_pages(). Default empty array.
    58      * @param int     $id          Optional. ID of the current page. Default 0 (unused).
     52     * @param string  $output             Used to append additional content. Passed by reference.
     53     * @param WP_Post $data_object        Page data object.
     54     * @param int     $depth              Optional. Depth of page in reference to parent pages.
     55     *                                    Used for padding. Default 0.
     56     * @param array   $args               Optional. Uses 'selected' argument for selected page to
     57     *                                    set selected HTML attribute for option element. Uses
     58     *                                    'value_field' argument to fill "value" attribute.
     59     *                                    See wp_dropdown_pages(). Default empty array.
     60     * @param int     $current_object_id  Optional. ID of the current page. Default 0.
    5961     */
    60     public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
     62    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    6163        // Restores the more descriptive, specific name for use within this method.
    6264        $page = $data_object;
  • trunk/src/wp-includes/class-walker-page.php

    r51739 r51779  
    9494     * @see Walker::start_el()
    9595     * @since 2.1.0
    96      * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
    97      *
    98      * @param string  $output       Used to append additional content. Passed by reference.
    99      * @param WP_Post $data_object  Page data object.
    100      * @param int     $depth        Optional. Depth of page. Used for padding. Default 0.
    101      * @param array   $args         Optional. Array of arguments. Default empty array.
    102      * @param int     $current_page Optional. Page ID. Default 0.
    103      */
    104     public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_page = 0 ) {
     96     * @since 5.9.0 Renamed `$page` to `$data_object` and `$current_page` to `$current_object_id`
     97     *              to match parent class for PHP 8 named parameter support.
     98     *
     99     * @param string  $output            Used to append additional content. Passed by reference.
     100     * @param WP_Post $data_object       Page data object.
     101     * @param int     $depth             Optional. Depth of page. Used for padding. Default 0.
     102     * @param array   $args              Optional. Array of arguments. Default empty array.
     103     * @param int     $current_object_id Optional. ID of the current page. Default 0.
     104     */
     105    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    105106        // Restores the more descriptive, specific name for use within this method.
    106         $page = $data_object;
     107        $page            = $data_object;
     108        $current_page_id = $current_object_id;
    107109
    108110        if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
     
    125127        }
    126128
    127         if ( ! empty( $current_page ) ) {
    128             $_current_page = get_post( $current_page );
     129        if ( ! empty( $current_page_id ) ) {
     130            $_current_page = get_post( $current_page_id );
    129131
    130132            if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
     
    132134            }
    133135
    134             if ( $page->ID == $current_page ) {
     136            if ( $page->ID == $current_page_id ) {
    135137                $css_class[] = 'current_page_item';
    136138            } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
     
    148150         * @see wp_list_pages()
    149151         *
    150          * @param string[] $css_class    An array of CSS classes to be applied to each list item.
    151          * @param WP_Post  $page         Page data object.
    152          * @param int      $depth        Depth of page, used for padding.
    153          * @param array    $args         An array of arguments.
    154          * @param int      $current_page ID of the current page.
     152         * @param string[] $css_class       An array of CSS classes to be applied to each list item.
     153         * @param WP_Post  $page            Page data object.
     154         * @param int      $depth           Depth of page, used for padding.
     155         * @param array    $args            An array of arguments.
     156         * @param int      $current_page_id ID of the current page.
    155157         */
    156         $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
     158        $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) );
    157159        $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
    158160
     
    167169        $atts                 = array();
    168170        $atts['href']         = get_permalink( $page->ID );
    169         $atts['aria-current'] = ( $page->ID == $current_page ) ? 'page' : '';
     171        $atts['aria-current'] = ( $page->ID == $current_page_id ) ? 'page' : '';
    170172
    171173        /**
     
    180182         *     @type string $aria-current The aria-current attribute.
    181183         * }
    182          * @param WP_Post $page         Page data object.
    183          * @param int     $depth        Depth of page, used for padding.
    184          * @param array   $args         An array of arguments.
    185          * @param int     $current_page ID of the current page.
     184         * @param WP_Post $page            Page data object.
     185         * @param int     $depth           Depth of page, used for padding.
     186         * @param array   $args            An array of arguments.
     187         * @param int     $current_page_id ID of the current page.
    186188         */
    187         $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
     189        $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );
    188190
    189191        $attributes = '';
  • trunk/src/wp-includes/class-wp-walker.php

    r51739 r51779  
    9191     * @param int    $depth             Depth of the item.
    9292     * @param array  $args              An array of additional arguments.
    93      * @param int    $current_object_id ID of the current item.
     93     * @param int    $current_object_id Optional. ID of the current item. Default 0.
    9494     */
    9595    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {}
Note: See TracChangeset for help on using the changeset viewer.