Make WordPress Core

Changeset 56586


Ignore:
Timestamp:
09/14/2023 12:44:23 PM (15 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-nav-menu-edit.php

    r56547 r56586  
    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
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r56450 r56586  
    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
     
    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.
     
    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}
  • trunk/src/wp-admin/includes/class-wp-links-list-table.php

    r56450 r56586  
    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.
     
    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
     
    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
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r56450 r56586  
    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 );
  • trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php

    r56450 r56586  
    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.
     
    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
     
    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
  • trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php

    r56450 r56586  
    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        ?>
     
    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.
     
    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
  • trunk/src/wp-admin/includes/class-wp-ms-users-list-table.php

    r56450 r56586  
    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
     
    520518
    521519        // Restores the more descriptive, specific name for use within this method.
    522         $user         = $item;
     520        $user = $item;
     521
    523522        $super_admins = get_super_admins();
    524 
    525         $actions = array();
     523        $actions      = array();
    526524
    527525        if ( current_user_can( 'edit_user', $user->ID ) ) {
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r56571 r56586  
    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
     
    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 );
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r56571 r56586  
    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'];
     
    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.
     
    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
  • trunk/src/wp-includes/class-walker-category-dropdown.php

    r52652 r56586  
    6060        // Restores the more descriptive, specific name for use within this method.
    6161        $category = $data_object;
    62         $pad      = str_repeat( ' ', $depth * 3 );
     62
     63        $pad = str_repeat( ' ', $depth * 3 );
    6364
    6465        /** This filter is documented in wp-includes/category-template.php */
  • trunk/src/wp-includes/class-walker-page-dropdown.php

    r55905 r56586  
    6363        // Restores the more descriptive, specific name for use within this method.
    6464        $page = $data_object;
    65         $pad  = str_repeat( ' ', $depth * 3 );
     65
     66        $pad = str_repeat( ' ', $depth * 3 );
    6667
    6768        if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
  • trunk/src/wp-includes/class-walker-page.php

    r56547 r56586  
    105105    public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    106106        // Restores the more descriptive, specific name for use within this method.
    107         $page            = $data_object;
     107        $page = $data_object;
     108
    108109        $current_page_id = $current_object_id;
    109110
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r56547 r56586  
    732732    public function prepare_item_for_response( $item, $request ) {
    733733        // Restores the more descriptive, specific name for use within this method.
    734         $post     = $item;
     734        $post = $item;
     735
    735736        $response = parent::prepare_item_for_response( $post, $request );
    736737        $fields   = $this->get_fields_for_response( $request );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php

    r56548 r56586  
    410410    public function prepare_item_for_response( $item, $request ) {
    411411        // Restores the more descriptive, specific name for use within this method.
    412         $post     = $item;
     412        $post = $item;
     413
    413414        $response = $this->revisions_controller->prepare_item_for_response( $post, $request );
    414 
    415         $fields = $this->get_fields_for_response( $request );
     415        $fields   = $this->get_fields_for_response( $request );
    416416
    417417        if ( in_array( 'preview_link', $fields, true ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php

    r56547 r56586  
    247247        // Restores the more descriptive, specific name for use within this method.
    248248        $block_type = $item;
    249         $fields     = $this->get_fields_for_response( $request );
    250         $data       = array();
     249
     250        $fields = $this->get_fields_for_response( $request );
     251        $data   = array();
    251252
    252253        if ( rest_is_field_included( 'attributes', $fields ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r56193 r56586  
    10401040        // Restores the more descriptive, specific name for use within this method.
    10411041        $comment = $item;
    1042         $fields  = $this->get_fields_for_response( $request );
    1043         $data    = array();
     1042
     1043        $fields = $this->get_fields_for_response( $request );
     1044        $data   = array();
    10441045
    10451046        if ( in_array( 'id', $fields, true ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

    r56575 r56586  
    368368
    369369        // Base fields for every post.
     370        $fields = $this->get_fields_for_response( $request );
    370371        $data   = array();
    371         $fields = $this->get_fields_for_response( $request );
    372372
    373373        if ( rest_is_field_included( 'id', $fields ) ) {
     
    604604
    605605        $theme  = WP_Theme_JSON_Resolver::get_merged_data( 'theme' );
     606        $fields = $this->get_fields_for_response( $request );
    606607        $data   = array();
    607         $fields = $this->get_fields_for_response( $request );
    608608
    609609        if ( rest_is_field_included( 'settings', $fields ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php

    r56415 r56586  
    169169    public function prepare_item_for_response( $item, $request ) {
    170170        // Restores the more descriptive, specific name for use within this method.
    171         $location  = $item;
     171        $location = $item;
     172
    172173        $locations = get_nav_menu_locations();
    173174        $menu      = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php

    r55234 r56586  
    194194    public function prepare_item_for_response( $item, $request ) {
    195195        // Restores the more descriptive, specific name for use within this method.
    196         $raw_pattern      = $item;
     196        $raw_pattern = $item;
     197
    197198        $prepared_pattern = array(
    198199            'id'             => absint( $raw_pattern->id ),
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php

    r56547 r56586  
    223223        // Restores the more descriptive, specific name for use within this method.
    224224        $status = $item;
     225
    225226        $fields = $this->get_fields_for_response( $request );
    226227        $data   = array();
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php

    r54288 r56586  
    177177    public function prepare_item_for_response( $item, $request ) {
    178178        // Restores the more descriptive, specific name for use within this method.
    179         $post_type  = $item;
     179        $post_type = $item;
     180
    180181        $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
    181182        $taxonomies = wp_list_pluck( $taxonomies, 'name' );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r56548 r56586  
    17491749    public function prepare_item_for_response( $item, $request ) {
    17501750        // Restores the more descriptive, specific name for use within this method.
    1751         $post            = $item;
     1751        $post = $item;
     1752
    17521753        $GLOBALS['post'] = $post;
    17531754
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    r56548 r56586  
    548548    public function prepare_item_for_response( $item, $request ) {
    549549        // Restores the more descriptive, specific name for use within this method.
    550         $post            = $item;
     550        $post = $item;
     551
    551552        $GLOBALS['post'] = $post;
    552553
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php

    r55293 r56586  
    196196        // Restores the more descriptive, specific name for use within this method.
    197197        $item_id = $item;
     198
    198199        $handler = $this->get_search_handler( $request );
    199200        if ( is_wp_error( $handler ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php

    r56195 r56586  
    321321        // Restores the more descriptive, specific name for use within this method.
    322322        $raw_sidebar = $item;
    323         $id          = $raw_sidebar['id'];
    324         $sidebar     = array( 'id' => $id );
     323
     324        $id      = $raw_sidebar['id'];
     325        $sidebar = array( 'id' => $id );
    325326
    326327        if ( isset( $wp_registered_sidebars[ $id ] ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php

    r54471 r56586  
    210210        // Restores the more descriptive, specific name for use within this method.
    211211        $taxonomy = $item;
    212         $base     = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
     212
     213        $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
    213214
    214215        $fields = $this->get_fields_for_response( $request );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r56415 r56586  
    232232    public function prepare_item_for_response( $item, $request ) {
    233233        // Restores the more descriptive, specific name for use within this method.
    234         $theme  = $item;
     234        $theme = $item;
     235
     236        $fields = $this->get_fields_for_response( $request );
    235237        $data   = array();
    236         $fields = $this->get_fields_for_response( $request );
    237238
    238239        if ( rest_is_field_included( 'stylesheet', $fields ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r56195 r56586  
    985985    public function prepare_item_for_response( $item, $request ) {
    986986        // Restores the more descriptive, specific name for use within this method.
    987         $user   = $item;
     987        $user = $item;
     988
     989        $fields = $this->get_fields_for_response( $request );
    988990        $data   = array();
    989         $fields = $this->get_fields_for_response( $request );
    990991
    991992        if ( in_array( 'id', $fields, true ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php

    r56559 r56586  
    298298        // Restores the more descriptive, specific name for use within this method.
    299299        $widget_type = $item;
    300         $fields      = $this->get_fields_for_response( $request );
    301         $data        = array(
     300
     301        $fields = $this->get_fields_for_response( $request );
     302        $data   = array(
    302303            'id' => $widget_type['id'],
    303304        );
  • trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php

    r53302 r56586  
    6161    public function get_url_list( $page_num, $object_subtype = '' ) {
    6262        // Restores the more descriptive, specific name for use within this method.
    63         $taxonomy        = $object_subtype;
     63        $taxonomy = $object_subtype;
     64
    6465        $supported_types = $this->get_object_subtypes();
    6566
Note: See TracChangeset for help on using the changeset viewer.