From e005108fe18e6278f4e6dd0fec030e503fe0ff46 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 14 Sep 2023 12:44:23 +0000 Subject: [PATCH] Coding Standards: Restore more descriptive variable names in a few class methods. When various methods parameters in child classes were renamed to `$item` to match the parent class for PHP 8 named parameter support, most of the methods restored the more descriptive, specific name at the beginning for better readability, with several exceptions for methods consisting only of a few lines. To avoid confusion about why some methods do that and some don't, this commit aims to bring more consistency to the code, specifically in list tables' `::column_default()` methods. Follow-up to [51728], [51737], [51786]. See #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56586 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-walker-nav-menu-edit.php | 3 ++- .../includes/class-wp-comments-list-table.php | 8 ++++++-- .../includes/class-wp-links-list-table.php | 8 ++++++-- .../includes/class-wp-media-list-table.php | 8 ++++---- .../includes/class-wp-ms-sites-list-table.php | 8 ++++++-- .../includes/class-wp-ms-themes-list-table.php | 15 ++++++++------- .../includes/class-wp-ms-users-list-table.php | 16 +++++++--------- .../includes/class-wp-posts-list-table.php | 4 +++- .../includes/class-wp-terms-list-table.php | 8 ++++++-- .../class-walker-category-dropdown.php | 3 ++- src/wp-includes/class-walker-page-dropdown.php | 3 ++- src/wp-includes/class-walker-page.php | 3 ++- .../class-wp-rest-attachments-controller.php | 3 ++- .../class-wp-rest-autosaves-controller.php | 6 +++--- .../class-wp-rest-block-types-controller.php | 5 +++-- .../class-wp-rest-comments-controller.php | 5 +++-- .../class-wp-rest-global-styles-controller.php | 4 ++-- .../class-wp-rest-menu-locations-controller.php | 3 ++- ...lass-wp-rest-pattern-directory-controller.php | 3 ++- .../class-wp-rest-post-statuses-controller.php | 1 + .../class-wp-rest-post-types-controller.php | 3 ++- .../endpoints/class-wp-rest-posts-controller.php | 3 ++- .../class-wp-rest-revisions-controller.php | 3 ++- .../class-wp-rest-search-controller.php | 1 + .../class-wp-rest-sidebars-controller.php | 5 +++-- .../class-wp-rest-taxonomies-controller.php | 3 ++- .../class-wp-rest-themes-controller.php | 5 +++-- .../endpoints/class-wp-rest-users-controller.php | 5 +++-- .../class-wp-rest-widget-types-controller.php | 5 +++-- .../providers/class-wp-sitemaps-taxonomies.php | 3 ++- 30 files changed, 95 insertions(+), 58 deletions(-) diff --git a/src/wp-admin/includes/class-walker-nav-menu-edit.php b/src/wp-admin/includes/class-walker-nav-menu-edit.php index 5869247d6491d..7cc7052cdba16 100644 --- a/src/wp-admin/includes/class-walker-nav-menu-edit.php +++ b/src/wp-admin/includes/class-walker-nav-menu-edit.php @@ -61,7 +61,8 @@ public function start_el( &$output, $data_object, $depth = 0, $args = null, $cur global $_wp_nav_menu_max_depth; // Restores the more descriptive, specific name for use within this method. - $menu_item = $data_object; + $menu_item = $data_object; + $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; ob_start(); diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php index 7d87ae9aabdc4..401dde0d97275 100644 --- a/src/wp-admin/includes/class-wp-comments-list-table.php +++ b/src/wp-admin/includes/class-wp-comments-list-table.php @@ -685,7 +685,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) { } // Restores the more descriptive, specific name for use within this method. - $comment = $item; + $comment = $item; + $the_comment_status = wp_get_comment_status( $comment ); $output = ''; @@ -1087,6 +1088,9 @@ public function column_response( $comment ) { * @param string $column_name The custom column's name. */ public function column_default( $item, $column_name ) { + // Restores the more descriptive, specific name for use within this method. + $comment = $item; + /** * Fires when the default column output is displayed for a single row. * @@ -1095,6 +1099,6 @@ public function column_default( $item, $column_name ) { * @param string $column_name The custom column's name. * @param string $comment_id The comment ID as a numeric string. */ - do_action( 'manage_comments_custom_column', $column_name, $item->comment_ID ); + do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); } } diff --git a/src/wp-admin/includes/class-wp-links-list-table.php b/src/wp-admin/includes/class-wp-links-list-table.php index f29cf7b3e237e..f8886df5fbb8e 100644 --- a/src/wp-admin/includes/class-wp-links-list-table.php +++ b/src/wp-admin/includes/class-wp-links-list-table.php @@ -290,6 +290,9 @@ public function column_rating( $link ) { * @param string $column_name Current column name. */ public function column_default( $item, $column_name ) { + // Restores the more descriptive, specific name for use within this method. + $link = $item; + /** * Fires for each registered custom link column. * @@ -298,7 +301,7 @@ public function column_default( $item, $column_name ) { * @param string $column_name Name of the custom column. * @param int $link_id Link ID. */ - do_action( 'manage_link_custom_column', $column_name, $item->link_id ); + do_action( 'manage_link_custom_column', $column_name, $link->link_id ); } public function display_rows() { @@ -332,7 +335,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) { } // Restores the more descriptive, specific name for use within this method. - $link = $item; + $link = $item; + $edit_link = get_edit_bookmark_link( $link ); $actions = array(); diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 9eae94ef92ed7..712f6ae190118 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -880,11 +880,11 @@ protected function handle_row_actions( $item, $column_name, $primary ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $post = $item; + $att_title = _draft_or_post_title(); - $actions = $this->_get_row_actions( - $item, // WP_Post object for an attachment. - $att_title - ); + $actions = $this->_get_row_actions( $post, $att_title ); return $this->row_actions( $actions ); } diff --git a/src/wp-admin/includes/class-wp-ms-sites-list-table.php b/src/wp-admin/includes/class-wp-ms-sites-list-table.php index ec48bf37c7b26..7f8ca76d82df3 100644 --- a/src/wp-admin/includes/class-wp-ms-sites-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-sites-list-table.php @@ -597,6 +597,9 @@ public function column_plugins( $blog ) { * @param string $column_name Current column name. */ public function column_default( $item, $column_name ) { + // Restores the more descriptive, specific name for use within this method. + $blog = $item; + /** * Fires for each registered custom column in the Sites list table. * @@ -605,7 +608,7 @@ public function column_default( $item, $column_name ) { * @param string $column_name The name of the column to display. * @param int $blog_id The site ID. */ - do_action( 'manage_sites_custom_column', $column_name, $item['blog_id'] ); + do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); } /** @@ -714,7 +717,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) { } // Restores the more descriptive, specific name for use within this method. - $blog = $item; + $blog = $item; + $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); // Preordered. diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php index 4b94e539213ea..ca8010940020e 100644 --- a/src/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -509,7 +509,8 @@ public function display_rows() { */ public function column_cb( $item ) { // Restores the more descriptive, specific name for use within this method. - $theme = $item; + $theme = $item; + $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) ); ?>