diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-posts-list-table.php
--- a/wp/wp-admin/includes/class-wp-posts-list-table.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/class-wp-posts-list-table.php Tue Dec 15 13:49:49 2020 +0100
@@ -67,7 +67,7 @@
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global WP_Post_Type $post_type_object
- * @global wpdb $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $args An associative array of arguments.
*/
@@ -109,7 +109,8 @@
$_GET['author'] = get_current_user_id();
}
- if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
+ $sticky_posts = get_option( 'sticky_posts' );
+ if ( 'post' === $post_type && $sticky_posts ) {
$sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
$this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
}
@@ -134,15 +135,22 @@
}
/**
+ * @global string $mode List table view mode.
* @global array $avail_post_stati
- * @global WP_Query $wp_query
+ * @global WP_Query $wp_query WordPress Query object.
* @global int $per_page
- * @global string $mode
*/
public function prepare_items() {
- global $avail_post_stati, $wp_query, $per_page, $mode;
+ global $mode, $avail_post_stati, $wp_query, $per_page;
- // is going to call wp()
+ if ( ! empty( $_REQUEST['mode'] ) ) {
+ $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
+ set_user_setting( 'posts_list_mode', $mode );
+ } else {
+ $mode = get_user_setting( 'posts_list_mode', 'list' );
+ }
+
+ // Is going to call wp().
$avail_post_stati = wp_edit_posts_query();
$this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
@@ -160,11 +168,11 @@
} else {
$post_counts = (array) wp_count_posts( $post_type, 'readable' );
- if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati ) ) {
+ if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) {
$total_items = $post_counts[ $_REQUEST['post_status'] ];
} elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
$total_items = $this->sticky_posts_count;
- } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) {
+ } elseif ( isset( $_GET['author'] ) && get_current_user_id() == $_GET['author'] ) {
$total_items = $this->user_posts_count;
} else {
$total_items = array_sum( $post_counts );
@@ -176,14 +184,7 @@
}
}
- if ( ! empty( $_REQUEST['mode'] ) ) {
- $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
- set_user_setting( 'posts_list_mode', $mode );
- } else {
- $mode = get_user_setting( 'posts_list_mode', 'list' );
- }
-
- $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
+ $this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'];
$this->set_pagination_args(
array(
@@ -243,7 +244,8 @@
protected function get_edit_link( $args, $label, $class = '' ) {
$url = add_query_arg( $args, 'edit.php' );
- $class_html = $aria_current = '';
+ $class_html = '';
+ $aria_current = '';
if ( ! empty( $class ) ) {
$class_html = sprintf(
' class="%s"',
@@ -303,6 +305,7 @@
);
$mine_inner_html = sprintf(
+ /* translators: %s: Number of posts. */
_nx(
'Mine (%s)',
'Mine (%s)',
@@ -323,6 +326,7 @@
}
$all_inner_html = sprintf(
+ /* translators: %s: Number of posts. */
_nx(
'All (%s)',
'All (%s)',
@@ -342,7 +346,7 @@
$status_name = $status->name;
- if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
+ if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
continue;
}
@@ -372,6 +376,7 @@
);
$sticky_inner_html = sprintf(
+ /* translators: %s: Number of posts. */
_nx(
'Sticky (%s)',
'Sticky (%s)',
@@ -386,7 +391,7 @@
);
// Sticky comes after Publish, or if not listed, after All.
- $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
+ $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ), true );
$status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
}
@@ -410,7 +415,7 @@
if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = __( 'Delete Permanently' );
+ $actions['delete'] = __( 'Delete permanently' );
} else {
$actions['trash'] = __( 'Move to Trash' );
}
@@ -464,17 +469,24 @@
* @since 5.2.0
* @access protected
*
- * @param string $post_type Post type key.
+ * @param string $post_type Post type slug.
*/
protected function formats_dropdown( $post_type ) {
/**
* Filters whether to remove the 'Formats' drop-down from the post list table.
*
* @since 5.2.0
+ * @since 5.5.0 The `$post_type` parameter was added.
*
- * @param bool $disable Whether to disable the drop-down. Default false.
+ * @param bool $disable Whether to disable the drop-down. Default false.
+ * @param string $post_type Post type slug.
*/
- if ( apply_filters( 'disable_formats_dropdown', false ) ) {
+ if ( apply_filters( 'disable_formats_dropdown', false, $post_type ) ) {
+ return;
+ }
+
+ // Return if the post type doesn't have post formats or if we're in the Trash.
+ if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) {
return;
}
@@ -486,11 +498,8 @@
)
);
- /*
- * Return if the post type doesn't have post formats, or there are no posts using formats,
- * or if we're in the trash.
- */
- if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || ! $used_post_formats || $this->is_trash ) {
+ // Return if there are no posts using formats.
+ if ( ! $used_post_formats ) {
return;
}
@@ -525,7 +534,7 @@
?>
months_dropdown( $this->screen->post_type );
@@ -586,10 +595,16 @@
}
/**
+ * @global string $mode List table view mode.
+ *
* @return array
*/
protected function get_table_classes() {
- return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
+ global $mode;
+
+ $mode_class = esc_attr( 'table-view-' . $mode );
+
+ return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
}
/**
@@ -602,7 +617,7 @@
$posts_columns['cb'] = '
';
- /* translators: manage posts column name */
+ /* translators: Posts screen column name. */
$posts_columns['title'] = _x( 'Title', 'column name' );
if ( post_type_supports( $post_type, 'author' ) ) {
@@ -639,7 +654,7 @@
}
$post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
- if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) {
+ if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) ) {
$posts_columns['comments'] = '';
}
@@ -693,10 +708,10 @@
}
/**
- * @global WP_Query $wp_query
+ * @global WP_Query $wp_query WordPress Query object.
* @global int $per_page
* @param array $posts
- * @param int $level
+ * @param int $level
*/
public function display_rows( $posts = array(), $level = 0 ) {
global $wp_query, $per_page;
@@ -716,7 +731,7 @@
/**
* @param array $posts
- * @param int $level
+ * @param int $level
*/
private function _display_rows( $posts, $level = 0 ) {
$post_type = $this->screen->post_type;
@@ -738,11 +753,11 @@
}
/**
- * @global wpdb $wpdb
- * @global WP_Post $post
+ * @global wpdb $wpdb WordPress database abstraction object.
+ * @global WP_Post $post Global post object.
* @param array $pages
- * @param int $pagenum
- * @param int $per_page
+ * @param int $pagenum
+ * @param int $per_page
*/
private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
global $wpdb;
@@ -847,11 +862,11 @@
* @since 4.2.0 Added the `$to_display` parameter.
*
* @param array $children_pages
- * @param int $count
- * @param int $parent
- * @param int $level
- * @param int $pagenum
- * @param int $per_page
+ * @param int $count
+ * @param int $parent
+ * @param int $level
+ * @param int $pagenum
+ * @param int $per_page
* @param array $to_display List of pages to be displayed. Passed by reference.
*/
private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
@@ -872,7 +887,7 @@
$my_parents = array();
$my_parent = $page->post_parent;
while ( $my_parent ) {
- // Get the ID from the list or the attribute if my_parent is an object
+ // Get the ID from the list or the attribute if my_parent is an object.
$parent_id = $my_parent;
if ( is_object( $my_parent ) ) {
$parent_id = $my_parent->ID;
@@ -901,7 +916,7 @@
$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
}
- unset( $children_pages[ $parent ] ); //required in order to keep track of orphans
+ unset( $children_pages[ $parent ] ); // Required in order to keep track of orphans.
}
/**
@@ -915,9 +930,10 @@
if ( current_user_can( 'edit_post', $post->ID ) ) :
?>
@@ -925,7 +941,7 @@
ID );
- if ( $can_edit_post && $post->post_status != 'trash' ) {
+ if ( $can_edit_post && 'trash' !== $post->post_status ) {
$lock_holder = wp_check_post_lock( $post->ID );
if ( $lock_holder ) {
$lock_holder = get_userdata( $lock_holder );
$locked_avatar = get_avatar( $lock_holder->ID, 18 );
- $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
+ /* translators: %s: User's display name. */
+ $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
} else {
- $locked_avatar = $locked_text = '';
+ $locked_avatar = '';
+ $locked_text = '';
}
echo '' . $locked_avatar . ' ' . $locked_text . "
\n";
@@ -1006,11 +1024,11 @@
$title = _draft_or_post_title();
- if ( $can_edit_post && $post->post_status != 'trash' ) {
+ if ( $can_edit_post && 'trash' !== $post->post_status ) {
printf(
'%s%s',
get_edit_post_link( $post->ID ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ),
$pad,
$title
@@ -1030,7 +1048,10 @@
}
echo "\n";
- if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
+ if ( 'excerpt' === $mode
+ && ! is_post_type_hierarchical( $this->screen->post_type )
+ && current_user_can( 'read_post', $post->ID )
+ ) {
if ( post_password_required( $post ) ) {
echo '' . esc_html( get_the_excerpt() ) . '';
} else {
@@ -1054,20 +1075,20 @@
global $mode;
if ( '0000-00-00 00:00:00' === $post->post_date ) {
- $t_time = $h_time = __( 'Unpublished' );
+ $t_time = __( 'Unpublished' );
$time_diff = 0;
} else {
- $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
- $m_time = $post->post_date;
- $time = get_post_time( 'G', true, $post );
-
- $time_diff = time() - $time;
+ $t_time = sprintf(
+ /* translators: 1: Post date, 2: Post time. */
+ __( '%1$s at %2$s' ),
+ /* translators: Post date format. See https://www.php.net/date */
+ get_the_time( __( 'Y/m/d' ), $post ),
+ /* translators: Post time format. See https://www.php.net/date */
+ get_the_time( __( 'g:i a' ), $post )
+ );
- if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
- $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
- } else {
- $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
- }
+ $time = get_post_timestamp( $post );
+ $time_diff = time() - $time;
}
if ( 'publish' === $post->post_status ) {
@@ -1098,27 +1119,20 @@
echo $status . '
';
}
- if ( 'excerpt' === $mode ) {
- /**
- * Filters the published time of the post.
- *
- * If `$mode` equals 'excerpt', the published time and date are both displayed.
- * If `$mode` equals 'list' (default), the publish date is displayed, with the
- * time and date together available as an abbreviation definition.
- *
- * @since 2.5.1
- *
- * @param string $t_time The published time.
- * @param WP_Post $post Post object.
- * @param string $column_name The column name.
- * @param string $mode The list display mode ('excerpt' or 'list').
- */
- echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
- } else {
-
- /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
- echo '' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '';
- }
+ /**
+ * Filters the published time of the post.
+ *
+ * @since 2.5.1
+ * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes.
+ * The published time and date are both displayed now,
+ * which is equivalent to the previous 'excerpt' mode.
+ *
+ * @param string $t_time The published time.
+ * @param WP_Post $post Post object.
+ * @param string $column_name The column name.
+ * @param string $mode The list display mode ('excerpt' or 'list').
+ */
+ echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
}
/**
@@ -1180,7 +1194,7 @@
$term_links = array();
foreach ( $terms as $t ) {
$posts_in_term_qv = array();
- if ( 'post' != $post->post_type ) {
+ if ( 'post' !== $post->post_type ) {
$posts_in_term_qv['post_type'] = $post->post_type;
}
if ( $taxonomy_object->query_var ) {
@@ -1200,13 +1214,13 @@
*
* @since 5.2.0
*
- * @param array $term_links List of links to edit.php, filtered by the taxonomy term.
- * @param string $taxonomy Taxonomy name.
- * @param array $terms Array of terms appearing in the post row.
+ * @param string[] $term_links Array of term editing links.
+ * @param string $taxonomy Taxonomy name.
+ * @param WP_Term[] $terms Array of term objects appearing in the post row.
*/
$term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
- /* translators: used between list items, there is a space after the comma */
+ /* translators: Used between list items, there is a space after the comma. */
echo join( __( ', ' ), $term_links );
} else {
echo '—' . $taxonomy_object->labels->no_terms . '';
@@ -1258,7 +1272,7 @@
}
/**
- * @global WP_Post $post
+ * @global WP_Post $post Global post object.
*
* @param int|WP_Post $post
* @param int $level
@@ -1312,7 +1326,8 @@
* @param object $post Post being acted upon.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
- * @return string Row actions output for posts.
+ * @return string Row actions output for posts, or an empty string
+ * if the current column is not the primary column.
*/
protected function handle_row_actions( $post, $column_name, $primary ) {
if ( $primary !== $column_name ) {
@@ -1324,11 +1339,11 @@
$actions = array();
$title = _draft_or_post_title();
- if ( $can_edit_post && 'trash' != $post->post_status ) {
+ if ( $can_edit_post && 'trash' !== $post->post_status ) {
$actions['edit'] = sprintf(
'%s',
get_edit_post_link( $post->ID ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ),
__( 'Edit' )
);
@@ -1336,7 +1351,7 @@
if ( 'wp_block' !== $post->post_type ) {
$actions['inline hide-if-no-js'] = sprintf(
'',
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $title ) ),
__( 'Quick Edit' )
);
@@ -1348,7 +1363,7 @@
$actions['untrash'] = sprintf(
'%s',
wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $title ) ),
__( 'Restore' )
);
@@ -1356,7 +1371,7 @@
$actions['trash'] = sprintf(
'%s',
get_delete_post_link( $post->ID ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $title ) ),
_x( 'Trash', 'verb' )
);
@@ -1365,7 +1380,7 @@
$actions['delete'] = sprintf(
'%s',
get_delete_post_link( $post->ID, '', true ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Delete “%s” permanently' ), $title ) ),
__( 'Delete Permanently' )
);
@@ -1373,22 +1388,22 @@
}
if ( is_post_type_viewable( $post_type_object ) ) {
- if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
+ if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
if ( $can_edit_post ) {
$preview_link = get_preview_post_link( $post );
$actions['view'] = sprintf(
'%s',
esc_url( $preview_link ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ),
__( 'Preview' )
);
}
- } elseif ( 'trash' != $post->post_status ) {
+ } elseif ( 'trash' !== $post->post_status ) {
$actions['view'] = sprintf(
'%s',
get_permalink( $post->ID ),
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'View “%s”' ), $title ) ),
__( 'View' )
);
@@ -1399,7 +1414,7 @@
$actions['export'] = sprintf(
'',
$post->ID,
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Export “%s” as JSON' ), $title ) ),
__( 'Export as JSON' )
);
@@ -1458,6 +1473,7 @@
$taxonomy_names = get_object_taxonomies( $screen->post_type );
$hierarchical_taxonomies = array();
$flat_taxonomies = array();
+
foreach ( $taxonomy_names as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name );
@@ -1498,7 +1514,8 @@
?>
-