Make WordPress Core

Changeset 51728


Ignore:
Timestamp:
09/02/2021 10:25:58 PM (3 years ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix parameter name mismatches for parent/child classes in WP_List_Table::column_default().

Matches the method signatures of the parent class and each child class.

Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

For readability:

  • @since clearly specifies the original parameter name and its new name as well as why the change happened
  • in methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.

Follow-up to [15632], [30679], [31210], [32740], [32753], [32754], [32755], [32756], [32757].

Props jrf, hellofromTonya, @sergeybiryukov, @azaozz, @desrosj, @johnbillion
See #51553.

Location:
trunk/src/wp-admin/includes
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r50805 r51728  
    10481048
    10491049    /**
    1050      * @param WP_Comment $comment     The comment object.
     1050     * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named param.
     1051     *
     1052     * @param WP_Comment $item        The comment object.
    10511053     * @param string     $column_name The custom column's name.
    10521054     */
    1053     public function column_default( $comment, $column_name ) {
     1055    public function column_default( $item, $column_name ) {
    10541056        /**
    10551057         * Fires when the default column output is displayed for a single row.
     
    10601062         * @param int    $comment_id  The custom column's unique ID number.
    10611063         */
    1062         do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
     1064        do_action( 'manage_comments_custom_column', $column_name, $item->comment_ID );
    10631065    }
    10641066}
  • trunk/src/wp-admin/includes/class-wp-links-list-table.php

    r50120 r51728  
    280280     *
    281281     * @since 4.3.0
    282      *
    283      * @param object $link        Link object.
     282     * @since 5.9.0 Renamed `$link` to `$item` to match parent class for PHP 8 named param.
     283     *
     284     * @param object $item        Link object.
    284285     * @param string $column_name Current column name.
    285286     */
    286     public function column_default( $link, $column_name ) {
     287    public function column_default( $item, $column_name ) {
    287288        /**
    288289         * Fires for each registered custom link column.
     
    293294         * @param int    $link_id     Link ID.
    294295         */
    295         do_action( 'manage_link_custom_column', $column_name, $link->link_id );
     296        do_action( 'manage_link_custom_column', $column_name, $item->link_id );
    296297    }
    297298
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r51638 r51728  
    595595     *
    596596     * @since 4.3.0
    597      *
    598      * @param WP_Post $post        The current WP_Post object.
     597     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named param.
     598     *
     599     * @param WP_Post $item        The current WP_Post object.
    599600     * @param string  $column_name Current column name.
    600601     */
    601     public function column_default( $post, $column_name ) {
     602    public function column_default( $item, $column_name ) {
     603        // Restores the more descriptive, specific name for use within this method.
     604        $post = $item;
     605
    602606        if ( 'categories' === $column_name ) {
    603607            $taxonomy = 'category';
  • trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php

    r49197 r51728  
    561561     *
    562562     * @since 4.3.0
    563      *
    564      * @param array  $blog        Current site.
     563     * @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named param.
     564     *
     565     * @param array  $item        Current site.
    565566     * @param string $column_name Current column name.
    566567     */
    567     public function column_default( $blog, $column_name ) {
     568    public function column_default( $item, $column_name ) {
    568569        /**
    569570         * Fires for each registered custom column in the Sites list table.
     
    574575         * @param int    $blog_id     The site ID.
    575576         */
    576         do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
     577        do_action( 'manage_sites_custom_column', $column_name, $item['blog_id'] );
    577578    }
    578579
  • trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php

    r50978 r51728  
    856856     *
    857857     * @since 4.3.0
    858      *
    859      * @param WP_Theme $theme       The current WP_Theme object.
     858     * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named param.
     859     *
     860     * @param WP_Theme $item        The current WP_Theme object.
    860861     * @param string   $column_name The current column name.
    861862     */
    862     public function column_default( $theme, $column_name ) {
    863         $stylesheet = $theme->get_stylesheet();
    864 
     863    public function column_default( $item, $column_name ) {
    865864        /**
    866865         * Fires inside each custom column of the Multisite themes list table.
     
    872871         * @param WP_Theme $theme       Current WP_Theme object.
    873872         */
    874         do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
     873        do_action(
     874            'manage_themes_custom_column',
     875            $column_name,
     876            $item->get_stylesheet(), // Directory name of the theme.
     877            $item // Theme object.
     878        );
    875879    }
    876880
  • trunk/src/wp-admin/includes/class-wp-ms-users-list-table.php

    r49183 r51728  
    443443     *
    444444     * @since 4.3.0
    445      *
    446      * @param WP_User $user        The current WP_User object.
     445     * @since 5.9.0 Renamed `$user` to `$item` to match parent class for PHP 8 named param.
     446     *
     447     * @param WP_User $item        The current WP_User object.
    447448     * @param string  $column_name The current column name.
    448449     */
    449     public function column_default( $user, $column_name ) {
     450    public function column_default( $item, $column_name ) {
    450451        /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
    451         echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
     452        echo apply_filters(
     453            'manage_users_custom_column',
     454            '', // Custom column output. Default empty.
     455            $column_name,
     456            $item->ID // User ID.
     457        );
    452458    }
    453459
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r51520 r51728  
    12361236     *
    12371237     * @since 4.3.0
    1238      *
    1239      * @param WP_Post $post        The current WP_Post object.
     1238     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named param.
     1239     *
     1240     * @param WP_Post $item        The current WP_Post object.
    12401241     * @param string  $column_name The current column name.
    12411242     */
    1242     public function column_default( $post, $column_name ) {
     1243    public function column_default( $item, $column_name ) {
     1244        // Restores the more descriptive, specific name for use within this method.
     1245        $post = $item;
     1246
    12431247        if ( 'categories' === $column_name ) {
    12441248            $taxonomy = 'category';
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r50780 r51728  
    621621
    622622    /**
    623      * @param WP_Term $tag         Term object.
     623     * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named param.
     624     *
     625     * @param WP_Term $item        Term object.
    624626     * @param string  $column_name Name of the column.
    625627     * @return string
    626628     */
    627     public function column_default( $tag, $column_name ) {
     629    public function column_default( $item, $column_name ) {
    628630        /**
    629631         * Filters the displayed columns in the terms list table.
     
    639641         * @since 2.8.0
    640642         *
    641          * @param string $string      Blank string.
     643         * @param string $string      Custom column output. Default empty.
    642644         * @param string $column_name Name of the column.
    643645         * @param int    $term_id     Term ID.
    644646         */
    645         return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
     647        return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $item->term_id );
    646648    }
    647649
Note: See TracChangeset for help on using the changeset viewer.