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.
Built from https://develop.svn.wordpress.org/trunk@51779


git-svn-id: http://core.svn.wordpress.org/trunk@51386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-09-09 12:39:59 +00:00
parent 0fcde6de17
commit 7abc752329
12 changed files with 124 additions and 111 deletions

View File

@ -61,15 +61,16 @@ class Walker_Category_Checklist extends Walker {
* @see Walker::start_el()
*
* @since 2.5.1
* @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Term $data_object The current term object.
* @param int $depth Depth of the term in reference to parents. Default 0.
* @param array $args An array of arguments. @see wp_terms_checklist()
* @param int $id ID of the current term.
* @param string $output Used to append additional content (passed by reference).
* @param WP_Term $data_object The current term object.
* @param int $depth Depth of the term in reference to parents. Default 0.
* @param array $args An array of arguments. @see wp_terms_checklist()
* @param int $current_object_id Optional. ID of the current term. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$category = $data_object;

View File

@ -61,18 +61,19 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
* @see Walker_Nav_Menu::start_el()
*
* @since 3.0.0
* @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @global int $_nav_menu_placeholder
* @global int|string $nav_menu_selected_id
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
* @param int $id Not used.
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
* @param int $current_object_id Optional. ID of the current menu item. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
global $_nav_menu_placeholder, $nav_menu_selected_id;
// Restores the more descriptive, specific name for use within this method.

View File

@ -46,17 +46,18 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
*
* @see Walker_Nav_Menu::start_el()
* @since 3.0.0
* @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @global int $_wp_nav_menu_max_depth
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
* @param int $id Not used.
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args Not used.
* @param int $current_object_id Optional. ID of the current menu item. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
global $_wp_nav_menu_max_depth;
// Restores the more descriptive, specific name for use within this method.
@ -241,13 +242,13 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
*
* @since 5.4.0
*
* @param int $item_id Menu item ID.
* @param WP_Post $menu_item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of menu item arguments.
* @param int $id Nav menu ID.
* @param int $item_id Menu item ID.
* @param WP_Post $menu_item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of menu item arguments.
* @param int $current_object_id Nav menu ID.
*/
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $id );
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
?>
<fieldset class="field-move hide-if-no-js description description-wide">

View File

