Skip to content

Commit

Permalink
Coding Standards: Restore more descriptive variable names in a few cl…
Browse files Browse the repository at this point in the history
…ass 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
  • Loading branch information
SergeyBiryukov committed Sep 14, 2023
1 parent 4ba29eb commit e005108
Show file tree
Hide file tree
Showing 30 changed files with 95 additions and 58 deletions.
3 changes: 2 additions & 1 deletion src/wp-admin/includes/class-walker-nav-menu-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions src/wp-admin/includes/class-wp-comments-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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.
*
Expand All @@ -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 );
}
}
8 changes: 6 additions & 2 deletions src/wp-admin/includes/class-wp-links-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/wp-admin/includes/class-wp-media-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
8 changes: 6 additions & 2 deletions src/wp-admin/includes/class-wp-ms-sites-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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'] );
}

/**
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions src/wp-admin/includes/class-wp-ms-themes-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
?>
<label class="label-covers-full-cell" for="<?php echo $checkbox_id; ?>" >
Expand Down Expand Up @@ -878,6 +879,11 @@ public function column_autoupdates( $theme ) {
* @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.
*
Expand All @@ -887,12 +893,7 @@ public function column_default( $item, $column_name ) {
* @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 );
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/wp-admin/includes/class-wp-ms-users-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,11 @@ public function column_blogs( $user ) {
* @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() {
Expand Down Expand Up @@ -519,10 +517,10 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
}

// 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 ) ) );
Expand Down
4 changes: 3 additions & 1 deletion src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ private function _page_rows( &$children_pages, &$count, $parent_page, $level, $p
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 );

/**
Expand Down Expand Up @@ -1458,7 +1459,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
}

// 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();
Expand Down
8 changes: 6 additions & 2 deletions src/wp-admin/includes/class-wp-terms-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
}

// 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'];

Expand Down Expand Up @@ -626,6 +627,9 @@ public function column_links( $tag ) {
* @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.
*
Expand All @@ -643,7 +647,7 @@ public function column_default( $item, $column_name ) {
* @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 );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/class-walker-category-dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ 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( '&nbsp;', $depth * 3 );

$pad = str_repeat( '&nbsp;', $depth * 3 );

/** This filter is documented in wp-includes/category-template.php */
$cat_name = apply_filters( 'list_cats', $category->name, $category );
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/class-walker-page-dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ 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( '&nbsp;', $depth * 3 );

$pad = str_repeat( '&nbsp;', $depth * 3 );

if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
$args['value_field'] = 'ID';
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/class-walker-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function end_lvl( &$output, $depth = 0, $args = array() ) {
*/
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;
$page = $data_object;

$current_page_id = $current_object_id;

if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,8 @@ protected function prepare_item_for_database( $request ) {
*/
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$post = $item;
$post = $item;

$response = parent::prepare_item_for_response( $post, $request );
$fields = $this->get_fields_for_response( $request );
$data = $response->get_data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@ public function create_post_autosave( $post_data ) {
*/
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 );
$post = $item;

$fields = $this->get_fields_for_response( $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 ) ) {
$parent_id = wp_is_post_autosave( $post );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ public function get_item( $request ) {
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();

$fields = $this->get_fields_for_response( $request );
$data = array();

if ( rest_is_field_included( 'attributes', $fields ) ) {
$data['attributes'] = $block_type->get_attributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,9 @@ public function delete_item( $request ) {
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();

$fields = $this->get_fields_for_response( $request );
$data = array();

if ( in_array( 'id', $fields, true ) ) {
$data['id'] = (int) $comment->comment_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ public function prepare_item_for_response( $post, $request ) { // phpcs:ignore V
}

// 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;
Expand Down Expand Up @@ -603,8 +603,8 @@ public function get_theme_item( $request ) {
}

$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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public function get_item( $request ) {
*/
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$location = $item;
$location = $item;

$locations = get_nav_menu_locations();
$menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public function get_items( $request ) {
*/
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$raw_pattern = $item;
$raw_pattern = $item;

$prepared_pattern = array(
'id' => absint( $raw_pattern->id ),
'title' => sanitize_text_field( $raw_pattern->title->rendered ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public function get_item( $request ) {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public function get_item( $request ) {
*/
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$post_type = $item;
$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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,8 @@ protected function check_delete_permission( $post ) {
*/
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$post = $item;
$post = $item;

$GLOBALS['post'] = $post;

setup_postdata( $post );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ protected function prepare_items_query( $prepared_args = array(), $request = nul
*/
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$post = $item;
$post = $item;

$GLOBALS['post'] = $post;

setup_postdata( $post );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function get_items( $request ) {
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();
Expand Down
Loading

0 comments on commit e005108

Please sign in to comment.