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
This commit is contained in:
Sergey Biryukov
2023-09-14 12:44:23 +00:00
parent 4ba29eb1cb
commit e005108fe1
30 changed files with 95 additions and 58 deletions

View File

@@ -61,7 +61,8 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
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();

View File

@@ -685,7 +685,8 @@ class WP_Comments_List_Table extends WP_List_Table {
}
// 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 @@ class WP_Comments_List_Table extends WP_List_Table {
* @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 @@ class WP_Comments_List_Table extends WP_List_Table {
* @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 );
}
}

View File

@@ -290,6 +290,9 @@ class WP_Links_List_Table extends WP_List_Table {
* @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 @@ 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, $item->link_id );
do_action( 'manage_link_custom_column', $column_name, $link->link_id );
}
public function display_rows() {
@@ -332,7 +335,8 @@ class WP_Links_List_Table extends WP_List_Table {
}
// Restores the more descriptive, specific name for use within this method.
$link = $item;
$link = $item;
$edit_link = get_edit_bookmark_link( $link );
$actions = array();

View File

@@ -880,11 +880,11 @@ class WP_Media_List_Table extends WP_List_Table {
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 );
}

View File

@@ -597,6 +597,9 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
* @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 @@ 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, $item['blog_id'] );
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
}
/**
@@ -714,7 +717,8 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
}
// Restores the more descriptive, specific name for use within this method.
$blog = $item;
$blog = $item;
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
// Preordered.

View File

@@ -509,7 +509,8 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*/
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' ) );
?>
<label class="label-covers-full-cell" for="<?php echo $checkbox_id; ?>" >
@@ -878,6 +879,11 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
* @param string $column_name The current column name.
*/
public function column_default( $item, $column_name ) {
// Restores the more descriptive, specific name for use within this method.
$theme = $item;
$stylesheet = $theme->get_stylesheet();
/**
* Fires inside each custom column of the Multisite themes list table.
*
@@ -887,12 +893,7 @@ 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,
$item->get_stylesheet(), // Directory name of the theme.
$item // Theme object.
);
do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
}
/**

View File

@@ -458,13 +458,11 @@ class WP_MS_Users_List_Table extends WP_List_Table {
* @param string $column_name The current column name.
*/
public function column_default( $item, $column_name ) {
// Restores the more descriptive, specific name for use within this method.
$user = $item;
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
echo apply_filters(
'manage_users_custom_column',
'', // Custom column output. Default empty.
$column_name,
$item->ID // User ID.
);
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
}
public function display_rows() {
@@ -519,10 +517,10 @@ class WP_MS_Users_List_Table extends WP_List_Table {
}
// Restores the more descriptive, specific name for use within this method.
$user = $item;
$super_admins = get_super_admins();
$user = $item;
$actions = array();
$super_admins = get_super_admins();
$actions = array();
if ( current_user_can( 'edit_user', $user->ID ) ) {
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

View File

@@ -1019,6 +1019,7 @@ class WP_Posts_List_Table extends WP_List_Table {
public function column_cb( $item ) {
// Restores the more descriptive, specific name for use within this method.
$post = $item;
$show = current_user_can( 'edit_post', $post->ID );
/**
@@ -1458,7 +1459,8 @@ class WP_Posts_List_Table extends WP_List_Table {
}
// Restores the more descriptive, specific name for use within this method.
$post = $item;
$post = $item;
$post_type_object = get_post_type_object( $post->post_type );
$can_edit_post = current_user_can( 'edit_post', $post->ID );
$actions = array();

View File

@@ -464,7 +464,8 @@ class WP_Terms_List_Table extends WP_List_Table {
}
// Restores the more descriptive, specific name for use within this method.
$tag = $item;
$tag = $item;
$taxonomy = $this->screen->taxonomy;
$uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
@@ -626,6 +627,9 @@ class WP_Terms_List_Table extends WP_List_Table {
* @return string
*/
public function column_default( $item, $column_name ) {
// Restores the more descriptive, specific name for use within this method.
$tag = $item;
/**
* Filters the displayed columns in the terms list table.
*
@@ -643,7 +647,7 @@ class WP_Terms_List_Table extends WP_List_Table {
* @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, $item->term_id );
return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
}
/**