Make WordPress Core

Ticket #32170: 32170.2.patch

File 32170.2.patch, 15.7 KB (added by afercia, 10 years ago)
  • src/wp-admin/includes/class-wp-comments-list-table.php

     
    318318
    319319        protected function get_sortable_columns() {
    320320                return array(
    321                         'author'   => 'comment_author',
    322                         'response' => 'comment_post_ID'
     321                        'author'   => array( 'comment_author', false, __( 'Table ordered by Comment Author.' ) ),
     322                        'response' => array( 'comment_post_ID', false, __( 'Table ordered by Post Replied To.' ) ),
    323323                );
    324324        }
    325325
     
    328328
    329329                $this->display_tablenav( 'top' );
    330330
     331                if ( ! isset( $_GET['orderby'] ) ) {
     332                        // in the initial view, Comments are ordered by comment's date but there's no column for that
     333                        echo '<p id="table-description">' . __( 'Table ordered by Comment Date. Descending order.' ) . '</p>';
     334                } else {
     335                        $this->print_table_description();
     336                }
    331337?>
    332 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>">
     338<table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" aria-describedby="table-description">
    333339        <thead>
    334340        <tr>
    335341                <?php $this->print_column_headers(); ?>
  • src/wp-admin/includes/class-wp-links-list-table.php

     
    101101
    102102        protected function get_sortable_columns() {
    103103                return array(
    104                         'name'    => 'name',
    105                         'url'     => 'url',
    106                         'visible' => 'visible',
    107                         'rating'  => 'rating'
     104                        'name'    => array( 'name', false, __( 'Table ordered by Name.' ), 'asc' ),
     105                        'url'     => array( 'url', false, __( 'Table ordered by URL.' ) ),
     106                        'visible' => array( 'visible', false, __( 'Table ordered by Visibility.' ) ),
     107                        'rating'  => array( 'rating', false, __( 'Table ordered by Rating.' ) ),
    108108                );
    109109        }
    110110
  • src/wp-admin/includes/class-wp-list-table.php

     
    779779         * 'internal-name' => 'orderby'
    780780         * or
    781781         * 'internal-name' => array( 'orderby', true )
     782         * or
     783         * 'internal-name' => array( 'orderby', bool, 'orderby-text', 'initially-sorted-column-order' )
    782784         *
    783          * The second format will make the initial sorting order be descending
     785         * The second format will make the initial sorting order be descending.
     786         * The third format adds a translatable string for the current sorting
     787         * and the order for the initial view sorted column, 'asc' or 'desc'.
     788         * Setting 'asc' or 'desc' also specifies which is the initially sorted column.
    784789         *
    785790         * @since 3.1.0
     791         * @since 4.3.0 Introduced 'orderby-text' and 'initially-sorted-column-order'.
    786792         * @access protected
    787793         *
    788794         * @return array
     
    825831                                continue;
    826832
    827833                        $data = (array) $data;
    828                         if ( !isset( $data[1] ) )
     834
     835                        // descending initial sorting
     836                        if ( ! isset( $data[1] ) )
    829837                                $data[1] = false;
     838                        // current sorting translatable string
     839                        if ( ! isset( $data[2] ) )
     840                                $data[2] = '';
     841                        // initial view sorted column and asc/desc order
     842                        if ( ! isset( $data[3] ) )
     843                                $data[3] = false;
    830844
    831845                        $sortable[$id] = $data;
    832846                }
     
    872886                if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
    873887                        $current_order = 'desc';
    874888                else
    875                         $current_order = 'asc';
     889                        $current_order = 'asc'; // the initial view is not always 'asc' we'll take care of this below
    876890
    877891                if ( ! empty( $columns['cb'] ) ) {
    878892                        static $cb_counter = 1;
     
    884898                foreach ( $columns as $column_key => $column_display_name ) {
    885899                        $class = array( 'manage-column', "column-$column_key" );
    886900
    887                         $style = '';
    888                         if ( in_array( $column_key, $hidden ) )
    889                                 $style = 'display:none;';
     901                        $style = $aria_sort_attr = '';
     902                        if ( in_array( $column_key, $hidden ) ) {
     903                                $style = ' style="display:none;"';
     904                        }
    890905
    891                         $style = ' style="' . $style . '"';
    892 
    893906                        if ( 'cb' == $column_key )
    894907                                $class[] = 'check-column';
    895908                        elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
     
    896909                                $class[] = 'num';
    897910
    898911                        if ( isset( $sortable[$column_key] ) ) {
    899                                 list( $orderby, $desc_first ) = $sortable[$column_key];
     912                                list( $orderby, $desc_first, $orderby_text, $initial_order ) = $sortable[$column_key];
    900913
     914                                // we're in the initial view and there's no $_GET['orderby'] then check if the
     915                                // initial sorting information is set in the sortable columns and use that
     916                                if ( '' === $current_orderby && $initial_order ) {
     917                                        // use the initially sorted column $orderby as current orderby
     918                                        $current_orderby = $orderby;
     919                                        // use the initially sorted column asc/desc order as initial order
     920                                        $current_order = $initial_order;
     921                                }
     922
     923                                // true in the initial view when an initial orderby is set via get_sortable_columns()
     924                                // and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby
    901925                                if ( $current_orderby == $orderby ) {
    902                                         $order = 'asc' == $current_order ? 'desc' : 'asc';
     926                                        // the sorted column
     927                                        // the `aria-sort` attribute must be set only on the sorted column
     928                                        if ( 'asc' == $current_order ) {
     929                                                $order = 'desc';
     930                                                $aria_sort_attr = ' aria-sort="ascending"';
     931                                        } else {
     932                                                $order = 'asc';
     933                                                $aria_sort_attr = ' aria-sort="descending"';
     934                                        }
    903935                                        $class[] = 'sorted';
    904936                                        $class[] = $current_order;
    905937                                } else {
     938                                        // the other sortable columns
    906939                                        $order = $desc_first ? 'desc' : 'asc';
    907940                                        $class[] = 'sortable';
    908941                                        $class[] = $desc_first ? 'asc' : 'desc';
     
    911944                                $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>';
    912945                        }
    913946
    914                         $id = $with_id ? "id='$column_key'" : '';
     947                        $id = $with_id ? " id='$column_key'" : '';
    915948
    916949                        if ( !empty( $class ) )
    917                                 $class = "class='" . join( ' ', $class ) . "'";
     950                                $class = " class='" . join( ' ', $class ) . "'";
    918951
    919                         echo "<th scope='col' $id $class $style>$column_display_name</th>";
     952                        echo "<th scope='col'$id$class$style$aria_sort_attr>$column_display_name</th>";
    920953                }
    921954        }
    922955
    923956        /**
     957         * Print table description, with information about current sorting and order.
     958         *
     959         * For the table initial view, information about initial orderby and order
     960         * should be provided via get_sortable_columns().
     961         *
     962         * @since 4.3.0
     963         * @access public
     964         */
     965        public function print_table_description() {
     966                list( $columns, $hidden, $sortable ) = $this->get_column_info();
     967
     968                if ( empty( $sortable ) ) {
     969                        return;
     970                }
     971
     972                // when users click on a column header to sort by other columns
     973                if ( isset( $_GET['orderby'] ) ) {
     974                        $current_orderby = $_GET['orderby'];
     975                // in the initial view there's no orderby parameter
     976                } else {
     977                        $current_orderby = '';
     978                }
     979
     980                // not in the initial view and descending order
     981                if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
     982                        $current_order = 'desc';
     983                } else {
     984                        // the initial view is not always 'asc' we'll take care of this below
     985                        $current_order = 'asc';
     986                }
     987
     988                // array_keys is slower? does it matter here?
     989                foreach ( array_keys( $columns ) as $column_key ) {
     990
     991                        if ( isset( $sortable[$column_key] ) ) {
     992
     993                                list( $orderby, $desc_first, $orderby_text, $initial_order ) = $sortable[$column_key];
     994
     995                                if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
     996                                        return;
     997                                }
     998                                // we're in the initial view and there's no $_GET['orderby'] then check if the
     999                                // initial sorting information is set in the sortable columns and use that
     1000                                if ( '' === $current_orderby && $initial_order ) {
     1001                                        // use the initially sorted column $orderby as current orderby
     1002                                        $current_orderby = $orderby;
     1003                                        // use the initially sorted column asc/desc order as initial order
     1004                                        $current_order = $initial_order;
     1005                                }
     1006
     1007                                // true in the initial view when an initial orderby is set via get_sortable_columns()
     1008                                // and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby
     1009                                if ( $current_orderby == $orderby ) {
     1010                                        $order_text = 'asc' === $current_order ? __( 'Ascending order.' ) : __( 'Descending order.' );
     1011                                        echo '<p id="table-description">' . $orderby_text . ' ' . $order_text . '</p>';
     1012
     1013                                        return;
     1014                                }
     1015                        }
     1016                }
     1017        }
     1018
     1019        /**
    9241020         * Display the table
    9251021         *
    9261022         * @since 3.1.0
     
    9311027
    9321028                $this->display_tablenav( 'top' );
    9331029
     1030                $this->print_table_description();
    9341031?>
    935 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
     1032<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" aria-describedby="table-description">
    9361033        <thead>
    9371034        <tr>
    9381035                <?php $this->print_column_headers(); ?>
  • src/wp-admin/includes/class-wp-media-list-table.php

     
    262262
    263263        protected function get_sortable_columns() {
    264264                return array(
    265                         'title'    => 'title',
    266                         'author'   => 'author',
    267                         'parent'   => 'parent',
    268                         'comments' => 'comment_count',
    269                         'date'     => array( 'date', true ),
     265                        'title'    => array( 'title', false, __( 'Table ordered by File Name.' ) ),
     266                        'author'   => array( 'author', false, __( 'Table ordered by Author.' ) ),
     267                        'parent'   => array( 'parent', false, __( 'Table ordered by Uploaded To.' ) ),
     268                        'comments' => array( 'comment_count', false, __( 'Table ordered by Comments.' ) ),
     269                        'date'     => array( 'date', true, __( 'Table ordered by Date.' ), 'desc' ),
    270270                );
    271271        }
    272272
  • src/wp-admin/includes/class-wp-ms-sites-list-table.php

     
    185185        }
    186186
    187187        protected function get_sortable_columns() {
     188                $blogname_orderby_text = ( is_subdomain_install() ) ? __( 'Table ordered by Site Domain Name.' ) : __( 'Table ordered by Site Path.' );
    188189                return array(
    189                         'blogname'    => 'blogname',
    190                         'lastupdated' => 'lastupdated',
    191                         'registered'  => 'blog_id',
     190                        'blogname'    => array( 'blogname', false, $blogname_orderby_text ),
     191                        'lastupdated' => array( 'lastupdated', true, __( 'Table ordered by Last Updated.' ) ),
     192                        'registered'  => array( 'blog_id', true, __( 'Table ordered by Registered Date.' ), 'desc' ),
    192193                );
    193194        }
    194195
  • src/wp-admin/includes/class-wp-ms-themes-list-table.php

     
    211211
    212212        protected function get_sortable_columns() {
    213213                return array(
    214                         'name'         => 'name',
     214                        'name' => array( 'name', false, __( 'Table ordered by Theme Name.' ), 'asc' ),
    215215                );
    216216        }
    217217
  • src/wp-admin/includes/class-wp-ms-users-list-table.php

     
    139139
    140140        protected function get_sortable_columns() {
    141141                return array(
    142                         'username'   => 'login',
    143                         'name'       => 'name',
    144                         'email'      => 'email',
    145                         'registered' => 'id',
     142                        'username'   => array( 'login', false, __( 'Table ordered by Username.' ), 'asc' ),
     143                        'name'       => array( 'name', false, __( 'Table ordered by Name.' ) ),
     144                        'email'      => array( 'email', false, __( 'Table ordered by E-mail.' ) ),
     145                        'registered' => array( 'id', false, __( 'Table ordered by Registered Date.' ) ),
    146146                );
    147147        }
    148148
  • src/wp-admin/includes/class-wp-posts-list-table.php

     
    417417        }
    418418
    419419        protected function get_sortable_columns() {
    420                 return array(
    421                         'title'    => 'title',
    422                         'parent'   => 'parent',
    423                         'comments' => 'comment_count',
    424                         'date'     => array( 'date', true )
    425                 );
     420
     421                $post_type = $this->screen->post_type;
     422
     423                if ( 'page' === $post_type ) {
     424                        $title_orderby_text = isset( $_GET['orderby'] ) ? __( 'Table ordered by Title.' ) : __( 'Table ordered by Hierarchical Menu Order and Title.' );
     425                        $sortables = array(
     426                                'title'    => array( 'title', false, $title_orderby_text, 'asc' ),
     427                                'parent'   => array( 'parent', false ),
     428                                'comments' => array( 'comment_count', false, __( 'Table ordered by Comments.' ) ),
     429                                'date'     => array( 'date', true, __( 'Table ordered by Date.' ) ),
     430                        );
     431                } else {
     432                        $sortables = array(
     433                                'title'    => array( 'title', false, __( 'Table ordered by Title.' ) ),
     434                                'parent'   => array( 'parent', false ),
     435                                'comments' => array( 'comment_count', false, __( 'Table ordered by Comments.' ) ),
     436                                'date'     => array( 'date', true, __( 'Table ordered by Date.' ), 'desc' ),
     437                        );
     438                }
     439                // Custom Post Types: there's a filter for that, see get_column_info()
     440
     441                return $sortables;
    426442        }
    427443
    428444        /**
  • src/wp-admin/includes/class-wp-terms-list-table.php

     
    150150        }
    151151
    152152        protected function get_sortable_columns() {
     153
     154                $taxonomy = $this->screen->taxonomy;
     155
     156                if ( ! isset( $_GET['orderby'] ) && is_taxonomy_hierarchical( $taxonomy ) ) {
     157                        $name_orderby_text = __( 'Table ordered hierarchically.' );
     158                } else {
     159                        $name_orderby_text = __( 'Table ordered by Name.' );
     160                }
     161
    153162                return array(
    154                         'name'        => 'name',
    155                         'description' => 'description',
    156                         'slug'        => 'slug',
    157                         'posts'       => 'count',
    158                         'links'       => 'count'
     163                        'name'        => array( 'name', false, $name_orderby_text, 'asc' ),
     164                        'description' => array( 'description', false, __( 'Table ordered by Description.' ) ),
     165                        'slug'        => array( 'slug', false, __( 'Table ordered by Slug.' ) ),
     166                        'posts'       => array( 'count', false, __( 'Table ordered by Posts Count.' ) ),
     167                        'links'       => array( 'count', false, __( 'Table ordered by Links Count.' ) ),
    159168                );
    160169        }
    161170
  • src/wp-admin/includes/class-wp-users-list-table.php

     
    282282         */
    283283        protected function get_sortable_columns() {
    284284                $c = array(
    285                         'username' => 'login',
    286                         'name'     => 'name',
    287                         'email'    => 'email',
     285                        'username' => array( 'login', false, __( 'Table ordered by Username.' ), 'asc' ),
     286                        'name'     => array( 'name', false, __( 'Table ordered by Name.' ) ),
     287                        'email'    => array( 'email', false, __( 'Table ordered by E-mail.' ) ),
    288288                );
    289289
    290290                if ( $this->is_site_users )
     
    420420                                        $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
    421421                                        break;
    422422                                case 'email':
    423                                         $r .= "<td $attributes><a href='mailto:$email' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a></td>";
     423                                        $r .= "<td $attributes><a href='mailto:$email'>$email</a></td>";
    424424                                        break;
    425425                                case 'role':
    426426                                        $r .= "<td $attributes>$role_name</td>";