Make WordPress Core

Ticket #32170: 32170.3.patch

File 32170.3.patch, 17.4 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, __( 'Author' ), __( 'Table ordered by Comment Author.' ) ),
     322                        'response' => array( 'comment_post_ID', false, _x( 'In Response To', 'column name' ), __( '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" class="screen-reader-text">' . __( '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, _x( 'Name', 'link name' ), __( 'Table ordered by Name.' ), 'asc' ),
     105                        'url'     => array( 'url', false, __( 'URL' ), __( 'Table ordered by URL.' ) ),
     106                        'visible' => array( 'visible', false, __( 'Visible' ), __( 'Table ordered by Visibility.' ) ),
     107                        'rating'  => array( 'rating', false, __( 'Rating' ), __( 'Table ordered by Rating.' ) ),
    108108                );
    109109        }
    110110
  • src/wp-admin/includes/class-wp-list-table.php

     
    778778         * Get a list of sortable columns. The format is:
    779779         * 'internal-name' => 'orderby'
    780780         * or
    781          * 'internal-name' => array( 'orderby', true )
     781         * 'internal-name' => array( 'orderby', bool, 'abbr', 'orderby-text', 'initially-sorted-column-order' )
    782782         *
    783          * The second format will make the initial sorting order be descending
     783         * In the second format, passing true as second parameter will make the initial
     784         * sorting order be descending. Following parameters add a short column name to
     785         * be used as 'abbr' attribute, a translatable string for the current sorting
     786         * and the initial order for the initial sorted column, 'asc' or 'desc'.
    784787         *
    785788         * @since 3.1.0
     789         * @since 4.3.0 Added 'abbr', 'orderby-text' and 'initially-sorted-column-order'.
    786790         * @access protected
    787791         *
    788792         * @return array
     
    825829                                continue;
    826830
    827831                        $data = (array) $data;
    828                         if ( !isset( $data[1] ) )
     832
     833                        // Descending initial sorting.
     834                        if ( ! isset( $data[1] ) )
    829835                                $data[1] = false;
     836                        // Current sorting translatable string.
     837                        if ( ! isset( $data[2] ) )
     838                                $data[2] = '';
     839                        // Initial view sorted column and asc/desc order.
     840                        if ( ! isset( $data[3] ) )
     841                                $data[3] = false;
    830842
    831843                        $sortable[$id] = $data;
    832844                }
     
    864876                $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    865877                $current_url = remove_query_arg( 'paged', $current_url );
    866878
    867                 if ( isset( $_GET['orderby'] ) )
     879                // When users click on a column header to sort by other columns.
     880                if ( isset( $_GET['orderby'] ) ) {
    868881                        $current_orderby = $_GET['orderby'];
    869                 else
     882                // In the initial view there's no orderby parameter.
     883                } else {
    870884                        $current_orderby = '';
     885                }
    871886
    872                 if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
     887                // Not in the initial view and descending order.
     888                if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
    873889                        $current_order = 'desc';
    874                 else
     890                } else {
     891                        // The initial view is not always 'asc' we'll take care of this below.
    875892                        $current_order = 'asc';
     893                }
    876894
    877895                if ( ! empty( $columns['cb'] ) ) {
    878896                        static $cb_counter = 1;
     
    884902                foreach ( $columns as $column_key => $column_display_name ) {
    885903                        $class = array( 'manage-column', "column-$column_key" );
    886904
    887                         $style = '';
    888                         if ( in_array( $column_key, $hidden ) )
    889                                 $style = 'display:none;';
     905                        $style = $aria_sort_attr = $abbr_attr = $order_text = '';
    890906
    891                         $style = ' style="' . $style . '"';
     907                        if ( in_array( $column_key, $hidden ) ) {
     908                                $style = ' style="display:none;"';
     909                        }
    892910
    893911                        if ( 'cb' == $column_key )
    894912                                $class[] = 'check-column';
     
    896914                                $class[] = 'num';
    897915
    898916                        if ( isset( $sortable[$column_key] ) ) {
    899                                 list( $orderby, $desc_first ) = $sortable[$column_key];
     917                                list( $orderby, $desc_first, $abbr, $orderby_text, $initial_order ) = $sortable[$column_key];
    900918
     919                                /*
     920                                 * We're in the initial view and there's no $_GET['orderby'] then check if the
     921                                 * initial sorting information is set in the sortable columns and use that.
     922                                 */
     923                                if ( '' === $current_orderby && $initial_order ) {
     924                                        // Use the initially sorted column $orderby as current orderby.
     925                                        $current_orderby = $orderby;
     926                                        // Use the initially sorted column asc/desc order as initial order.
     927                                        $current_order = $initial_order;
     928                                }
     929
     930                                /*
     931                                 * True in the initial view when an initial orderby is set via get_sortable_columns()
     932                                 * and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
     933                                 */
    901934                                if ( $current_orderby == $orderby ) {
    902                                         $order = 'asc' == $current_order ? 'desc' : 'asc';
     935                                        // The sorted column. The `aria-sort` attribute must be set only on the sorted column.
     936                                        if ( 'asc' == $current_order ) {
     937                                                $order = 'desc';
     938                                                $aria_sort_attr = ' aria-sort="ascending"';
     939                                                $order_text = __( 'Click to sort descending.' );
     940                                        } else {
     941                                                $order = 'asc';
     942                                                $aria_sort_attr = ' aria-sort="descending"';
     943                                                $order_text = __( 'Click to sort ascending.' );
     944                                        }
    903945                                        $class[] = 'sorted';
    904946                                        $class[] = $current_order;
    905947                                } else {
     948                                        // The other sortable columns.
    906949                                        $order = $desc_first ? 'desc' : 'asc';
    907950                                        $class[] = 'sortable';
    908951                                        $class[] = $desc_first ? 'asc' : 'desc';
     952                                        $order_text = 'asc' === $order ? __( 'Sortable column. Click to sort ascending.' ) : __( 'Sortable column. Click to sort descending.' );
    909953                                }
    910954
    911                                 $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>';
     955                                // Print an 'abbr' attribute if a value is provided via get_sortable_columns().
     956                                $abbr_attr = $abbr ? ' abbr="' . esc_attr( $abbr ) . '"' : '';
     957
     958                                $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> <span class="screen-reader-text">' . $order_text . '</span></a>';
    912959                        }
    913960
    914                         $id = $with_id ? "id='$column_key'" : '';
     961                        $id = $with_id ? " id='$column_key'" : '';
    915962
    916963                        if ( !empty( $class ) )
    917                                 $class = "class='" . join( ' ', $class ) . "'";
     964                                $class = " class='" . join( ' ', $class ) . "'";
    918965
    919                         echo "<th scope='col' $id $class $style>$column_display_name</th>";
     966                        echo "<th scope='col'$id$class$style$aria_sort_attr$abbr_attr>$column_display_name</th>";
    920967                }
    921968        }
    922969
    923970        /**
     971         * Print a table description with information about current sorting and order.
     972         *
     973         * For the table initial view, information about initial orderby and order
     974         * should be provided via get_sortable_columns().
     975         *
     976         * @since 4.3.0
     977         * @access public
     978         */
     979        public function print_table_description() {
     980                list( $columns, $hidden, $sortable ) = $this->get_column_info();
     981
     982                if ( empty( $sortable ) ) {
     983                        return;
     984                }
     985
     986                // When users click on a column header to sort by other columns.
     987                if ( isset( $_GET['orderby'] ) ) {
     988                        $current_orderby = $_GET['orderby'];
     989                // In the initial view there's no orderby parameter.
     990                } else {
     991                        $current_orderby = '';
     992                }
     993
     994                // Not in the initial view and descending order.
     995                if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
     996                        $current_order = 'desc';
     997                } else {
     998                        // The initial view is not always 'asc' we'll take care of this below.
     999                        $current_order = 'asc';
     1000                }
     1001
     1002                foreach ( array_keys( $columns ) as $column_key ) {
     1003
     1004                        if ( isset( $sortable[$column_key] ) ) {
     1005
     1006                                list( $orderby, $desc_first, $abbr, $orderby_text, $initial_order ) = $sortable[$column_key];
     1007
     1008                                if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
     1009                                        return;
     1010                                }
     1011                                /*
     1012                                 * We're in the initial view and there's no $_GET['orderby'] then check if the
     1013                                 * initial sorting information is set in the sortable columns and use that.
     1014                                 */
     1015                                if ( '' === $current_orderby && $initial_order ) {
     1016                                        // Use the initially sorted column $orderby as current orderby.
     1017                                        $current_orderby = $orderby;
     1018                                        // Use the initially sorted column asc/desc order as initial order.
     1019                                        $current_order = $initial_order;
     1020                                }
     1021
     1022                                /*
     1023                                 * True in the initial view when an initial orderby is set via get_sortable_columns()
     1024                                 * and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
     1025                                 */
     1026                                if ( $current_orderby == $orderby ) {
     1027                                        $order_text = 'asc' === $current_order ? __( 'Ascending order.' ) : __( 'Descending order.' );
     1028                                        echo '<p id="table-description" class="screen-reader-text">' . $orderby_text . ' ' . $order_text . '</p>';
     1029
     1030                                        return;
     1031                                }
     1032                        }
     1033                }
     1034        }
     1035
     1036        /**
    9241037         * Display the table
    9251038         *
    9261039         * @since 3.1.0
     
    9311044
    9321045                $this->display_tablenav( 'top' );
    9331046
     1047                $this->print_table_description();
    9341048?>
    935 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
     1049<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" aria-describedby="table-description">
    9361050        <thead>
    9371051        <tr>
    9381052                <?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, _x( 'File', 'column name' ), __( 'Table ordered by File Name.' ) ),
     266                        'author'   => array( 'author', false, __( 'Author' ), __( 'Table ordered by Author.' ) ),
     267                        'parent'   => array( 'parent', false, _x( 'Uploaded to', 'column name' ), __( 'Table ordered by Uploaded To.' ) ),
     268                        'comments' => array( 'comment_count', __( 'Comments' ), false, __( 'Table ordered by Comments.' ) ),
     269                        'date'     => array( 'date', true, __( 'Date' ), __( '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                if ( is_subdomain_install() ) {
     189                        $abbr = __( 'Domain' );
     190                        $blogname_orderby_text = __( 'Table ordered by Site Domain Name.' );
     191                } else {
     192                        $abbr = __( 'Path' );
     193                        $blogname_orderby_text = __( 'Table ordered by Site Path.' )
     194                }
    188195                return array(
    189                         'blogname'    => 'blogname',
    190                         'lastupdated' => 'lastupdated',
    191                         'registered'  => 'blog_id',
     196                        'blogname'    => array( 'blogname', false, $abbr, $blogname_orderby_text ),
     197                        'lastupdated' => array( 'lastupdated', true, __( 'Last Updated' ), __( 'Table ordered by Last Updated.' ) ),
     198                        'registered'  => array( 'blog_id', true, _x( 'Registered', 'site' ), __( 'Table ordered by Site Registered Date.' ), 'desc' ),
    192199                );
    193200        }
    194201
  • 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, __( 'Theme' ), __( '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, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ),
     143                        'name'       => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ),
     144                        'email'      => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ),
     145                        'registered' => array( 'id', false, _x( 'Registered', 'user' ), __( 'Table ordered by User 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' ), $title_orderby_text, 'asc' ),
     427                                'parent'   => array( 'parent', false ),
     428                                'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
     429                                'date'     => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ) ),
     430                        );
     431                } else {
     432                        $sortables = array(
     433                                'title'    => array( 'title', false, __( 'Title' ), __( 'Table ordered by Title.' ) ),
     434                                'parent'   => array( 'parent', false ),
     435                                'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
     436                                'date'     => array( 'date', true, __( 'Date' ), __( '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, _x( 'Name', 'term name' ), $name_orderby_text, 'asc' ),
     164                        'description' => array( 'description', false, __( 'Description' ), __( 'Table ordered by Description.' ) ),
     165                        'slug'        => array( 'slug', false, __( 'Slug' ), __( 'Table ordered by Slug.' ) ),
     166                        'posts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ),
     167                        'links'       => array( 'count', false, __( 'Links' ), __( 'Table ordered by Links.' ) ),
    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, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ),
     286                        'name'     => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ),
     287                        'email'    => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ),
    288288                );
    289289
    290290                if ( $this->is_site_users )