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. Built from https://develop.svn.wordpress.org/trunk@56586 git-svn-id: http://core.svn.wordpress.org/trunk@56098 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6388ac820b
commit
1aca5e48e5
|
@ -62,6 +62,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
|
|||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$menu_item = $data_object;
|
||||
|
||||
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
||||
|
||||
ob_start();
|
||||
|
|
|
@ -686,6 +686,7 @@ class WP_Comments_List_Table extends WP_List_Table {
|
|||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
@ -333,6 +336,7 @@ class WP_Links_List_Table extends WP_List_Table {
|
|||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$link = $item;
|
||||
|
||||
$edit_link = get_edit_bookmark_link( $link );
|
||||
|
||||
$actions = array();
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -715,6 +718,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
|
|||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$blog = $item;
|
||||
|
||||
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
|
||||
|
||||
// Preordered.
|
||||
|
|
|
@ -510,6 +510,7 @@ 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;
|
||||
|
||||
$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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() {
|
||||
|
@ -520,8 +518,8 @@ 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();
|
||||
|
||||
$super_admins = get_super_admins();
|
||||
$actions = array();
|
||||
|
||||
if ( current_user_can( 'edit_user', $user->ID ) ) {
|
||||
|
|
|
@ -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 );
|
||||
|
||||
/**
|
||||
|
@ -1459,6 +1460,7 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||
|
||||
// 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();
|
||||
|
|
|
@ -465,6 +465,7 @@ class WP_Terms_List_Table extends WP_List_Table {
|
|||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,6 +59,7 @@ class Walker_CategoryDropdown extends Walker {
|
|||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_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 */
|
||||
|
|
|
@ -62,6 +62,7 @@ class Walker_PageDropdown extends Walker {
|
|||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_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']} ) ) {
|
||||
|
|
|
@ -105,6 +105,7 @@ class Walker_Page extends Walker {
|
|||
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$page = $data_object;
|
||||
|
||||
$current_page_id = $current_object_id;
|
||||
|
||||
if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
|
||||
|
|
|
@ -732,6 +732,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
|
||||
$response = parent::prepare_item_for_response( $post, $request );
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = $response->get_data();
|
||||
|
|
|
@ -410,8 +410,8 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
$response = $this->revisions_controller->prepare_item_for_response( $post, $request );
|
||||
|
||||
$response = $this->revisions_controller->prepare_item_for_response( $post, $request );
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
|
||||
if ( in_array( 'preview_link', $fields, true ) ) {
|
||||
|
|
|
@ -246,6 +246,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$block_type = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
|
|
|
@ -1039,6 +1039,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$comment = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
|
|
|
@ -367,8 +367,8 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
// Base fields for every post.
|
||||
$data = array();
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'id', $fields ) ) {
|
||||
$data['id'] = $post->ID;
|
||||
|
@ -603,8 +603,8 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$theme = WP_Theme_JSON_Resolver::get_merged_data( 'theme' );
|
||||
$data = array();
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'settings', $fields ) ) {
|
||||
$data['settings'] = $theme->get_settings();
|
||||
|
|
|
@ -169,6 +169,7 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$location = $item;
|
||||
|
||||
$locations = get_nav_menu_locations();
|
||||
$menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
|
||||
|
||||
|
|
|
@ -194,6 +194,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$raw_pattern = $item;
|
||||
|
||||
$prepared_pattern = array(
|
||||
'id' => absint( $raw_pattern->id ),
|
||||
'title' => sanitize_text_field( $raw_pattern->title->rendered ),
|
||||
|
|
|
@ -222,6 +222,7 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$status = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
|
|
|
@ -177,6 +177,7 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post_type = $item;
|
||||
|
||||
$taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
|
||||
$taxonomies = wp_list_pluck( $taxonomies, 'name' );
|
||||
$base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
|
||||
|
|
|
@ -1749,6 +1749,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
|
||||
$GLOBALS['post'] = $post;
|
||||
|
||||
setup_postdata( $post );
|
||||
|
|
|
@ -548,6 +548,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$post = $item;
|
||||
|
||||
$GLOBALS['post'] = $post;
|
||||
|
||||
setup_postdata( $post );
|
||||
|
|
|
@ -195,6 +195,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$item_id = $item;
|
||||
|
||||
$handler = $this->get_search_handler( $request );
|
||||
if ( is_wp_error( $handler ) ) {
|
||||
return new WP_REST_Response();
|
||||
|
|
|
@ -320,6 +320,7 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
|
|||
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$raw_sidebar = $item;
|
||||
|
||||
$id = $raw_sidebar['id'];
|
||||
$sidebar = array( 'id' => $id );
|
||||
|
||||
|
|
|
@ -209,6 +209,7 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$taxonomy = $item;
|
||||
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
|
|
|
@ -232,8 +232,9 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$theme = $item;
|
||||
$data = array();
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( rest_is_field_included( 'stylesheet', $fields ) ) {
|
||||
$data['stylesheet'] = $theme->get_stylesheet();
|
||||
|
|
|
@ -985,8 +985,9 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$user = $item;
|
||||
$data = array();
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
||||
if ( in_array( 'id', $fields, true ) ) {
|
||||
$data['id'] = $user->ID;
|
||||
|
|
|
@ -297,6 +297,7 @@ class WP_REST_Widget_Types_Controller extends WP_REST_Controller {
|
|||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$widget_type = $item;
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array(
|
||||
'id' => $widget_type['id'],
|
||||
|
|
|
@ -61,6 +61,7 @@ class WP_Sitemaps_Taxonomies extends WP_Sitemaps_Provider {
|
|||
public function get_url_list( $page_num, $object_subtype = '' ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$taxonomy = $object_subtype;
|
||||
|
||||
$supported_types = $this->get_object_subtypes();
|
||||
|
||||
// Bail early if the queried taxonomy is not supported.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.4-alpha-56585';
|
||||
$wp_version = '6.4-alpha-56586';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue