From 2c9189972437d105c7c8986701c4d455c482d368 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Thu, 2 Sep 2021 22:26:56 +0000 Subject: [PATCH] Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_List_Table::column_default()`. Matches the method signatures of the parent class and each 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. 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. Follow-up to [15632], [30679], [31210], [32740], [32753], [32754], [32755], [32756], [32757]. Props jrf, hellofromTonya, @sergeybiryukov, @azaozz, @desrosj, @johnbillion See #51553. Built from https://develop.svn.wordpress.org/trunk@51728 git-svn-id: http://core.svn.wordpress.org/trunk@51334 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-comments-list-table.php | 8 +++++--- wp-admin/includes/class-wp-links-list-table.php | 7 ++++--- wp-admin/includes/class-wp-media-list-table.php | 8 ++++++-- wp-admin/includes/class-wp-ms-sites-list-table.php | 7 ++++--- .../includes/class-wp-ms-themes-list-table.php | 14 +++++++++----- wp-admin/includes/class-wp-ms-users-list-table.php | 12 +++++++++--- wp-admin/includes/class-wp-posts-list-table.php | 8 ++++++-- wp-admin/includes/class-wp-terms-list-table.php | 10 ++++++---- wp-includes/version.php | 2 +- 9 files changed, 50 insertions(+), 26 deletions(-) diff --git a/wp-admin/includes/class-wp-comments-list-table.php b/wp-admin/includes/class-wp-comments-list-table.php index d62020039d..a027e800cd 100644 --- a/wp-admin/includes/class-wp-comments-list-table.php +++ b/wp-admin/includes/class-wp-comments-list-table.php @@ -1047,10 +1047,12 @@ class WP_Comments_List_Table extends WP_List_Table { } /** - * @param WP_Comment $comment The comment object. + * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named param. + * + * @param WP_Comment $item The comment object. * @param string $column_name The custom column's name. */ - public function column_default( $comment, $column_name ) { + public function column_default( $item, $column_name ) { /** * Fires when the default column output is displayed for a single row. * @@ -1059,6 +1061,6 @@ class WP_Comments_List_Table extends WP_List_Table { * @param string $column_name The custom column's name. * @param int $comment_id The custom column's unique ID number. */ - do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); + do_action( 'manage_comments_custom_column', $column_name, $item->comment_ID ); } } diff --git a/wp-admin/includes/class-wp-links-list-table.php b/wp-admin/includes/class-wp-links-list-table.php index b867a8ad19..60ba8ed778 100644 --- a/wp-admin/includes/class-wp-links-list-table.php +++ b/wp-admin/includes/class-wp-links-list-table.php @@ -279,11 +279,12 @@ class WP_Links_List_Table extends WP_List_Table { * Handles the default column output. * * @since 4.3.0 + * @since 5.9.0 Renamed `$link` to `$item` to match parent class for PHP 8 named param. * - * @param object $link Link object. + * @param object $item Link object. * @param string $column_name Current column name. */ - public function column_default( $link, $column_name ) { + public function column_default( $item, $column_name ) { /** * Fires for each registered custom link column. * @@ -292,7 +293,7 @@ class WP_Links_List_Table extends WP_List_Table { * @param string $column_name Name of the custom column. * @param int $link_id Link ID. */ - do_action( 'manage_link_custom_column', $column_name, $link->link_id ); + do_action( 'manage_link_custom_column', $column_name, $item->link_id ); } public function display_rows() { diff --git a/wp-admin/includes/class-wp-media-list-table.php b/wp-admin/includes/class-wp-media-list-table.php index 275d07caca..6c0a499001 100644 --- a/wp-admin/includes/class-wp-media-list-table.php +++ b/wp-admin/includes/class-wp-media-list-table.php @@ -594,11 +594,15 @@ class WP_Media_List_Table extends WP_List_Table { * Handles output for the default column. * * @since 4.3.0 + * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named param. * - * @param WP_Post $post The current WP_Post object. + * @param WP_Post $item The current WP_Post object. * @param string $column_name Current column name. */ - public function column_default( $post, $column_name ) { + public function column_default( $item, $column_name ) { + // Restores the more descriptive, specific name for use within this method. + $post = $item; + if ( 'categories' === $column_name ) { $taxonomy = 'category'; } elseif ( 'tags' === $column_name ) { diff --git a/wp-admin/includes/class-wp-ms-sites-list-table.php b/wp-admin/includes/class-wp-ms-sites-list-table.php index b928ee92c6..02f7938ead 100644 --- a/wp-admin/includes/class-wp-ms-sites-list-table.php +++ b/wp-admin/includes/class-wp-ms-sites-list-table.php @@ -560,11 +560,12 @@ class WP_MS_Sites_List_Table extends WP_List_Table { * Handles output for the default column. * * @since 4.3.0 + * @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named param. * - * @param array $blog Current site. + * @param array $item Current site. * @param string $column_name Current column name. */ - public function column_default( $blog, $column_name ) { + public function column_default( $item, $column_name ) { /** * Fires for each registered custom column in the Sites list table. * @@ -573,7 +574,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table { * @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, $blog['blog_id'] ); + do_action( 'manage_sites_custom_column', $column_name, $item['blog_id'] ); } /** diff --git a/wp-admin/includes/class-wp-ms-themes-list-table.php b/wp-admin/includes/class-wp-ms-themes-list-table.php index d7d20e238a..d4ad43df57 100644 --- a/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -855,13 +855,12 @@ class WP_MS_Themes_List_Table extends WP_List_Table { * Handles default column output. * * @since 4.3.0 + * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named param. * - * @param WP_Theme $theme The current WP_Theme object. + * @param WP_Theme $item The current WP_Theme object. * @param string $column_name The current column name. */ - public function column_default( $theme, $column_name ) { - $stylesheet = $theme->get_stylesheet(); - + public function column_default( $item, $column_name ) { /** * Fires inside each custom column of the Multisite themes list table. * @@ -871,7 +870,12 @@ class WP_MS_Themes_List_Table extends WP_List_Table { * @param string $stylesheet Directory name of the theme. * @param WP_Theme $theme Current WP_Theme object. */ - do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); + do_action( + 'manage_themes_custom_column', + $column_name, + $item->get_stylesheet(), // Directory name of the theme. + $item // Theme object. + ); } /** diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php index 8e1656ed6c..825f8e86ef 100644 --- a/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/wp-admin/includes/class-wp-ms-users-list-table.php @@ -442,13 +442,19 @@ class WP_MS_Users_List_Table extends WP_List_Table { * Handles the default column output. * * @since 4.3.0 + * @since 5.9.0 Renamed `$user` to `$item` to match parent class for PHP 8 named param. * - * @param WP_User $user The current WP_User object. + * @param WP_User $item The current WP_User object. * @param string $column_name The current column name. */ - public function column_default( $user, $column_name ) { + public function column_default( $item, $column_name ) { /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ - echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); + echo apply_filters( + 'manage_users_custom_column', + '', // Custom column output. Default empty. + $column_name, + $item->ID // User ID. + ); } public function display_rows() { diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index f8687efb95..9b3a03b1c0 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -1235,11 +1235,15 @@ class WP_Posts_List_Table extends WP_List_Table { * Handles the default column output. * * @since 4.3.0 + * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named param. * - * @param WP_Post $post The current WP_Post object. + * @param WP_Post $item The current WP_Post object. * @param string $column_name The current column name. */ - public function column_default( $post, $column_name ) { + public function column_default( $item, $column_name ) { + // Restores the more descriptive, specific name for use within this method. + $post = $item; + if ( 'categories' === $column_name ) { $taxonomy = 'category'; } elseif ( 'tags' === $column_name ) { diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php index f6697f13a9..ef4b37ee4d 100644 --- a/wp-admin/includes/class-wp-terms-list-table.php +++ b/wp-admin/includes/class-wp-terms-list-table.php @@ -620,11 +620,13 @@ class WP_Terms_List_Table extends WP_List_Table { } /** - * @param WP_Term $tag Term object. + * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named param. + * + * @param WP_Term $item Term object. * @param string $column_name Name of the column. * @return string */ - public function column_default( $tag, $column_name ) { + public function column_default( $item, $column_name ) { /** * Filters the displayed columns in the terms list table. * @@ -638,11 +640,11 @@ class WP_Terms_List_Table extends WP_List_Table { * * @since 2.8.0 * - * @param string $string Blank string. + * @param string $string Custom column output. Default empty. * @param string $column_name Name of the column. * @param int $term_id Term ID. */ - return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); + return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $item->term_id ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 0d3c5f83ed..7e5ac18a90 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51727'; +$wp_version = '5.9-alpha-51728'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.