Make WordPress Core

Ticket #32170: 32170.5.patch

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

     
    369369         */
    370370        protected function get_sortable_columns() {
    371371                return array(
    372                         'author'   => 'comment_author',
    373                         'response' => 'comment_post_ID'
     372                        'author'   => array( 'comment_author', false, __( 'Author' ), __( 'Table ordered by Comment Author.' ) ),
     373                        'response' => array( 'comment_post_ID', false, _x( 'In Response To', 'column name' ), __( 'Table ordered by Post Replied To.' ) ),
    374374                );
    375375        }
    376376
     
    394394
    395395                $this->display_tablenav( 'top' );
    396396
     397                if ( ! isset( $_GET['orderby'] ) ) {
     398                        // In the initial view, Comments are ordered by comment's date but there's no column for that.
     399                        echo '<p id="table-description" class="screen-reader-text">' . __( 'Table ordered by Comment Date. Descending order.' ) . '</p>';
     400                } else {
     401                        $this->print_table_description();
     402                }
    397403?>
    398 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
     404<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" aria-describedby="table-description">
    399405        <thead>
    400406        <tr>
    401407                <?php $this->print_column_headers(); ?>
  • src/wp-admin/includes/class-wp-links-list-table.php

     
    132132         */
    133133        protected function get_sortable_columns() {
    134134                return array(
    135                         'name'    => 'name',
    136                         'url'     => 'url',
    137                         'visible' => 'visible',
    138                         'rating'  => 'rating'
     135                        'name'    => array( 'name', false, _x( 'Name', 'link name' ), __( 'Table ordered by Name.' ), 'asc' ),
     136                        'url'     => array( 'url', false, __( 'URL' ), __( 'Table ordered by URL.' ) ),
     137                        'visible' => array( 'visible', false, __( 'Visible' ), __( 'Table ordered by Visibility.' ) ),
     138                        'rating'  => array( 'rating', false, __( 'Rating' ), __( 'Table ordered by Rating.' ) ),
    139139                );
    140140        }
    141141
  • src/wp-admin/includes/class-wp-list-table.php

     
    810810         * Get a list of sortable columns. The format is:
    811811         * 'internal-name' => 'orderby'
    812812         * or
    813          * 'internal-name' => array( 'orderby', true )
     813         * 'internal-name' => array( 'orderby', bool, 'abbr', 'orderby-text', 'initially-sorted-column-order' )
    814814         *
    815          * The second format will make the initial sorting order be descending
     815         * In the second format, passing true as second parameter will make the initial
     816         * sorting order be descending. Following parameters add a short column name to
     817         * be used as 'abbr' attribute, a translatable string for the current sorting
     818         * and the initial order for the initial sorted column, 'asc' or 'desc' (default: false).
    816819         *
    817820         * @since 3.1.0
     821+        * @since 4.3.0 Added 'abbr', 'orderby-text' and 'initially-sorted-column-order'.
    818822         * @access protected
    819823         *
    820824         * @return array
     
    908912                                continue;
    909913
    910914                        $data = (array) $data;
    911                         if ( !isset( $data[1] ) )
    912                                 $data[1] = false;
     915                        // Descending initial sorting.
     916                        if ( ! isset( $data[1] ) ) {
     917                                $data[1] = false;
     918                        }
     919                        // Current sorting translatable string.
     920                        if ( ! isset( $data[2] ) ) {
     921                                $data[2] = '';
     922                        }
     923                        // Initial view sorted column and asc/desc order, default: false.
     924                        if ( ! isset( $data[3] ) ) {
     925                                $data[3] = false;
     926                        }
     927                        // Initial order for the initial sorted column, default: false.
     928                        if ( ! isset( $data[4] ) ) {
     929                                $data[4] = false;
     930                        }
    913931
    914932                        $sortable[$id] = $data;
    915933                }
     
    950968                $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    951969                $current_url = remove_query_arg( 'paged', $current_url );
    952970
    953                 if ( isset( $_GET['orderby'] ) )
    954                         $current_orderby = $_GET['orderby'];
    955                 else
    956                         $current_orderby = '';
     971                // When users click on a column header to sort by other columns.
     972                if ( isset( $_GET['orderby'] ) ) {
     973                        $current_orderby = $_GET['orderby'];
     974                // In the initial view there's no orderby parameter.
     975                } else {
     976                        $current_orderby = '';
     977                }
    957978
    958                 if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
     979                // Not in the initial view and descending order.
     980                if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
    959981                        $current_order = 'desc';
    960                 else
     982                } else {
     983                        // The initial view is not always 'asc' we'll take care of this below.
    961984                        $current_order = 'asc';
     985                }
    962986
    963987                if ( ! empty( $columns['cb'] ) ) {
    964988                        static $cb_counter = 1;
     
    970994                foreach ( $columns as $column_key => $column_display_name ) {
    971995                        $class = array( 'manage-column', "column-$column_key" );
    972996
     997                        $aria_sort_attr = $abbr_attr = $order_text = '';
     998
    973999                        if ( in_array( $column_key, $hidden ) ) {
    9741000                                $class[] = 'hidden';
    9751001                        }
     
    9841010                        }
    9851011
    9861012                        if ( isset( $sortable[$column_key] ) ) {
    987                                 list( $orderby, $desc_first ) = $sortable[$column_key];
     1013                                list( $orderby, $desc_first, $abbr, $orderby_text, $initial_order ) = $sortable[$column_key];
    9881014
     1015                                /*
     1016                                 * We're in the initial view and there's no $_GET['orderby'] then check if the
     1017                                 * initial sorting information is set in the sortable columns and use that.
     1018                                 */
     1019                                if ( '' === $current_orderby && $initial_order ) {
     1020                                        // Use the initially sorted column $orderby as current orderby.
     1021                                        $current_orderby = $orderby;
     1022                                        // Use the initially sorted column asc/desc order as initial order.
     1023                                        $current_order = $initial_order;
     1024                                }
     1025
     1026                                /*
     1027                                 * True in the initial view when an initial orderby is set via get_sortable_columns()
     1028                                 * and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
     1029                                 */
    9891030                                if ( $current_orderby == $orderby ) {
    990                                         $order = 'asc' == $current_order ? 'desc' : 'asc';
     1031                                        // The sorted column. The `aria-sort` attribute must be set only on the sorted column.
     1032                                        if ( 'asc' == $current_order ) {
     1033                                                $order = 'desc';
     1034                                                $aria_sort_attr = ' aria-sort="ascending"';
     1035                                                $order_text = __( 'Click to sort descending.' );
     1036                                        } else {
     1037                                                $order = 'asc';
     1038                                                $aria_sort_attr = ' aria-sort="descending"';
     1039                                                $order_text = __( 'Click to sort ascending.' );
     1040                                        }
    9911041                                        $class[] = 'sorted';
    9921042                                        $class[] = $current_order;
    9931043                                } else {
     1044                                        // The other sortable columns.
    9941045                                        $order = $desc_first ? 'desc' : 'asc';
    9951046                                        $class[] = 'sortable';
    9961047                                        $class[] = $desc_first ? 'asc' : 'desc';
     1048                                        $order_text = 'asc' === $order ? __( 'Sortable column. Click to sort ascending.' ) : __( 'Sortable column. Click to sort descending.' );
    9971049                                }
    9981050
    999                                 $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>';
    1000                         }
     1051                                // Print an 'abbr' attribute if a value is provided via get_sortable_columns().
     1052                                $abbr_attr = $abbr ? ' abbr="' . esc_attr( $abbr ) . '"' : '';
    10011053
     1054                                $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>';
     1055                        }
     1056
    10021057                        $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
    10031058                        $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
    10041059                        $id = $with_id ? "id='$column_key'" : '';
     
    10061061                        if ( !empty( $class ) )
    10071062                                $class = "class='" . join( ' ', $class ) . "'";
    10081063
    1009                         echo "<$tag $scope $id $class>$column_display_name</$tag>";
     1064                        echo "<$tag $scope $id $class $aria_sort_attr $abbr_attr>$column_display_name</$tag>";
    10101065                }
    10111066        }
    10121067
     1068        /**
     1069         * Print a table description with information about current sorting and order.
     1070         *
     1071         * For the table initial view, information about initial orderby and order
     1072         * should be provided via get_sortable_columns().
     1073         *
     1074         * @since 4.3.0
     1075         * @access public
     1076         */
     1077        public function print_table_description() {
     1078                list( $columns, $hidden, $sortable ) = $this->get_column_info();
     1079
     1080                if ( empty( $sortable ) ) {
     1081                        return;
     1082                }
     1083
     1084                // When users click on a column header to sort by other columns.
     1085                if ( isset( $_GET['orderby'] ) ) {
     1086                        $current_orderby = $_GET['orderby'];
     1087                // In the initial view there's no orderby parameter.
     1088                } else {
     1089                        $current_orderby = '';
     1090                }
     1091
     1092                // Not in the initial view and descending order.
     1093                if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
     1094                        $current_order = 'desc';
     1095                } else {
     1096                        // The initial view is not always 'asc' we'll take care of this below.
     1097                        $current_order = 'asc';
     1098                }
     1099
     1100                foreach ( array_keys( $columns ) as $column_key ) {
     1101
     1102                        if ( isset( $sortable[$column_key] ) ) {
     1103
     1104                                list( $orderby, $desc_first, $abbr, $orderby_text, $initial_order ) = $sortable[$column_key];
     1105
     1106                                if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
     1107                                        return;
     1108                                }
     1109                                /*
     1110                                 * We're in the initial view and there's no $_GET['orderby'] then check if the
     1111                                 * initial sorting information is set in the sortable columns and use that.
     1112                                 */
     1113                                if ( '' === $current_orderby && $initial_order ) {
     1114                                        // Use the initially sorted column $orderby as current orderby.
     1115                                        $current_orderby = $orderby;
     1116                                        // Use the initially sorted column asc/desc order as initial order.
     1117                                        $current_order = $initial_order;
     1118                                }
     1119
     1120                                /*
     1121                                 * True in the initial view when an initial orderby is set via get_sortable_columns()
     1122                                 * and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
     1123                                 */
     1124                                if ( $current_orderby == $orderby ) {
     1125                                        $order_text = 'asc' === $current_order ? __( 'Ascending order.' ) : __( 'Descending order.' );
     1126                                        echo '<p id="table-description" class="screen-reader-text">' . $orderby_text . ' ' . $order_text . '</p>';
     1127
     1128                                        return;
     1129                                }
     1130                        }
     1131                }
     1132        }
     1133
    10131134        /**
    10141135         * Display the table
    10151136         *
     
    10201141                $singular = $this->_args['singular'];
    10211142
    10221143                $this->display_tablenav( 'top' );
     1144
     1145                $this->print_table_description();
    10231146?>
    1024 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
     1147<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" aria-describedby="table-description">
    10251148        <thead>
    10261149        <tr>
    10271150                <?php $this->print_column_headers(); ?>
  • src/wp-admin/includes/class-wp-media-list-table.php

     
    302302         */
    303303        protected function get_sortable_columns() {
    304304                return array(
    305                         'title'    => 'title',
    306                         'author'   => 'author',
    307                         'parent'   => 'parent',
    308                         'comments' => 'comment_count',
    309                         'date'     => array( 'date', true ),
     305                        'title'    => array( 'title', false, _x( 'File', 'column name' ), __( 'Table ordered by File Name.' ) ),
     306                        'author'   => array( 'author', false, __( 'Author' ), __( 'Table ordered by Author.' ) ),
     307                        'parent'   => array( 'parent', false, _x( 'Uploaded to', 'column name' ), __( 'Table ordered by Uploaded To.' ) ),
     308                        'comments' => array( 'comment_count', __( 'Comments' ), false, __( 'Table ordered by Comments.' ) ),
     309                        'date'     => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ),
    310310                );
    311311        }
    312312
  • src/wp-admin/includes/class-wp-ms-sites-list-table.php

     
    223223         * @return array
    224224         */
    225225        protected function get_sortable_columns() {
     226
     227                if ( is_subdomain_install() ) {
     228                        $abbr = __( 'Domain' );
     229                        $blogname_orderby_text = __( 'Table ordered by Site Domain Name.' );
     230                } else {
     231                        $abbr = __( 'Path' );
     232                        $blogname_orderby_text = __( 'Table ordered by Site Path.' );
     233                }
     234
    226235                return array(
    227                         'blogname'    => 'blogname',
    228                         'lastupdated' => 'lastupdated',
    229                         'registered'  => 'blog_id',
     236                        'blogname'    => array( 'blogname', false, $abbr, $blogname_orderby_text ),
     237                        'lastupdated' => array( 'lastupdated', true, __( 'Last Updated' ), __( 'Table ordered by Last Updated.' ) ),
     238                        'registered'  => array( 'blog_id', true, _x( 'Registered', 'site' ), __( 'Table ordered by Site Registered Date.' ), 'desc' ),
    230239                );
    231240        }
    232241
  • src/wp-admin/includes/class-wp-ms-themes-list-table.php

     
    240240         */
    241241        protected function get_sortable_columns() {
    242242                return array(
    243                         'name'         => 'name',
     243                        'name' => array( 'name', false, __( 'Theme' ), __( 'Table ordered by Theme Name.' ), 'asc' ),
    244244                );
    245245        }
    246246
  • src/wp-admin/includes/class-wp-ms-users-list-table.php

     
    167167         */
    168168        protected function get_sortable_columns() {
    169169                return array(
    170                         'username'   => 'login',
    171                         'name'       => 'name',
    172                         'email'      => 'email',
    173                         'registered' => 'id',
     170                        'username'   => array( 'login', false, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ),
     171                        'name'       => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ),
     172                        'email'      => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ),
     173                        'registered' => array( 'id', false, _x( 'Registered', 'user' ), __( 'Table ordered by User Registered Date.' ) ),
    174174                );
    175175        }
    176176
  • src/wp-admin/includes/class-wp-posts-list-table.php

     
    468468         * @return array
    469469         */
    470470        protected function get_sortable_columns() {
    471                 return array(
    472                         'title'    => 'title',
    473                         'parent'   => 'parent',
    474                         'comments' => 'comment_count',
    475                         'date'     => array( 'date', true )
    476                 );
     471
     472                $post_type = $this->screen->post_type;
     473
     474                if ( 'page' === $post_type ) {
     475                        $title_orderby_text = isset( $_GET['orderby'] ) ? __( 'Table ordered by Title.' ) : __( 'Table ordered by Hierarchical Menu Order and Title.' );
     476                        $sortables = array(
     477                                'title'    => array( 'title', false, __( 'Title' ), $title_orderby_text, 'asc' ),
     478                                'parent'   => array( 'parent', false ),
     479                                'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
     480                                'date'     => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ) ),
     481                        );
     482                } else {
     483                        $sortables = array(
     484                                'title'    => array( 'title', false, __( 'Title' ), __( 'Table ordered by Title.' ) ),
     485                                'parent'   => array( 'parent', false ),
     486                                'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ),
     487                                'date'     => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ),
     488                        );
     489                }
     490                // Custom Post Types: there's a filter for that, see get_column_info().
     491
     492                return $sortables;
    477493        }
    478494
    479495        /**
  • src/wp-admin/includes/class-wp-terms-list-table.php

     
    185185         * @return array
    186186         */
    187187        protected function get_sortable_columns() {
     188
     189                $taxonomy = $this->screen->taxonomy;
     190
     191                if ( ! isset( $_GET['orderby'] ) && is_taxonomy_hierarchical( $taxonomy ) ) {
     192                        $name_orderby_text = __( 'Table ordered hierarchically.' );
     193                } else {
     194                        $name_orderby_text = __( 'Table ordered by Name.' );
     195                }
     196
    188197                return array(
    189                         'name'        => 'name',
    190                         'description' => 'description',
    191                         'slug'        => 'slug',
    192                         'posts'       => 'count',
    193                         'links'       => 'count'
     198                        'name'        => array( 'name', false, _x( 'Name', 'term name' ), $name_orderby_text, 'asc' ),
     199                        'description' => array( 'description', false, __( 'Description' ), __( 'Table ordered by Description.' ) ),
     200                        'slug'        => array( 'slug', false, __( 'Slug' ), __( 'Table ordered by Slug.' ) ),
     201                        'posts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ),
     202                        'links'       => array( 'count', false, __( 'Links' ), __( 'Table ordered by Links.' ) ),
    194203                );
    195204        }
    196205
  • src/wp-admin/includes/class-wp-users-list-table.php

     
    291291         */
    292292        protected function get_sortable_columns() {
    293293                $c = array(
    294                         'username' => 'login',
    295                         'name'     => 'name',
    296                         'email'    => 'email',
     294                        'username' => array( 'login', false, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ),
     295                        'name'     => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ),
     296                        'email'    => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ),
    297297                );
    298298
    299299                if ( $this->is_site_users )