Make WordPress Core


Ignore:
Timestamp:
09/07/2021 07:23:00 PM (3 years ago)
Author:
hellofromTonya
Message:

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

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 [32644], [32664], [32798], [38489], [49183], [49197].

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

File:
1 edited

Legend:

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

    r51735 r51737  
    828828     *
    829829     * @since 4.3.0
    830      *
    831      * @param WP_Post $post        Attachment being acted upon.
     830     * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
     831     *
     832     * @param WP_Post $item        Attachment being acted upon.
    832833     * @param string  $column_name Current column name.
    833834     * @param string  $primary     Primary column name.
     
    835836     *                if the current column is not the primary column.
    836837     */
    837     protected function handle_row_actions( $post, $column_name, $primary ) {
     838    protected function handle_row_actions( $item, $column_name, $primary ) {
    838839        if ( $primary !== $column_name ) {
    839840            return '';
     
    841842
    842843        $att_title = _draft_or_post_title();
    843 
    844         return $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
     844        $actions   = $this->_get_row_actions(
     845            $item, // WP_Post object for an attachment.
     846            $att_title
     847        );
     848
     849        return $this->row_actions( $actions );
    845850    }
    846851}
Note: See TracChangeset for help on using the changeset viewer.