diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-comments-list-table.php
--- a/wp/wp-admin/includes/class-wp-comments-list-table.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/class-wp-comments-list-table.php Tue Dec 15 13:49:49 2020 +0100
@@ -55,6 +55,15 @@
);
}
+ /**
+ * Adds avatars to comment author names.
+ *
+ * @since 3.1.0
+ *
+ * @param string $name Comment author name.
+ * @param int $comment_ID Comment ID.
+ * @return string Avatar with the user name.
+ */
public function floated_admin_avatar( $name, $comment_ID ) {
$comment = get_comment( $comment_ID );
$avatar = get_avatar( $comment, 32, 'mystery' );
@@ -69,16 +78,24 @@
}
/**
+ * @global string $mode List table view mode.
* @global int $post_id
* @global string $comment_status
+ * @global string $comment_type
* @global string $search
- * @global string $comment_type
*/
public function prepare_items() {
- global $post_id, $comment_status, $search, $comment_type;
+ global $mode, $post_id, $comment_status, $comment_type, $search;
+
+ 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' );
+ }
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
- if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
+ if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ), true ) ) {
$comment_status = 'all';
}
@@ -100,7 +117,7 @@
if ( isset( $_REQUEST['number'] ) ) {
$number = (int) $_REQUEST['number'];
} else {
- $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
+ $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra.
}
$page = $this->get_pagenum();
@@ -200,6 +217,8 @@
if ( 'moderated' === $comment_status ) {
_e( 'No comments awaiting moderation.' );
+ } elseif ( 'trash' === $comment_status ) {
+ _e( 'No comments found in Trash.' );
} else {
_e( 'No comments found.' );
}
@@ -217,42 +236,42 @@
$num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
$stati = array(
- /* translators: %s: all comments count */
+ /* translators: %s: Number of comments. */
'all' => _nx_noop(
'All (%s)',
'All (%s)',
'comments'
- ), // singular not used
+ ), // Singular not used.
- /* translators: %s: current user's comments count */
+ /* translators: %s: Number of comments. */
'mine' => _nx_noop(
'Mine (%s)',
'Mine (%s)',
'comments'
),
- /* translators: %s: pending comments count */
+ /* translators: %s: Number of comments. */
'moderated' => _nx_noop(
'Pending (%s)',
'Pending (%s)',
'comments'
),
- /* translators: %s: approved comments count */
+ /* translators: %s: Number of comments. */
'approved' => _nx_noop(
'Approved (%s)',
'Approved (%s)',
'comments'
),
- /* translators: %s: spam comments count */
+ /* translators: %s: Number of comments. */
'spam' => _nx_noop(
'Spam (%s)',
'Spam (%s)',
'comments'
),
- /* translators: %s: trashed comments count */
+ /* translators: %s: Number of comments. */
'trash' => _nx_noop(
'Trash (%s)',
'Trash (%s)',
@@ -265,7 +284,7 @@
}
$link = admin_url( 'edit-comments.php' );
- if ( ! empty( $comment_type ) && 'all' != $comment_type ) {
+ if ( ! empty( $comment_type ) && 'all' !== $comment_type ) {
$link = add_query_arg( 'comment_type', $comment_type, $link );
}
@@ -333,24 +352,24 @@
global $comment_status;
$actions = array();
- if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) {
+ if ( in_array( $comment_status, array( 'all', 'approved' ), true ) ) {
$actions['unapprove'] = __( 'Unapprove' );
}
- if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) {
+ if ( in_array( $comment_status, array( 'all', 'moderated' ), true ) ) {
$actions['approve'] = __( 'Approve' );
}
- if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) {
- $actions['spam'] = _x( 'Mark as Spam', 'comment' );
+ if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ), true ) ) {
+ $actions['spam'] = _x( 'Mark as spam', 'comment' );
}
if ( 'trash' === $comment_status ) {
$actions['untrash'] = __( 'Restore' );
} elseif ( 'spam' === $comment_status ) {
- $actions['unspam'] = _x( 'Not Spam', 'comment' );
+ $actions['unspam'] = _x( 'Not spam', 'comment' );
}
- if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = __( 'Delete Permanently' );
+ if ( in_array( $comment_status, array( 'trash', 'spam' ), true ) || ! EMPTY_TRASH_DAYS ) {
+ $actions['delete'] = __( 'Delete permanently' );
} else {
$actions['trash'] = __( 'Move to Trash' );
}
@@ -371,43 +390,24 @@
if ( ! isset( $has_items ) ) {
$has_items = $this->has_items();
}
- ?>
-
- ';
if ( 'top' === $which ) {
- ?>
-
-
- comment_status_dropdown( $comment_type );
/**
* Fires just before the Filter submit button for comment types.
*
* @since 3.5.0
*/
do_action( 'restrict_manage_comments' );
- submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
+
+ $output = ob_get_clean();
+
+ if ( ! empty( $output ) && $this->has_items() ) {
+ echo $output;
+ submit_button( esc_html__( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
+ }
}
if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) {
@@ -455,16 +455,65 @@
$columns['comment'] = _x( 'Comment', 'column name' );
if ( ! $post_id ) {
- /* translators: column name or table row header */
- $columns['response'] = __( 'In Response To' );
+ /* translators: Column name or table row header. */
+ $columns['response'] = __( 'In response to' );
}
- $columns['date'] = _x( 'Submitted On', 'column name' );
+ $columns['date'] = _x( 'Submitted on', 'column name' );
return $columns;
}
/**
+ * Displays a comment status drop-down for filtering on the Comments list table.
+ *
+ * @since 5.5.0
+ *
+ * @param string $comment_type The current comment type slug.
+ */
+ protected function comment_status_dropdown( $comment_type ) {
+ /**
+ * Filters the comment types dropdown menu.
+ *
+ * @since 2.7.0
+ *
+ * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
+ */
+ $comment_types = apply_filters(
+ 'admin_comment_types_dropdown',
+ array(
+ 'comment' => esc_html__( 'Comments' ),
+ 'pings' => esc_html__( 'Pings' ),
+ )
+ );
+
+ if ( $comment_types && is_array( $comment_types ) ) {
+ printf( '
', esc_html__( 'Filter by comment type' ) );
+
+ echo '';
+ }
+ }
+
+ /**
* @return array
*/
protected function get_sortable_columns() {
@@ -487,11 +536,22 @@
}
/**
+ * Displays the comments table.
+ *
+ * Overrides the parent display() method to render extra comments.
+ *
+ * @since 3.1.0
*/
public function display() {
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
+ static $has_items;
- $this->display_tablenav( 'top' );
+ if ( ! isset( $has_items ) ) {
+ $has_items = $this->has_items();
+ if ( $has_items ) {
+ $this->display_tablenav( 'top' );
+ }
+ }
$this->screen->render_screen_reader_content( 'heading_list' );
@@ -533,8 +593,8 @@
}
/**
- * @global WP_Post $post
- * @global WP_Comment $comment
+ * @global WP_Post $post Global post object.
+ * @global WP_Comment $comment Global comment object.
*
* @param WP_Comment $item
*/
@@ -571,7 +631,9 @@
* @param WP_Comment $comment The comment object.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
- * @return string|void Comment row actions output.
+ * @return string Row actions output for comments. An empty string
+ * if the current column is not the primary column,
+ * or if the current user cannot edit the comment.
*/
protected function handle_row_actions( $comment, $column_name, $primary ) {
global $comment_status;
@@ -581,7 +643,7 @@
}
if ( ! $this->user_can ) {
- return;
+ return '';
}
$the_comment_status = wp_get_comment_status( $comment );
@@ -616,56 +678,152 @@
);
// Not looking at all comments.
- if ( $comment_status && 'all' != $comment_status ) {
+ if ( $comment_status && 'all' !== $comment_status ) {
if ( 'approved' === $the_comment_status ) {
- $actions['unapprove'] = "
" . __( 'Unapprove' ) . '';
+ $actions['unapprove'] = sprintf(
+ '
%s',
+ $unapprove_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=unapproved",
+ esc_attr__( 'Unapprove this comment' ),
+ __( 'Unapprove' )
+ );
} elseif ( 'unapproved' === $the_comment_status ) {
- $actions['approve'] = "
" . __( 'Approve' ) . '';
+ $actions['approve'] = sprintf(
+ '
%s',
+ $approve_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=approved",
+ esc_attr__( 'Approve this comment' ),
+ __( 'Approve' )
+ );
}
} else {
- $actions['approve'] = "
" . __( 'Approve' ) . '';
- $actions['unapprove'] = "
" . __( 'Unapprove' ) . '';
+ $actions['approve'] = sprintf(
+ '
%s',
+ $approve_url,
+ "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
+ esc_attr__( 'Approve this comment' ),
+ __( 'Approve' )
+ );
+
+ $actions['unapprove'] = sprintf(
+ '
%s',
+ $unapprove_url,
+ "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
+ esc_attr__( 'Unapprove this comment' ),
+ __( 'Unapprove' )
+ );
}
if ( 'spam' !== $the_comment_status ) {
- $actions['spam'] = "
" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '';
+ $actions['spam'] = sprintf(
+ '
%s',
+ $spam_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
+ esc_attr__( 'Mark this comment as spam' ),
+ /* translators: "Mark as spam" link. */
+ _x( 'Spam', 'verb' )
+ );
} elseif ( 'spam' === $the_comment_status ) {
- $actions['unspam'] = "
" . _x( 'Not Spam', 'comment' ) . '';
+ $actions['unspam'] = sprintf(
+ '
%s',
+ $unspam_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1",
+ esc_attr__( 'Restore this comment from the spam' ),
+ _x( 'Not Spam', 'comment' )
+ );
}
if ( 'trash' === $the_comment_status ) {
- $actions['untrash'] = "
" . __( 'Restore' ) . '';
+ $actions['untrash'] = sprintf(
+ '
%s',
+ $untrash_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1",
+ esc_attr__( 'Restore this comment from the Trash' ),
+ __( 'Restore' )
+ );
}
if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = "
" . __( 'Delete Permanently' ) . '';
+ $actions['delete'] = sprintf(
+ '
%s',
+ $delete_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}::delete=1",
+ esc_attr__( 'Delete this comment permanently' ),
+ __( 'Delete Permanently' )
+ );
} else {
- $actions['trash'] = "
" . _x( 'Trash', 'verb' ) . '';
+ $actions['trash'] = sprintf(
+ '
%s',
+ $trash_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
+ esc_attr__( 'Move this comment to the Trash' ),
+ _x( 'Trash', 'verb' )
+ );
}
if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
- $actions['edit'] = "
" . __( 'Edit' ) . '';
+ $actions['edit'] = sprintf(
+ '
%s',
+ "comment.php?action=editcomment&c={$comment->comment_ID}",
+ esc_attr__( 'Edit this comment' ),
+ __( 'Edit' )
+ );
$format = '
';
- $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline', esc_attr__( 'Quick edit this comment inline' ), __( 'Quick Edit' ) );
+ $actions['quickedit'] = sprintf(
+ $format,
+ $comment->comment_ID,
+ $comment->comment_post_ID,
+ 'edit',
+ 'vim-q comment-inline',
+ esc_attr__( 'Quick edit this comment inline' ),
+ __( 'Quick Edit' )
+ );
- $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
+ $actions['reply'] = sprintf(
+ $format,
+ $comment->comment_ID,
+ $comment->comment_post_ID,
+ 'replyto',
+ 'vim-r comment-inline',
+ esc_attr__( 'Reply to this comment' ),
+ __( 'Reply' )
+ );
}
/** This filter is documented in wp-admin/includes/dashboard.php */
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
- $i = 0;
- $out .= '
';
+ $always_visible = false;
+
+ $mode = get_user_setting( 'posts_list_mode', 'list' );
+
+ if ( 'excerpt' === $mode ) {
+ $always_visible = true;
+ }
+
+ $out .= '
';
+
+ $i = 0;
+
foreach ( $actions as $action => $link ) {
++$i;
- ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
- // Reply and quickedit need a hide-if-no-js span when not added with ajax
+ if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
+ || 1 === $i
+ ) {
+ $sep = '';
+ } else {
+ $sep = ' | ';
+ }
+
+ // Reply and quickedit need a hide-if-no-js span when not added with Ajax.
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
$action .= ' hide-if-no-js';
- } elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
+ } elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status )
+ || ( 'unspam' === $action && 'spam' === $the_comment_status )
+ ) {
if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
$action .= ' approve';
} else {
@@ -675,6 +833,7 @@
$out .= "$sep$link";
}
+
$out .= '
';
$out .= '
';
@@ -708,7 +867,7 @@
$parent_link = esc_url( get_comment_link( $parent ) );
$name = get_comment_author( $parent );
printf(
- /* translators: %s: comment link */
+ /* translators: %s: Comment link. */
__( 'In reply to %s.' ),
'
' . $name . ''
);
@@ -785,11 +944,12 @@
* @param WP_Comment $comment The comment object.
*/
public function column_date( $comment ) {
- /* translators: 1: comment date, 2: comment time */
$submitted = sprintf(
+ /* translators: 1: Comment date, 2: Comment time. */
__( '%1$s at %2$s' ),
- /* translators: comment date format. See https://secure.php.net/date */
+ /* translators: Comment date format. See https://www.php.net/date */
get_comment_date( __( 'Y/m/d' ), $comment ),
+ /* translators: Comment time format. See https://www.php.net/date */
get_comment_date( __( 'g:i a' ), $comment )
);
@@ -819,8 +979,9 @@
if ( isset( $this->pending_count[ $post->ID ] ) ) {
$pending_comments = $this->pending_count[ $post->ID ];
} else {
- $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
- $pending_comments = $this->pending_count[ $post->ID ] = $_pending_count_temp[ $post->ID ];
+ $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
+ $pending_comments = $_pending_count_temp[ $post->ID ];
+ $this->pending_count[ $post->ID ] = $pending_comments;
}
if ( current_user_can( 'edit_post', $post->ID ) ) {
@@ -831,8 +992,11 @@
}
echo '
';
- if ( 'attachment' === $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) {
- echo $thumb;
+ if ( 'attachment' === $post->post_type ) {
+ $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true );
+ if ( $thumb ) {
+ echo $thumb;
+ }
}
echo $post_link;
$post_type_object = get_post_type_object( $post->post_type );
@@ -853,8 +1017,8 @@
*
* @since 2.8.0
*
- * @param string $column_name The custom column's name.
- * @param int $comment->comment_ID The custom column's unique ID number.
+ * @param string $column_name The custom column's name.
+ * @param int $comment_ID The custom column's unique ID number.
*/
do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
}