Make WordPress Core

Changeset 48165


Ignore:
Timestamp:
06/25/2020 11:33:23 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Administration: Correct and simplify the logic for asc and desc arguments in WP_List_Table::get_sortable_columns().

Setting the initial order didn't work as expected due to reversed logic.

Follow-up to [48151].

See #45089.

Location:
trunk
Files:
2 edited

Legend:

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

    r48162 r48165  
    11711171                    $class[] = $current_order;
    11721172                } else {
    1173                     if ( in_array( strtolower( $desc_first ), array( 'desc', 'asc' ), true ) ) {
    1174                         $order = 'asc' === strtolower( $desc_first ) ? 'desc' : 'asc';
    1175                     } else {
     1173                    $order = strtolower( $desc_first );
     1174
     1175                    if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
    11761176                        $order = $desc_first ? 'desc' : 'asc';
    11771177                    }
     
    11811181                }
    11821182
    1183                 $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
     1183                $column_display_name = sprintf(
     1184                    '<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
     1185                    esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
     1186                    $column_display_name
     1187                );
    11841188            }
    11851189
  • trunk/tests/phpunit/tests/admin/includesListTable.php

    r48151 r48165  
    304304            'author'   => array( 'comment_author', true ),
    305305            'response' => 'comment_post_ID',
    306             'date'     => array( 'comment_date', 'dEsC' ), // The ordering support should be case insensitive.
     306            'date'     => array( 'comment_date', 'dEsC' ), // The ordering support should be case-insensitive.
    307307        );
    308308
     
    325325        $this->assertContains( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
    326326
    327         $this->assertContains( '?orderby=comment_date&#038;order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' );
    328         $this->assertContains( 'column-date sortable desc', $output, 'Mismatch of CSS classes for the comment date column.' );
     327        $this->assertContains( '?orderby=comment_date&#038;order=desc', $output, 'Mismatch of the default link ordering for comment date column. Should be asc.' );
     328        $this->assertContains( 'column-date sortable asc', $output, 'Mismatch of CSS classes for the comment date column.' );
    329329    }
    330330
Note: See TracChangeset for help on using the changeset viewer.