Skip to content

Commit e005108

Browse files
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
1 parent 4ba29eb commit e005108

30 files changed

+95
-58
lines changed

src/wp-admin/includes/class-walker-nav-menu-edit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public function start_el( &$output, $data_object, $depth = 0, $args = null, $cur
6161
global $_wp_nav_menu_max_depth;
6262

6363
// Restores the more descriptive, specific name for use within this method.
64-
$menu_item = $data_object;
64+
$menu_item = $data_object;
65+
6566
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
6667

6768
ob_start();

src/wp-admin/includes/class-wp-comments-list-table.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
685685
}
686686

687687
// Restores the more descriptive, specific name for use within this method.
688-
$comment = $item;
688+
$comment = $item;
689+
689690
$the_comment_status = wp_get_comment_status( $comment );
690691

691692
$output = '';
@@ -1087,6 +1088,9 @@ public function column_response( $comment ) {
10871088
* @param string $column_name The custom column's name.
10881089
*/
10891090
public function column_default( $item, $column_name ) {
1091+
// Restores the more descriptive, specific name for use within this method.
1092+
$comment = $item;
1093+
10901094
/**
10911095
* Fires when the default column output is displayed for a single row.
10921096
*
@@ -1095,6 +1099,6 @@ public function column_default( $item, $column_name ) {
10951099
* @param string $column_name The custom column's name.
10961100
* @param string $comment_id The comment ID as a numeric string.
10971101
*/
1098-
do_action( 'manage_comments_custom_column', $column_name, $item->comment_ID );
1102+
do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
10991103
}
11001104
}

src/wp-admin/includes/class-wp-links-list-table.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ public function column_rating( $link ) {
290290
* @param string $column_name Current column name.
291291
*/
292292
public function column_default( $item, $column_name ) {
293+
// Restores the more descriptive, specific name for use within this method.
294+
$link = $item;
295+
293296
/**
294297
* Fires for each registered custom link column.
295298
*
@@ -298,7 +301,7 @@ public function column_default( $item, $column_name ) {
298301
* @param string $column_name Name of the custom column.
299302
* @param int $link_id Link ID.
300303
*/
301-
do_action( 'manage_link_custom_column', $column_name, $item->link_id );
304+
do_action( 'manage_link_custom_column', $column_name, $link->link_id );
302305
}
303306

304307
public function display_rows() {
@@ -332,7 +335,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
332335
}
333336

334337
// Restores the more descriptive, specific name for use within this method.
335-
$link = $item;
338+
$link = $item;
339+
336340
$edit_link = get_edit_bookmark_link( $link );
337341

338342
$actions = array();

src/wp-admin/includes/class-wp-media-list-table.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,11 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
880880
return '';
881881
}
882882

883+
// Restores the more descriptive, specific name for use within this method.
884+
$post = $item;
885+
883886
$att_title = _draft_or_post_title();
884-
$actions = $this->_get_row_actions(
885-
$item, // WP_Post object for an attachment.
886-
$att_title
887-
);
887+
$actions = $this->_get_row_actions( $post, $att_title );
888888

889889
return $this->row_actions( $actions );
890890
}

