[wp-trac] [WordPress Trac] #45089: WP_List_Table

WordPress Trac noreply at wordpress.org
Fri Oct 12 20:23:28 UTC 2018


#45089: WP_List_Table
-------------------------+-----------------------------
 Reporter:  Tkama        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  4.9.8
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 When registering new sortable column we can set default first sort order,
 by setting false/true in the second parameter of array:

 {{{#!php
 <?php
 function get_sortable_columns(){
         return array(
                 'register_date' => array( 'register_date', false ), //
 false = asc
                 'login_date'    => array( 'login_date', true ),
                 'rating'        => array( 'rating', false ),
         );
 }
 }}}

 It is much more clear to write 'asc' / 'desc' then false/true.

 To achieve such behavior and not lose current one, we need to change /wp-
 admin/includes/class-wp-list-table.php#L16
 {{{#!php
 <?php
 if ( $current_orderby === $orderby ) {
         $order = 'asc' === $current_order ? 'desc' : 'asc';
         $class[] = 'sorted';
         $class[] = $current_order;
 } else {
         $order = $desc_first ? 'desc' : 'asc';
         $class[] = 'sortable';
         $class[] = $desc_first ? 'asc' : 'desc';
 }
 }}}

 to

 {{{#!php
 <?php
 ...
 } else {
         if( in_array( strtolower($desc_first), array('desc', 'asc'), true
 ) )
                 $order = strtolower( $desc_first );
         else
                 $order = $desc_first ? 'desc' : 'asc';

         $class[] = 'sortable';
         $class[] = $order === 'desc' ? 'asc' : 'desc';
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45089>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list