@ -20,19 +20,21 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Page' ) ) {
* Outputs the beginning of the current element in the tree.
*
* @since Twenty Twenty 1.0
* @since Twenty Twenty 1.9 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since Twenty Twenty 1.9 Renamed `$page` to `$data_object` and `$current_page` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @see Walker::start_el()
*
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Post $data_object Page data object.
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
* @param array $args Optional. Array of arguments. Default empty array.
* @param int $current_page Optional. Page ID. Default 0.
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Post $data_object Page data object.
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
* @param array $args Optional. Array of arguments. Default empty array.
* @param int $current_object_id Optional. ID of the current page. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_page = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$page = $data_object;
$page = $data_object;
$current_page_id = $current_object_id;
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
$t = "\t";
@ -53,12 +55,12 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Page' ) ) {
$css_class[] = 'page_item_has_children';
}
if ( ! empty( $current_page ) ) {
$_current_page = get_post( $current_page );
if ( ! empty( $current_page_id ) ) {
$_current_page = get_post( $current_page_id );
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
$css_class[] = 'current_page_ancestor';
}
if ( $page->ID === $current_page ) {
if ( $page->ID === $current_page_id ) {
$css_class[] = 'current_page_item';
} elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
$css_class[] = 'current_page_parent';
@ -68,7 +70,7 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Page' ) ) {
}
/** This filter is documented in wp-includes/class-walker-page.php */
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) );
$css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
if ( '' === $page->post_title ) {
@ -81,10 +83,10 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Page' ) ) {
$atts = array();
$atts['href'] = get_permalink( $page->ID );
$atts['aria-current'] = ( $page->ID === $current_page ) ? 'page' : '';
$atts['aria-current'] = ( $page->ID === $current_page_id ) ? 'page' : '';
/** This filter is documented in wp-includes/class-walker-page.php */
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );
$attributes = '';
foreach ( $atts as $attr => $value ) {

View File

@ -44,18 +44,19 @@ class Walker_CategoryDropdown extends Walker {
* Starts the element output.
*
* @since 2.1.0
* @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @see Walker::start_el()
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Term $data_object Category data object.
* @param int $depth Depth of category. Used for padding.
* @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
* See wp_dropdown_categories().
* @param int $id Optional. ID of the current category. Default 0 (unused).
* @param string $output Used to append additional content (passed by reference).
* @param WP_Term $data_object Category data object.
* @param int $depth Depth of category. Used for padding.
* @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
* See wp_dropdown_categories().
* @param int $current_object_id Optional. ID of the current category. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$category = $data_object;
$pad = str_repeat( '&nbsp;', $depth * 3 );

View File

@ -86,18 +86,19 @@ class Walker_Category extends Walker {
* Starts the element output.
*
* @since 2.1.0
* @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @see Walker::start_el()
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Term $data_object Category data object.
* @param int $depth Optional. Depth of category in reference to parents. Default 0.
* @param array $args Optional. An array of arguments. See wp_list_categories().
* Default empty array.
* @param int $id Optional. ID of the current category. Default 0.
* @param string $output Used to append additional content (passed by reference).
* @param WP_Term $data_object Category data object.
* @param int $depth Optional. Depth of category in reference to parents. Default 0.
* @param array $args Optional. An array of arguments. See wp_list_categories().
* Default empty array.
* @param int $current_object_id Optional. ID of the current category. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$category = $data_object;
@ -135,12 +136,12 @@ class Walker_Category extends Walker {
* @type string $href The href attribute.
* @type string $title The title attribute.
* }
* @param WP_Term $category Term data object.
* @param int $depth Depth of category, used for padding.
* @param array $args An array of arguments.
* @param int $id ID of the current category.
* @param WP_Term $category Term data object.
* @param int $depth Depth of category, used for padding.
* @param array $args An array of arguments.
* @param int $current_object_id ID of the current category.
*/
$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id );
$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $current_object_id );
$attributes = '';
foreach ( $atts as $attr => $value ) {

View File

@ -157,20 +157,21 @@ class Walker_Comment extends Walker {
* Starts the element output.
*
* @since 2.7.0
* @since 5.9.0 Renamed `$comment` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$comment` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @see Walker::start_el()
* @see wp_list_comments()
* @global int $comment_depth
* @global WP_Comment $comment Global comment object.
*
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Comment $data_object Comment data object.
* @param int $depth Optional. Depth of the current comment in reference to parents. Default 0.
* @param array $args Optional. An array of arguments. Default empty array.
* @param int $id Optional. ID of the current comment. Default 0 (unused).
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Comment $data_object Comment data object.
* @param int $depth Optional. Depth of the current comment in reference to parents. Default 0.
* @param array $args Optional. An array of arguments. Default empty array.
* @param int $current_object_id Optional. ID of the current comment. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$comment = $data_object;

View File

@ -106,17 +106,18 @@ class Walker_Nav_Menu extends Walker {
*
* @since 3.0.0
* @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added.
* @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @see Walker::start_el()
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $id Current item ID.
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $data_object Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $current_object_id Optional. ID of the current menu item. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$menu_item = $data_object;

View File

@ -44,20 +44,22 @@ class Walker_PageDropdown extends Walker {
* Starts the element output.
*
* @since 2.1.0
* @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$page` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @see Walker::start_el()
*
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Post $data_object Page data object.
* @param int $depth Optional. Depth of page in reference to parent pages. Used for padding.
* Default 0.
* @param array $args Optional. Uses 'selected' argument for selected page to set selected HTML
* attribute for option element. Uses 'value_field' argument to fill "value"
* attribute. See wp_dropdown_pages(). Default empty array.
* @param int $id Optional. ID of the current page. Default 0 (unused).
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Post $data_object Page data object.
* @param int $depth Optional. Depth of page in reference to parent pages.
* Used for padding. Default 0.
* @param array $args Optional. Uses 'selected' argument for selected page to
* set selected HTML attribute for option element. Uses
* 'value_field' argument to fill "value" attribute.
* See wp_dropdown_pages(). Default empty array.
* @param int $current_object_id Optional. ID of the current page. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$page = $data_object;
$pad = str_repeat( '&nbsp;', $depth * 3 );

View File

@ -93,17 +93,19 @@ class Walker_Page extends Walker {
*
* @see Walker::start_el()
* @since 2.1.0
* @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
* @since 5.9.0 Renamed `$page` to `$data_object` and `$current_page` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
*
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Post $data_object Page data object.
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
* @param array $args Optional. Array of arguments. Default empty array.
* @param int $current_page Optional. Page ID. Default 0.
* @param string $output Used to append additional content. Passed by reference.
* @param WP_Post $data_object Page data object.
* @param int $depth Optional. Depth of page. Used for padding. Default 0.
* @param array $args Optional. Array of arguments. Default empty array.
* @param int $current_object_id Optional. ID of the current page. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_page = 0 ) {
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$page = $data_object;
$page = $data_object;
$current_page_id = $current_object_id;
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
$t = "\t";
@ -124,14 +126,14 @@ class Walker_Page extends Walker {
$css_class[] = 'page_item_has_children';
}
if ( ! empty( $current_page ) ) {
$_current_page = get_post( $current_page );
if ( ! empty( $current_page_id ) ) {
$_current_page = get_post( $current_page_id );
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
$css_class[] = 'current_page_ancestor';
}
if ( $page->ID == $current_page ) {
if ( $page->ID == $current_page_id ) {
$css_class[] = 'current_page_item';
} elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
$css_class[] = 'current_page_parent';
@ -147,13 +149,13 @@ class Walker_Page extends Walker {
*
* @see wp_list_pages()
*
* @param string[] $css_class An array of CSS classes to be applied to each list item.
* @param WP_Post $page Page data object.
* @param int $depth Depth of page, used for padding.
* @param array $args An array of arguments.
* @param int $current_page ID of the current page.
* @param string[] $css_class An array of CSS classes to be applied to each list item.
* @param WP_Post $page Page data object.
* @param int $depth Depth of page, used for padding.
* @param array $args An array of arguments.
* @param int $current_page_id ID of the current page.
*/
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) );
$css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
if ( '' === $page->post_title ) {
@ -166,7 +168,7 @@ class Walker_Page extends Walker {
$atts = array();
$atts['href'] = get_permalink( $page->ID );
$atts['aria-current'] = ( $page->ID == $current_page ) ? 'page' : '';
$atts['aria-current'] = ( $page->ID == $current_page_id ) ? 'page' : '';
/**
* Filters the HTML attributes applied to a page menu item's anchor element.
@ -179,12 +181,12 @@ class Walker_Page extends Walker {
* @type string $href The href attribute.
* @type string $aria-current The aria-current attribute.
* }
* @param WP_Post $page Page data object.
* @param int $depth Depth of page, used for padding.
* @param array $args An array of arguments.
* @param int $current_page ID of the current page.
* @param WP_Post $page Page data object.
* @param int $depth Depth of page, used for padding.
* @param array $args An array of arguments.
* @param int $current_page_id ID of the current page.
*/
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );
$attributes = '';
foreach ( $atts as $attr => $value ) {

View File

@ -90,7 +90,7 @@ class Walker {
* @param object $data_object The data object.
* @param int $depth Depth of the item.
* @param array $args An array of additional arguments.
* @param int $current_object_id ID of the current item.
* @param int $current_object_id Optional. ID of the current item. Default 0.
*/
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-51768';
$wp_version = '5.9-alpha-51779';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.