From 15a9bcad35ae79f5ee701ea047907f8197cd5232 Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Fri, 23 Jun 2023 17:47:34 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@56004 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-comments-list-table.php | 5 ++- src/wp-admin/includes/class-wp-list-table.php | 33 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php index 49c3dc16ff..7d87ae9aab 100644 --- a/src/wp-admin/includes/class-wp-comments-list-table.php +++ b/src/wp-admin/includes/class-wp-comments-list-table.php @@ -583,7 +583,10 @@ class WP_Comments_List_Table extends WP_List_Table { ' . __( 'Ordered by Comment Date, descending.' ) . '

'; + echo '' . + /* translators: Hidden accessibility text. */ + __( 'Ordered by Comment Date, descending.' ) . + ''; } else { $this->print_table_description(); } diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 4dfb825996..c5463f40f6 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -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 = ' ' . $order_text . ''; @@ -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 '' . $orderby_text . ' ' . $order_text . '

'; + /* translators: Hidden accessibility text. */ + $asc_text = __( 'Ascending.' ); + /* translators: Hidden accessibility text. */ + $desc_text = __( 'Descending.' ); + $order_text = 'asc' === $current_order ? $asc_text : $desc_text; + echo '' . $orderby_text . ' ' . $order_text . ''; return; }