mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 07:36:58 +00:00
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in Walker::start_el().
In the parent class, renames the parameter `$object` to `$data_object`. Why? `object` is a PHP reserved keyword. In each child class: renames the corresponding parameter to match the parent's method signature. 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, 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]. Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion. See #51553. git-svn-id: https://develop.svn.wordpress.org/trunk@51739 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -44,18 +44,21 @@ 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.
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @param string $output Used to append additional content (passed by reference).
|
||||
* @param WP_Term $category 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 $id Optional. ID of the current category. Default 0 (unused).
|
||||
*/
|
||||
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$category = $data_object;
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
||||
|
||||
@@ -86,16 +86,21 @@ 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.
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @param string $output Used to append additional content (passed by reference).
|
||||
* @param WP_Term $category 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 $id Optional. ID of the current category. Default 0.
|
||||
*/
|
||||
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$category = $data_object;
|
||||
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$cat_name = apply_filters( 'list_cats', esc_attr( $category->name ), $category );
|
||||
|
||||
|
||||
@@ -157,19 +157,23 @@ 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.
|
||||
*
|
||||
* @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 $comment 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 $id Optional. ID of the current comment. Default 0 (unused).
|
||||
*/
|
||||
public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$comment = $data_object;
|
||||
|
||||
$depth++;
|
||||
$GLOBALS['comment_depth'] = $depth;
|
||||
$GLOBALS['comment'] = $comment;
|
||||
|
||||
@@ -106,16 +106,20 @@ 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.
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @param string $output Used to append additional content (passed by reference).
|
||||
* @param WP_Post $item 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 $id Current item ID.
|
||||
*/
|
||||
public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$menu_item = $data_object;
|
||||
|
||||
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
|
||||
$t = '';
|
||||
$n = '';
|
||||
@@ -125,19 +129,19 @@ class Walker_Nav_Menu extends Walker {
|
||||
}
|
||||
$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
|
||||
|
||||
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
|
||||
$classes[] = 'menu-item-' . $item->ID;
|
||||
$classes = empty( $menu_item->classes ) ? array() : (array) $menu_item->classes;
|
||||
$classes[] = 'menu-item-' . $menu_item->ID;
|
||||
|
||||
/**
|
||||
* Filters the arguments for a single nav menu item.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param WP_Post $item 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 WP_Post $menu_item Menu item data object.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
|
||||
$args = apply_filters( 'nav_menu_item_args', $args, $menu_item, $depth );
|
||||
|
||||
/**
|
||||
* Filters the CSS classes applied to a menu item's list item element.
|
||||
@@ -145,12 +149,12 @@ class Walker_Nav_Menu extends Walker {
|
||||
* @since 3.0.0
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element.
|
||||
* @param WP_Post $item The current menu item.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element.
|
||||
* @param WP_Post $menu_item The current menu item object.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
|
||||
$class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $menu_item, $args, $depth ) );
|
||||
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
|
||||
|
||||
/**
|
||||
@@ -159,26 +163,26 @@ class Walker_Nav_Menu extends Walker {
|
||||
* @since 3.0.1
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param string $menu_id The ID that is applied to the menu item's `<li>` element.
|
||||
* @param WP_Post $item The current menu item.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param string $menu_id The ID that is applied to the menu item's `<li>` element.
|
||||
* @param WP_Post $menu_item The current menu item.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
|
||||
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $menu_item->ID, $menu_item, $args, $depth );
|
||||
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
|
||||
|
||||
$output .= $indent . '<li' . $id . $class_names . '>';
|
||||
|
||||
$atts = array();
|
||||
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
|
||||
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
|
||||
if ( '_blank' === $item->target && empty( $item->xfn ) ) {
|
||||
$atts['title'] = ! empty( $menu_item->attr_title ) ? $menu_item->attr_title : '';
|
||||
$atts['target'] = ! empty( $menu_item->target ) ? $menu_item->target : '';
|
||||
if ( '_blank' === $menu_item->target && empty( $menu_item->xfn ) ) {
|
||||
$atts['rel'] = 'noopener';
|
||||
} else {
|
||||
$atts['rel'] = $item->xfn;
|
||||
$atts['rel'] = $menu_item->xfn;
|
||||
}
|
||||
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
|
||||
$atts['aria-current'] = $item->current ? 'page' : '';
|
||||
$atts['href'] = ! empty( $menu_item->url ) ? $menu_item->url : '';
|
||||
$atts['aria-current'] = $menu_item->current ? 'page' : '';
|
||||
|
||||
/**
|
||||
* Filters the HTML attributes applied to a menu item's anchor element.
|
||||
@@ -195,11 +199,11 @@ class Walker_Nav_Menu extends Walker {
|
||||
* @type string $href The href attribute.
|
||||
* @type string $aria-current The aria-current attribute.
|
||||
* }
|
||||
* @param WP_Post $item The current menu item.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param WP_Post $menu_item The current menu item object.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
|
||||
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth );
|
||||
|
||||
$attributes = '';
|
||||
foreach ( $atts as $attr => $value ) {
|
||||
@@ -210,19 +214,19 @@ class Walker_Nav_Menu extends Walker {
|
||||
}
|
||||
|
||||
/** This filter is documented in wp-includes/post-template.php */
|
||||
$title = apply_filters( 'the_title', $item->title, $item->ID );
|
||||
$title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID );
|
||||
|
||||
/**
|
||||
* Filters a menu item's title.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $title The menu item's title.
|
||||
* @param WP_Post $item The current menu item.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param string $title The menu item's title.
|
||||
* @param WP_Post $menu_item The current menu item object.
|
||||
* @param stdClass $args An object of wp_nav_menu() arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
|
||||
$title = apply_filters( 'nav_menu_item_title', $title, $menu_item, $args, $depth );
|
||||
|
||||
$item_output = $args->before;
|
||||
$item_output .= '<a' . $attributes . '>';
|
||||
@@ -240,11 +244,11 @@ class Walker_Nav_Menu extends Walker {
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $item_output The menu item's starting HTML output.
|
||||
* @param WP_Post $item Menu item data object.
|
||||
* @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 wp_nav_menu() arguments.
|
||||
*/
|
||||
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
||||
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $menu_item, $depth, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,20 +44,23 @@ 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.
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @param string $output Used to append additional content. Passed by reference.
|
||||
* @param WP_Post $page 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 $id Optional. ID of the current page. Default 0 (unused).
|
||||
*/
|
||||
public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$page = $data_object;
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
|
||||
if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
|
||||
$args['value_field'] = 'ID';
|
||||
|
||||
@@ -93,14 +93,18 @@ 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.
|
||||
*
|
||||
* @param string $output Used to append additional content. Passed by reference.
|
||||
* @param WP_Post $page Page data object.
|
||||
* @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.
|
||||
*/
|
||||
public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_page = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$page = $data_object;
|
||||
|
||||
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
|
||||
$t = "\t";
|
||||
$n = "\n";
|
||||
|
||||
@@ -83,15 +83,16 @@ class Walker {
|
||||
* class methods. Includes the element output also.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 5.9.0 Renamed `$object` (a PHP reserved keyword) to `$data_object` for PHP 8 named parameter support.
|
||||
* @abstract
|
||||
*
|
||||
* @param string $output Used to append additional content (passed by reference).
|
||||
* @param object $object The data object.
|
||||
* @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.
|
||||
*/
|
||||
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {}
|
||||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {}
|
||||
|
||||
/**
|
||||
* Ends the element output, if needed.
|
||||
|
||||
Reference in New Issue
Block a user