Make WordPress Core


Ignore:
Timestamp:
06/23/2020 11:13:35 PM (6 years ago)
Author:
whyisjake
Message:

Administration: Update WP_List_Table::get_sortable_columns() to support asc and desc arguments.

This makes the API a little more clear, whereas setting false used to mean asc and true meant desc, you can now use those directly, while maintaining back-compat.

Fixes #45089.

Props Tkama, SergeyBiryukov, shital-patel, desrosj, birgire, davidbaumwald.

File:
1 edited

Legend:

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

    r48134 r48151  
    947947
    948948        /**
    949          * Get a list of sortable columns. The format is:
    950          * 'internal-name' => 'orderby'
    951          * or
    952          * 'internal-name' => array( 'orderby', true )
    953          *
    954          * The second format will make the initial sorting order be descending
     949         * Get a list of sortable columns.
     950         *
     951         * The format is:
     952         * - `'internal-name' => 'orderby'`
     953         * - `'internal-name' => array( 'orderby', 'asc' )` - The second element set the initial sorting order.
     954         * - `'internal-name' => array( 'orderby', true )` - The second element will make the initial sorting order be descending.
    955955         *
    956956         * @since 3.1.0
    … …  
    11621162                                        $class[] = $current_order;
    11631163                                } else {
    1164                                         $order   = $desc_first ? 'desc' : 'asc';
     1164                                        if ( in_array( strtolower( $desc_first ), array( 'desc', 'asc' ), true ) ) {
     1165                                                $order = 'asc' === strtolower( $desc_first ) ? 'desc' : 'asc';
     1166                                        } else {
     1167                                                $order = $desc_first ? 'desc' : 'asc';
     1168                                        }
    11651169                                        $class[] = 'sortable';
    1166                                         $class[] = $desc_first ? 'asc' : 'desc';
     1170                                        $class[] = 'desc' === $order ? 'asc' : 'desc';
    11671171                                }
    11681172
Note: See TracChangeset for help on using the changeset viewer.