rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -173,7 +173,7 @@ class WP_List_Table {
}
/**
* Make private properties readable for backward compatibility.
* Makes private properties readable for backward compatibility.
*
* @since 4.0.0
*
@@ -187,7 +187,7 @@ class WP_List_Table {
}
/**
* Make private properties settable for backward compatibility.
* Makes private properties settable for backward compatibility.
*
* @since 4.0.0
*
@@ -202,7 +202,7 @@ class WP_List_Table {
}
/**
* Make private properties checkable for backward compatibility.
* Makes private properties checkable for backward compatibility.
*
* @since 4.0.0
*
@@ -218,7 +218,7 @@ class WP_List_Table {
}
/**
* Make private properties un-settable for backward compatibility.
* Makes private properties un-settable for backward compatibility.
*
* @since 4.0.0
*
@@ -231,7 +231,7 @@ class WP_List_Table {
}
/**
* Make private/protected methods readable for backward compatibility.
* Makes private/protected methods readable for backward compatibility.
*
* @since 4.0.0
*
@@ -269,7 +269,7 @@ class WP_List_Table {
}
/**
* An internal method that sets all the necessary pagination arguments
* Sets all the necessary pagination arguments.
*
* @since 3.1.0
*
@@ -320,7 +320,7 @@ class WP_List_Table {
}
/**
* Whether the table has items to display or not
* Determines whether the table has items to display or not
*
* @since 3.1.0
*
@@ -698,13 +698,11 @@ class WP_List_Table {
$months = $wpdb->get_results(
$wpdb->prepare(
"
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
FROM $wpdb->posts
WHERE post_type = %s
$extra_checks
ORDER BY post_date DESC
",
"SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
FROM $wpdb->posts
WHERE post_type = %s
$extra_checks
ORDER BY post_date DESC",
$post_type
)
);
@@ -775,7 +773,9 @@ class WP_List_Table {
}
printf(
"<a href='%s' class='%s' id='view-switch-$mode'$aria_current><span class='screen-reader-text'>%s</span></a>\n",
"<a href='%s' class='%s' id='view-switch-$mode'$aria_current>" .
"<span class='screen-reader-text'>%s</span>" .
"</a>\n",
esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ),
implode( ' ', $classes ),
$title
@@ -821,20 +821,27 @@ class WP_List_Table {
if ( ! $approved_comments && ! $pending_comments ) {
// No comments at all.
printf(
'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
'<span aria-hidden="true">&#8212;</span>' .
'<span class="screen-reader-text">%s</span>',
__( 'No comments' )
);
} elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) {
// Don't link the comment bubble for a trashed post.
printf(
'<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
'<span class="post-com-count post-com-count-approved">' .
'<span class="comment-count-approved" aria-hidden="true">%s</span>' .
'<span class="screen-reader-text">%s</span>' .
'</span>',
$approved_comments_number,
$pending_comments ? $approved_phrase : $approved_only_phrase
);
} elseif ( $approved_comments ) {
// Link the comment bubble to approved comments.
printf(
'<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
'<a href="%s" class="post-com-count post-com-count-approved">' .
'<span class="comment-count-approved" aria-hidden="true">%s</span>' .
'<span class="screen-reader-text">%s</span>' .
'</a>',
esc_url(
add_query_arg(
array(
@@ -850,7 +857,10 @@ class WP_List_Table {
} else {
// Don't link the comment bubble when there are no approved comments.
printf(
'<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
'<span class="post-com-count post-com-count-no-comments">' .
'<span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span>' .
'<span class="screen-reader-text">%s</span>' .
'</span>',
$approved_comments_number,
$pending_comments ?
/* translators: Hidden accessibility text. */
@@ -862,7 +872,10 @@ class WP_List_Table {
if ( $pending_comments ) {
printf(
'<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
'<a href="%s" class="post-com-count post-com-count-pending">' .
'<span class="comment-count-pending" aria-hidden="true">%s</span>' .
'<span class="screen-reader-text">%s</span>' .
'</a>',
esc_url(
add_query_arg(
array(
@@ -877,7 +890,10 @@ class WP_List_Table {
);
} else {
printf(
'<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
'<span class="post-com-count post-com-count-pending post-com-count-no-pending">' .
'<span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span>' .
'<span class="screen-reader-text">%s</span>' .
'</span>',
$pending_comments_number,
$approved_comments ?
/* translators: Hidden accessibility text. */
@@ -1006,7 +1022,10 @@ class WP_List_Table {
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
"<a class='first-page button' href='%s'>" .
"<span class='screen-reader-text'>%s</span>" .
"<span aria-hidden='true'>%s</span>" .
'</a>',
esc_url( remove_query_arg( 'paged', $current_url ) ),
/* translators: Hidden accessibility text. */
__( 'First page' ),
@@ -1018,7 +1037,10 @@ class WP_List_Table {
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
"<a class='prev-page button' href='%s'>" .
"<span class='screen-reader-text'>%s</span>" .
"<span aria-hidden='true'>%s</span>" .
'</a>',
esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
/* translators: Hidden accessibility text. */
__( 'Previous page' ),
@@ -1028,23 +1050,29 @@ class WP_List_Table {
if ( 'bottom' === $which ) {
$html_current_page = $current;
$total_pages_before = '<span class="screen-reader-text">' .
$total_pages_before = sprintf(
'<span class="screen-reader-text">%s</span>' .
'<span id="table-paging" class="paging-input">' .
'<span class="tablenav-paging-text">',
/* translators: Hidden accessibility text. */
__( 'Current Page' ) .
'</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
__( 'Current Page' )
);
} else {
$html_current_page = sprintf(
"%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
'<label for="current-page-selector" class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Current Page' ) .
'</label>',
'<label for="current-page-selector" class="screen-reader-text">%s</label>' .
"<input class='current-page' id='current-page-selector' type='text'
name='paged' value='%s' size='%d' aria-describedby='table-paging' />" .
"<span class='tablenav-paging-text'>",
/* translators: Hidden accessibility text. */
__( 'Current Page' ),
$current,
strlen( $total_pages )
);
}
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
$page_links[] = $total_pages_before . sprintf(
$page_links[] = $total_pages_before . sprintf(
/* translators: 1: Current page, 2: Total pages. */
_x( '%1$s of %2$s', 'paging' ),
$html_current_page,
@@ -1055,7 +1083,10 @@ class WP_List_Table {
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
"<a class='next-page button' href='%s'>" .
"<span class='screen-reader-text'>%s</span>" .
"<span aria-hidden='true'>%s</span>" .
'</a>',
esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
/* translators: Hidden accessibility text. */
__( 'Next page' ),
@@ -1067,7 +1098,10 @@ class WP_List_Table {
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
"<a class='last-page button' href='%s'>" .
"<span class='screen-reader-text'>%s</span>" .
"<span aria-hidden='true'>%s</span>" .
'</a>',
esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
/* translators: Hidden accessibility text. */
__( 'Last page' ),
@@ -1111,10 +1145,17 @@ class WP_List_Table {
*
* The format is:
* - `'internal-name' => 'orderby'`
* - `'internal-name' => array( 'orderby', bool, 'abbr', 'orderby-text', 'initially-sorted-column-order' )` -
* - `'internal-name' => array( 'orderby', 'asc' )` - The second element sets the initial sorting order.
* - `'internal-name' => array( 'orderby', true )` - The second element makes the initial order descending.
*
* In the second format, passing true as second parameter will make the initial
* sorting order be descending. Following parameters add a short column name to
* be used as 'abbr' attribute, a translatable string for the current sorting,
* and the initial order for the initial sorted column, 'asc' or 'desc' (default: false).
*
* @since 3.1.0
* @since 6.3.0 Added 'abbr', 'orderby-text' and 'initially-sorted-column-order'.
*
* @return array
*/
@@ -1137,8 +1178,10 @@ class WP_List_Table {
return $column;
}
// We need a primary defined so responsive views show something,
// so let's fall back to the first non-checkbox column.
/*
* We need a primary defined so responsive views show something,
* so let's fall back to the first non-checkbox column.
*/
foreach ( $columns as $col => $column_name ) {
if ( 'cb' === $col ) {
continue;
@@ -1152,6 +1195,8 @@ class WP_List_Table {
}
/**
* Gets the name of the primary column.
*
* Public wrapper for WP_List_Table::get_default_primary_column_name().
*
* @since 4.4.0
@@ -1173,8 +1218,10 @@ class WP_List_Table {
$columns = get_column_headers( $this->screen );
$default = $this->get_default_primary_column_name();
// If the primary column doesn't exist,
// fall back to the first non-checkbox column.
/*
* If the primary column doesn't exist,
* fall back to the first non-checkbox column.
*/
if ( ! isset( $columns[ $default ] ) ) {
$default = self::get_default_primary_column_name();
}
@@ -1253,9 +1300,22 @@ class WP_List_Table {
}
$data = (array) $data;
// Descending initial sorting.
if ( ! isset( $data[1] ) ) {
$data[1] = false;
}
// Current sorting translatable string.
if ( ! isset( $data[2] ) ) {
$data[2] = '';
}
// Initial view sorted column and asc/desc order, default: false.
if ( ! isset( $data[3] ) ) {
$data[3] = false;
}
// Initial order for the initial sorted column, default: false.
if ( ! isset( $data[4] ) ) {
$data[4] = false;
}
$sortable[ $id ] = $data;
}
@@ -1292,30 +1352,39 @@ class WP_List_Table {
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$current_url = remove_query_arg( 'paged', $current_url );
// When users click on a column header to sort by other columns.
if ( isset( $_GET['orderby'] ) ) {
$current_orderby = $_GET['orderby'];
// In the initial view there's no orderby parameter.
} else {
$current_orderby = '';
}
// Not in the initial view and descending order.
if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
$current_order = 'desc';
} else {
// The initial view is not always 'asc', we'll take care of this below.
$current_order = 'asc';
}
if ( ! empty( $columns['cb'] ) ) {
static $cb_counter = 1;
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' .
$columns['cb'] = '<label class="label-covers-full-cell" for="cb-select-all-' . $cb_counter . '">' .
'<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Select All' ) .
'</span>' .
'</label>' .
'<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
$cb_counter++;
}
foreach ( $columns as $column_key => $column_display_name ) {
$class = array( 'manage-column', "column-$column_key" );
$class = array( 'manage-column', "column-$column_key" );
$aria_sort_attr = '';
$abbr_attr = '';
$order_text = '';
if ( in_array( $column_key, $hidden, true ) ) {
$class[] = 'hidden';
@@ -1332,14 +1401,41 @@ class WP_List_Table {
}
if ( isset( $sortable[ $column_key ] ) ) {
list( $orderby, $desc_first ) = $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
* initial sorting information is set in the sortable columns and use that.
*/
if ( '' === $current_orderby && $initial_order ) {
// Use the initially sorted column $orderby as current orderby.
$current_orderby = $orderby;
// Use the initially sorted column asc/desc order as initial order.
$current_order = $initial_order;
}
/*
* True in the initial view when an initial orderby is set via get_sortable_columns()
* and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
*/
if ( $current_orderby === $orderby ) {
$order = 'asc' === $current_order ? 'desc' : 'asc';
// The sorted column. The `aria-sort` attribute must be set only on the sorted column.
if ( 'asc' === $current_order ) {
$order = 'desc';
$aria_sort_attr = ' aria-sort="ascending"';
} else {
$order = 'asc';
$aria_sort_attr = ' aria-sort="descending"';
}
$class[] = 'sorted';
$class[] = $current_order;
} else {
// The other sortable columns.
$order = strtolower( $desc_first );
if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
@@ -1348,12 +1444,33 @@ class WP_List_Table {
$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>';
}
// Print an 'abbr' attribute if a value is provided via get_sortable_columns().
$abbr_attr = $abbr ? ' abbr="' . esc_attr( $abbr ) . '"' : '';
$column_display_name = sprintf(
'<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
'<a href="%1$s">' .
'<span>%2$s</span>' .
'<span class="sorting-indicators">' .
'<span class="sorting-indicator asc" aria-hidden="true"></span>' .
'<span class="sorting-indicator desc" aria-hidden="true"></span>' .
'</span>' .
'%3$s' .
'</a>',
esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
$column_display_name
$column_display_name,
$order_text
);
}
@@ -1365,7 +1482,80 @@ class WP_List_Table {
$class = "class='" . implode( ' ', $class ) . "'";
}
echo "<$tag $scope $id $class>$column_display_name</$tag>";
echo "<$tag $scope $id $class $aria_sort_attr $abbr_attr>$column_display_name</$tag>";
}
}
/**
* Print a table description with information about current sorting and order.
*
* For the table initial view, information about initial orderby and order
* should be provided via get_sortable_columns().
*
* @since 6.3.0
* @access public
*/
public function print_table_description() {
list( $columns, $hidden, $sortable ) = $this->get_column_info();
if ( empty( $sortable ) ) {
return;
}
// When users click on a column header to sort by other columns.
if ( isset( $_GET['orderby'] ) ) {
$current_orderby = $_GET['orderby'];
// In the initial view there's no orderby parameter.
} else {
$current_orderby = '';
}
// Not in the initial view and descending order.
if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
$current_order = 'desc';
} else {
// The initial view is not always 'asc', we'll take care of this below.
$current_order = 'asc';
}
foreach ( array_keys( $columns ) as $column_key ) {
if ( isset( $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;
}
/*
* We're in the initial view and there's no $_GET['orderby'] then check if the
* initial sorting information is set in the sortable columns and use that.
*/
if ( '' === $current_orderby && $initial_order ) {
// Use the initially sorted column $orderby as current orderby.
$current_orderby = $orderby;
// Use the initially sorted column asc/desc order as initial order.
$current_order = $initial_order;
}
/*
* True in the initial view when an initial orderby is set via get_sortable_columns()
* and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
*/
if ( $current_orderby === $orderby ) {
/* 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;
}
}
}
}
@@ -1382,6 +1572,7 @@ class WP_List_Table {
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<?php $this->print_table_description(); ?>
<thead>
<tr>
<?php $this->print_column_headers(); ?>
@@ -1453,7 +1644,7 @@ class WP_List_Table {
}
/**
* Extra controls to be displayed between bulk actions and pagination.
* Displays extra controls between bulk actions and pagination.
*
* @since 3.1.0
*
@@ -1531,8 +1722,10 @@ class WP_List_Table {
$classes .= ' hidden';
}
// Comments column uses HTML in the display name with screen reader text.
// Strip tags to get closer to a user-friendly string.
/*
* Comments column uses HTML in the display name with screen reader text.
* Strip tags to get closer to a user-friendly string.
*/
$data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"';
$attributes = "class='$classes' $data";