From 16b04903feec8216bdd2e6230f4ad511a9238db1 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Tue, 7 Sep 2021 19:23:00 +0000 Subject: [PATCH] Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_List_Table::handle_row_actions()`. 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 [32644], [32664], [32798], [38489], [49183], [49197]. Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion. See #51553. git-svn-id: https://develop.svn.wordpress.org/trunk@51737 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-comments-list-table.php | 7 +++++-- src/wp-admin/includes/class-wp-links-list-table.php | 7 +++++-- src/wp-admin/includes/class-wp-media-list-table.php | 11 ++++++++--- .../includes/class-wp-ms-sites-list-table.php | 7 +++++-- .../includes/class-wp-ms-users-list-table.php | 7 +++++-- src/wp-admin/includes/class-wp-posts-list-table.php | 7 +++++-- src/wp-admin/includes/class-wp-terms-list-table.php | 7 +++++-- 7 files changed, 38 insertions(+), 15 deletions(-) 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 4efe76dd41..2fbbbc3328 100644 --- a/src/wp-admin/includes/class-wp-comments-list-table.php +++ b/src/wp-admin/includes/class-wp-comments-list-table.php @@ -651,17 +651,18 @@ class WP_Comments_List_Table extends WP_List_Table { * Generate and display row actions links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. * * @global string $comment_status Status for the current listed comments. * - * @param WP_Comment $comment The comment object. + * @param WP_Comment $item The comment object. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for comments. An empty string * if the current column is not the primary column, * or if the current user cannot edit the comment. */ - protected function handle_row_actions( $comment, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { global $comment_status; if ( $primary !== $column_name ) { @@ -672,6 +673,8 @@ class WP_Comments_List_Table extends WP_List_Table { return ''; } + // Restores the more descriptive, specific name for use within this method. + $comment = $item; $the_comment_status = wp_get_comment_status( $comment ); $out = ''; 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 8c2d06bb2c..58ee4d6fff 100644 --- a/src/wp-admin/includes/class-wp-links-list-table.php +++ b/src/wp-admin/includes/class-wp-links-list-table.php @@ -317,18 +317,21 @@ class WP_Links_List_Table extends WP_List_Table { * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. * - * @param object $link Link being acted upon. + * @param object $item Link being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for links, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $link, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $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 a95b2a332e..cc27e80324 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -827,20 +827,25 @@ class WP_Media_List_Table extends WP_List_Table { * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. * - * @param WP_Post $post Attachment being acted upon. + * @param WP_Post $item Attachment being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for media attachments, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $post, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } $att_title = _draft_or_post_title(); + $actions = $this->_get_row_actions( + $item, // WP_Post object for an attachment. + $att_title + ); - return $this->row_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 3b41e21e5f..64cab8cecb 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 @@ -668,18 +668,21 @@ class WP_MS_Sites_List_Table extends WP_List_Table { * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support. * - * @param array $blog Site being acted upon. + * @param array $item Site being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for sites in Multisite, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $blog, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $blog = $item; $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); // Preordered. diff --git a/src/wp-admin/includes/class-wp-ms-users-list-table.php b/src/wp-admin/includes/class-wp-ms-users-list-table.php index 726d83092f..3494f8c871 100644 --- a/src/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-users-list-table.php @@ -499,18 +499,21 @@ class WP_MS_Users_List_Table extends WP_List_Table { * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$user` to `$item` to match parent class for PHP 8 named parameter support. * - * @param WP_User $user User being acted upon. + * @param WP_User $item User being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for users in Multisite, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $user, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $user = $item; $super_admins = get_super_admins(); $actions = array(); diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index a4e0899481..19686959e2 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -1402,18 +1402,21 @@ class WP_Posts_List_Table extends WP_List_Table { * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. * - * @param WP_Post $post Post being acted upon. + * @param WP_Post $item Post being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for posts, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $post, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $post = $item; $post_type_object = get_post_type_object( $post->post_type ); $can_edit_post = current_user_can( 'edit_post', $post->ID ); $actions = array(); diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index 0b931c4228..e905749088 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -461,18 +461,21 @@ class WP_Terms_List_Table extends WP_List_Table { * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. * - * @param WP_Term $tag Tag being acted upon. + * @param WP_Term $item Tag being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for terms, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $tag, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $tag = $item; $taxonomy = $this->screen->taxonomy; $tax = get_taxonomy( $taxonomy ); $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];