src/wp-admin/includes/class-wp-ms-sites-list-table.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ public function column_plugins( $blog ) {
597597
* @param string $column_name Current column name.
598598
*/
599599
public function column_default( $item, $column_name ) {
600+
// Restores the more descriptive, specific name for use within this method.
601+
$blog = $item;
602+
600603
/**
601604
* Fires for each registered custom column in the Sites list table.
602605
*
@@ -605,7 +608,7 @@ public function column_default( $item, $column_name ) {
605608
* @param string $column_name The name of the column to display.
606609
* @param int $blog_id The site ID.
607610
*/
608-
do_action( 'manage_sites_custom_column', $column_name, $item['blog_id'] );
611+
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
609612
}
610613

611614
/**
@@ -714,7 +717,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
714717
}
715718

716719
// Restores the more descriptive, specific name for use within this method.
717-
$blog = $item;
720+
$blog = $item;
721+
718722
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
719723

720724
// Preordered.

src/wp-admin/includes/class-wp-ms-themes-list-table.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ public function display_rows() {
509509
*/
510510
public function column_cb( $item ) {
511511
// Restores the more descriptive, specific name for use within this method.
512-
$theme = $item;
512+
$theme = $item;
513+
513514
$checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
514515
?>
515516
<label class="label-covers-full-cell" for="<?php echo $checkbox_id; ?>" >
@@ -878,6 +879,11 @@ public function column_autoupdates( $theme ) {
878879
* @param string $column_name The current column name.
879880
*/
880881
public function column_default( $item, $column_name ) {
882+
// Restores the more descriptive, specific name for use within this method.
883+
$theme = $item;
884+
885+
$stylesheet = $theme->get_stylesheet();
886+
881887
/**
882888
* Fires inside each custom column of the Multisite themes list table.
883889
*
@@ -887,12 +893,7 @@ public function column_default( $item, $column_name ) {
887893
* @param string $stylesheet Directory name of the theme.
888894
* @param WP_Theme $theme Current WP_Theme object.
889895
*/
890-
do_action(
891-
'manage_themes_custom_column',
892-
$column_name,
893-
$item->get_stylesheet(), // Directory name of the theme.
894-
$item // Theme object.
895-
);
896+
do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
896897
}
897898

898899
/**

src/wp-admin/includes/class-wp-ms-users-list-table.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,11 @@ public function column_blogs( $user ) {
458458
* @param string $column_name The current column name.
459459
*/
460460
public function column_default( $item, $column_name ) {
461+
// Restores the more descriptive, specific name for use within this method.
462+
$user = $item;
463+
461464
/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
462-
echo apply_filters(
463-
'manage_users_custom_column',
464-
'', // Custom column output. Default empty.
465-
$column_name,
466-
$item->ID // User ID.
467-
);
465+
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
468466
}
469467

470468
public function display_rows() {
@@ -519,10 +517,10 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
519517
}
520518

521519
// Restores the more descriptive, specific name for use within this method.
522-
$user = $item;
523-
$super_admins = get_super_admins();
520+
$user = $item;
524521

525-
$actions = array();
522+
$super_admins = get_super_admins();
523+
$actions = array();
526524

527525
if ( current_user_can( 'edit_user', $user->ID ) ) {
528526
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

src/wp-admin/includes/class-wp-posts-list-table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ private function _page_rows( &$children_pages, &$count, $parent_page, $level, $p
10191019
public function column_cb( $item ) {
10201020
// Restores the more descriptive, specific name for use within this method.
10211021
$post = $item;
1022+
10221023
$show = current_user_can( 'edit_post', $post->ID );
10231024

10241025
/**
@@ -1458,7 +1459,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
14581459
}
14591460

14601461
// Restores the more descriptive, specific name for use within this method.
1461-
$post = $item;
1462+
$post = $item;
1463+
14621464
$post_type_object = get_post_type_object( $post->post_type );
14631465
$can_edit_post = current_user_can( 'edit_post', $post->ID );
14641466
$actions = array();

src/wp-admin/includes/class-wp-terms-list-table.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
464464
}
465465

466466
// Restores the more descriptive, specific name for use within this method.
467-
$tag = $item;
467+
$tag = $item;
468+
468469
$taxonomy = $this->screen->taxonomy;
469470
$uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
470471

@@ -626,6 +627,9 @@ public function column_links( $tag ) {
626627
* @return string
627628
*/
628629
public function column_default( $item, $column_name ) {
630+
// Restores the more descriptive, specific name for use within this method.
631+
$tag = $item;
632+
629633
/**
630634
* Filters the displayed columns in the terms list table.
631635
*
@@ -643,7 +647,7 @@ public function column_default( $item, $column_name ) {
643647
* @param string $column_name Name of the column.
644648
* @param int $term_id Term ID.
645649
*/
646-
return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $item->term_id );
650+
return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
647651
}
648652

649653
/**

src/wp-includes/class-walker-category-dropdown.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Walker_CategoryDropdown extends Walker {
5959
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
6060
// Restores the more descriptive, specific name for use within this method.
6161
$category = $data_object;
62-
$pad = str_repeat( '&nbsp;', $depth * 3 );
62+
63+
$pad = str_repeat( '&nbsp;', $depth * 3 );
6364

6465
/** This filter is documented in wp-includes/category-template.php */
6566
$cat_name = apply_filters( 'list_cats', $category->name, $category );

0 commit comments

Comments
 (0)