Administration: Backwards compatibility for new sortable keys.

Replace use of `list` to parse array keys into variables. `list` throws errors if the keys don't exist, and many extenders will not define the new array keys. The code path already falls back effectively for empty values.

Also add translator comments to screen reader hidden text, fix a docblock, and fix an HTML error.

Follow up to [r55971].

Props kebbet, chouby, joedolson.
Fixes #32170.
Built from https://develop.svn.wordpress.org/trunk@56004


git-svn-id: http://core.svn.wordpress.org/trunk@55516 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2023-06-23 17:49:28 +00:00
parent 72fda0359f
commit d1717e60b9
3 changed files with 29 additions and 11 deletions

View File

@ -583,7 +583,10 @@ class WP_Comments_List_Table extends WP_List_Table {
<?php
if ( ! isset( $_GET['orderby'] ) ) {
// In the initial view, Comments are ordered by comment's date but there's no column for that.
echo '<caption class="screen-reader-text">' . __( 'Ordered by Comment Date, descending.' ) . '</p>';
echo '<caption class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Ordered by Comment Date, descending.' ) .
'</caption>';
} else {
$this->print_table_description();
}

View File

@ -1361,7 +1361,11 @@ class WP_List_Table {
}
if ( isset( $sortable[ $column_key ] ) ) {
list( $orderby, $desc_first, $abbr, $orderby_text, $initial_order ) = $sortable[ $column_key ];
$orderby = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
$desc_first = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
$abbr = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
$orderby_text = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
$initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
/*
* We're in the initial view and there's no $_GET['orderby'] then check if the
@ -1397,9 +1401,13 @@ class WP_List_Table {
$order = $desc_first ? 'desc' : 'asc';
}
$class[] = 'sortable';
$class[] = 'desc' === $order ? 'asc' : 'desc';
$order_text = 'asc' === $order ? __( 'Sort ascending.' ) : __( 'Sort descending.' );
$class[] = 'sortable';
$class[] = 'desc' === $order ? 'asc' : 'desc';
/* translators: Hidden accessibility text. */
$asc_text = __( 'Sort ascending.' );
/* translators: Hidden accessibility text. */
$desc_text = __( 'Sort descending.' );
$order_text = 'asc' === $order ? $asc_text : $desc_text;
}
if ( '' !== $order_text ) {
$order_text = ' <span class="screen-reader-text">' . $order_text . '</span>';
@ -1428,7 +1436,7 @@ class WP_List_Table {
* For the table initial view, information about initial orderby and order
* should be provided via get_sortable_columns().
*
* @since 4.3.0
* @since 6.3.0
* @access public
*/
public function print_table_description() {
@ -1457,8 +1465,11 @@ class WP_List_Table {
foreach ( array_keys( $columns ) as $column_key ) {
if ( isset( $sortable[ $column_key ] ) ) {
list( $orderby, $desc_first, $abbr, $orderby_text, $initial_order ) = $sortable[ $column_key ];
$orderby = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
$desc_first = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
$abbr = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
$orderby_text = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
$initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
return;
@ -1479,8 +1490,12 @@ class WP_List_Table {
* and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
*/
if ( $current_orderby == $orderby ) {
$order_text = 'asc' === $current_order ? __( 'Ascending.' ) : __( 'Descending.' );
echo '<caption class="screen-reader-text">' . $orderby_text . ' ' . $order_text . '</p>';
/* translators: Hidden accessibility text. */
$asc_text = __( 'Ascending.' );
/* translators: Hidden accessibility text. */
$desc_text = __( 'Descending.' );
$order_text = 'asc' === $current_order ? $asc_text : $desc_text;
echo '<caption class="screen-reader-text">' . $orderby_text . ' ' . $order_text . '</caption>';
return;
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-56003';
$wp_version = '6.3-alpha-56004';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.