';
+
+ $i = 0;
+
foreach ( $actions as $action => $link ) {
++$i;
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
- $out .= "$link$sep";
+
+ $sep = ( $i < $action_count ) ? ' | ' : '';
+
+ $out .= "$link$sep";
}
+
$out .= '
';
$out .= '
modes as $mode => $title ) {
- $classes = array( 'view-' . $mode );
+ $classes = array( 'view-' . $mode );
+ $aria_current = '';
+
if ( $current_mode === $mode ) {
- $classes[] = 'current';
+ $classes[] = 'current';
+ $aria_current = ' aria-current="page"';
}
+
printf(
- "
%s\n",
- esc_url( add_query_arg( 'mode', $mode ) ),
+ "
%s\n",
+ esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ),
implode( ' ', $classes ),
$title
);
@@ -648,7 +667,7 @@
}
/**
- * Display a comment count bubble
+ * Displays a comment count bubble.
*
* @since 3.1.0
*
@@ -661,18 +680,39 @@
$approved_comments_number = number_format_i18n( $approved_comments );
$pending_comments_number = number_format_i18n( $pending_comments );
- $approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number );
- $approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
- $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
+ $approved_only_phrase = sprintf(
+ /* translators: %s: Number of comments. */
+ _n( '%s comment', '%s comments', $approved_comments ),
+ $approved_comments_number
+ );
- // No comments at all.
+ $approved_phrase = sprintf(
+ /* translators: %s: Number of comments. */
+ _n( '%s approved comment', '%s approved comments', $approved_comments ),
+ $approved_comments_number
+ );
+
+ $pending_phrase = sprintf(
+ /* translators: %s: Number of comments. */
+ _n( '%s pending comment', '%s pending comments', $pending_comments ),
+ $pending_comments_number
+ );
+
if ( ! $approved_comments && ! $pending_comments ) {
+ // No comments at all.
printf(
'
—%s',
__( 'No comments' )
);
- // Approved comments have different display depending on some conditions.
+ } elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) {
+ // Don't link the comment bubble for a trashed post.
+ printf(
+ '
%s',
+ $approved_comments_number,
+ $pending_comments ? $approved_phrase : $approved_only_phrase
+ );
} elseif ( $approved_comments ) {
+ // Link the comment bubble to approved comments.
printf(
'
%s',
esc_url(
@@ -688,6 +728,7 @@
$pending_comments ? $approved_phrase : $approved_only_phrase
);
} else {
+ // Don't link the comment bubble when there are no approved comments.
printf(
'',
$approved_comments_number,
@@ -720,7 +761,7 @@
}
/**
- * Get the current page number
+ * Gets the current page number.
*
* @since 3.1.0
*
@@ -737,7 +778,7 @@
}
/**
- * Get number of items to display on a single page
+ * Gets the number of items to display on a single page.
*
* @since 3.1.0
*
@@ -754,11 +795,22 @@
/**
* Filters the number of items to be displayed on each page of the list table.
*
- * The dynamic hook name, $option, refers to the `per_page` option depending
- * on the type of list table in use. Possible values include: 'edit_comments_per_page',
- * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
- * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
- * 'edit_{$post_type}_per_page', etc.
+ * The dynamic hook name, `$option`, refers to the `per_page` option depending
+ * on the type of list table in use. Possible filter names include:
+ *
+ * - `edit_comments_per_page`
+ * - `sites_network_per_page`
+ * - `site_themes_network_per_page`
+ * - `themes_network_per_page'`
+ * - `users_network_per_page`
+ * - `edit_post_per_page`
+ * - `edit_page_per_page'`
+ * - `edit_{$post_type}_per_page`
+ * - `edit_post_tag_per_page`
+ * - `edit_category_per_page`
+ * - `edit_{$taxonomy}_per_page`
+ * - `site_users_network_per_page`
+ * - `users_per_page`
*
* @since 2.9.0
*
@@ -768,7 +820,7 @@
}
/**
- * Display the pagination.
+ * Displays the pagination.
*
* @since 3.1.0
*
@@ -790,7 +842,11 @@
$this->screen->render_screen_reader_content( 'heading_pagination' );
}
- $output = '
' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '';
+ $output = '
' . sprintf(
+ /* translators: %s: Number of items. */
+ _n( '%s item', '%s items', $total_items ),
+ number_format_i18n( $total_items )
+ ) . '';
$current = $this->get_pagenum();
$removable_query_args = wp_removable_query_args();
@@ -804,20 +860,23 @@
$total_pages_before = '
';
$total_pages_after = '';
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
+ $disable_first = false;
+ $disable_last = false;
+ $disable_prev = false;
+ $disable_next = false;
- if ( $current == 1 ) {
+ if ( 1 == $current ) {
$disable_first = true;
$disable_prev = true;
}
- if ( $current == 2 ) {
+ if ( 2 == $current ) {
$disable_first = true;
}
- if ( $current == $total_pages ) {
+ if ( $total_pages == $current ) {
$disable_last = true;
$disable_next = true;
}
- if ( $current == $total_pages - 1 ) {
+ if ( $total_pages - 1 == $current ) {
$disable_last = true;
}
@@ -855,7 +914,12 @@
);
}
$html_total_pages = sprintf( "
%s", number_format_i18n( $total_pages ) );
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
+ $page_links[] = $total_pages_before . sprintf(
+ /* translators: 1: Current page, 2: Total pages. */
+ _x( '%1$s of %2$s', 'paging' ),
+ $html_current_page,
+ $html_total_pages
+ ) . $total_pages_after;
if ( $disable_next ) {
$page_links[] = '
›';
@@ -896,8 +960,10 @@
}
/**
- * Get a list of columns. The format is:
- * 'internal-name' => 'Title'
+ * Gets a list of columns.
+ *
+ * The format is:
+ * - `'internal-name' => 'Title'`
*
* @since 3.1.0
* @abstract
@@ -905,16 +971,16 @@
* @return array
*/
public function get_columns() {
- die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
+ die( 'function WP_List_Table::get_columns() must be overridden in a subclass.' );
}
/**
- * Get a list of sortable columns. The format is:
- * 'internal-name' => 'orderby'
- * or
- * 'internal-name' => array( 'orderby', true )
+ * Gets a list of sortable columns.
*
- * The second format will make the initial sorting order be descending
+ * The format is:
+ * - `'internal-name' => 'orderby'`
+ * - `'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.
*
* @since 3.1.0
*
@@ -975,8 +1041,8 @@
$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 = WP_List_Table::get_default_primary_column_name();
}
@@ -999,14 +1065,14 @@
}
/**
- * Get a list of all, hidden and sortable columns, with filter applied
+ * Gets a list of all, hidden and sortable columns, with filter applied.
*
* @since 3.1.0
*
* @return array
*/
protected function get_column_info() {
- // $_column_headers is already set / cached
+ // $_column_headers is already set / cached.
if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
// Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
// In 4.3, we added a fourth argument for primary column.
@@ -1028,7 +1094,7 @@
* The dynamic portion of the hook name, `$this->screen->id`, refers
* to the ID of the current screen, usually a string.
*
- * @since 3.5.0
+ * @since 3.1.0
*
* @param array $sortable_columns An array of sortable columns.
*/
@@ -1055,7 +1121,7 @@
}
/**
- * Return number of visible columns
+ * Returns the number of visible columns.
*
* @since 3.1.0
*
@@ -1068,13 +1134,11 @@
}
/**
- * Print column headers, accounting for hidden and sortable columns.
+ * Prints column headers, accounting for hidden and sortable columns.
*
* @since 3.1.0
*
- * @staticvar int $cb_counter
- *
- * @param bool $with_id Whether to set the id attribute or not
+ * @param bool $with_id Whether to set the ID attribute or not
*/
public function print_column_headers( $with_id = true ) {
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
@@ -1104,13 +1168,13 @@
foreach ( $columns as $column_key => $column_display_name ) {
$class = array( 'manage-column', "column-$column_key" );
- if ( in_array( $column_key, $hidden ) ) {
+ if ( in_array( $column_key, $hidden, true ) ) {
$class[] = 'hidden';
}
if ( 'cb' === $column_key ) {
$class[] = 'check-column';
- } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
+ } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
$class[] = 'num';
}
@@ -1122,16 +1186,26 @@
list( $orderby, $desc_first ) = $sortable[ $column_key ];
if ( $current_orderby === $orderby ) {
- $order = 'asc' === $current_order ? 'desc' : 'asc';
+ $order = 'asc' === $current_order ? 'desc' : 'asc';
+
$class[] = 'sorted';
$class[] = $current_order;
} else {
- $order = $desc_first ? 'desc' : 'asc';
+ $order = strtolower( $desc_first );
+
+ if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
+ $order = $desc_first ? 'desc' : 'asc';
+ }
+
$class[] = 'sortable';
- $class[] = $desc_first ? 'asc' : 'desc';
+ $class[] = 'desc' === $order ? 'asc' : 'desc';
}
- $column_display_name = '
' . $column_display_name . '';
+ $column_display_name = sprintf(
+ '
%s',
+ esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
+ $column_display_name
+ );
}
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
@@ -1147,7 +1221,7 @@
}
/**
- * Display the table
+ * Displays the table.
*
* @since 3.1.0
*/
@@ -1187,18 +1261,22 @@
}
/**
- * Get a list of CSS classes for the WP_List_Table table tag.
+ * Gets a list of CSS classes for the WP_List_Table table tag.
*
* @since 3.1.0
*
- * @return array List of CSS classes for the table tag.
+ * @return string[] Array of CSS classes for the table tag.
*/
protected function get_table_classes() {
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
+ $mode = get_user_setting( 'posts_list_mode', 'list' );
+
+ $mode_class = esc_attr( 'table-view-' . $mode );
+
+ return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
}
/**
- * Generate the table navigation above or below the table
+ * Generates the table navigation above or below the table
*
* @since 3.1.0
* @param string $which
@@ -1226,7 +1304,7 @@
}
/**
- * Extra controls to be displayed between bulk actions and pagination
+ * Extra controls to be displayed between bulk actions and pagination.
*
* @since 3.1.0
*
@@ -1235,7 +1313,7 @@
protected function extra_tablenav( $which ) {}
/**
- * Generate the tbody element for the list table.
+ * Generates the tbody element for the list table.
*
* @since 3.1.0
*/
@@ -1250,7 +1328,7 @@
}
/**
- * Generate the table rows
+ * Generates the table rows.
*
* @since 3.1.0
*/
@@ -1261,7 +1339,7 @@
}
/**
- * Generates content for a single row of the table
+ * Generates content for a single row of the table.
*
* @since 3.1.0
*
@@ -1285,11 +1363,11 @@
protected function column_cb( $item ) {}
/**
- * Generates the columns for a single row of the table
+ * Generates the columns for a single row of the table.
*
* @since 3.1.0
*
- * @param object $item The current item
+ * @param object $item The current item.
*/
protected function single_row_columns( $item ) {
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
@@ -1300,7 +1378,7 @@
$classes .= ' has-row-actions column-primary';
}
- if ( in_array( $column_name, $hidden ) ) {
+ if ( in_array( $column_name, $hidden, true ) ) {
$classes .= ' hidden';
}
@@ -1344,14 +1422,15 @@
* @param object $item The item being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
- * @return string The row actions HTML, or an empty string if the current column is the primary column.
+ * @return string The row actions HTML, or an empty string
+ * if the current column is not the primary column.
*/
protected function handle_row_actions( $item, $column_name, $primary ) {
return $column_name === $primary ? '
' : '';
}
/**
- * Handle an incoming ajax request (called from admin-ajax.php)
+ * Handles an incoming ajax request (called from admin-ajax.php)
*
* @since 3.1.0
*/
@@ -1371,6 +1450,7 @@
if ( isset( $this->_pagination_args['total_items'] ) ) {
$response['total_items_i18n'] = sprintf(
+ /* translators: Number of items. */
_n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
number_format_i18n( $this->_pagination_args['total_items'] )
);
@@ -1384,7 +1464,9 @@
}
/**
- * Send required variables to JavaScript land
+ * Sends required variables to JavaScript land.
+ *
+ * @since 3.1.0
*/
public function _js_vars() {
$args = array(