45
45
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
48
parent::__construct( array(
49
'plural' => 'comments',
50
'singular' => 'comment',
52
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
50
'plural' => 'comments',
51
'singular' => 'comment',
53
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
56
58
public function floated_admin_avatar( $name, $comment_ID ) {
57
59
$comment = get_comment( $comment_ID );
58
$avatar = get_avatar( $comment, 32, 'mystery' );
60
$avatar = get_avatar( $comment, 32, 'mystery' );
59
61
return "$avatar $name";
77
78
global $post_id, $comment_status, $search, $comment_type;
79
80
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
80
if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) )
81
if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
81
82
$comment_status = 'all';
83
$comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
85
$comment_type = ! empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
85
87
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
117
118
$status_map = array(
118
120
'moderated' => 'hold',
119
'approved' => 'approve',
121
'approved' => 'approve',
124
'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
126
'user_id' => $user_id,
129
'post_id' => $post_id,
130
'type' => $comment_type,
131
'orderby' => $orderby,
126
'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status,
128
'user_id' => $user_id,
131
'post_id' => $post_id,
132
'type' => $comment_type,
133
'orderby' => $orderby,
133
135
'post_type' => $post_type,
139
* Filters the arguments for the comment query in the comments list table.
143
* @param array $args An array of get_comments() arguments.
145
$args = apply_filters( 'comments_list_table_query_args', $args );
136
147
$_comments = get_comments( $args );
137
148
if ( is_array( $_comments ) ) {
138
149
update_comment_cache( $_comments );
140
$this->items = array_slice( $_comments, 0, $comments_per_page );
151
$this->items = array_slice( $_comments, 0, $comments_per_page );
141
152
$this->extra_items = array_slice( $_comments, $comments_per_page );
143
154
$_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
145
156
$this->pending_count = get_pending_comments_num( $_comment_post_ids );
148
$total_comments = get_comments( array_merge( $args, array(
159
$total_comments = get_comments(
154
$this->set_pagination_args( array(
155
'total_items' => $total_comments,
156
'per_page' => $comments_per_page,
170
$this->set_pagination_args(
172
'total_items' => $total_comments,
173
'per_page' => $comments_per_page,
162
179
* @param string $comment_status
205
220
/* translators: %s: all comments count */
207
222
'All <span class="count">(%s)</span>',
208
223
'All <span class="count">(%s)</span>',
210
225
), // singular not used
227
/* translators: %s: current user's comments count */
229
'Mine <span class="count">(%s)</span>',
230
'Mine <span class="count">(%s)</span>',
212
234
/* translators: %s: pending comments count */
213
235
'moderated' => _nx_noop(
214
236
'Pending <span class="count">(%s)</span>',
219
241
/* translators: %s: approved comments count */
220
'approved' => _nx_noop(
242
'approved' => _nx_noop(
221
243
'Approved <span class="count">(%s)</span>',
222
244
'Approved <span class="count">(%s)</span>',
226
248
/* translators: %s: spam comments count */
228
250
'Spam <span class="count">(%s)</span>',
229
251
'Spam <span class="count">(%s)</span>',
233
255
/* translators: %s: trashed comments count */
235
257
'Trash <span class="count">(%s)</span>',
236
258
'Trash <span class="count">(%s)</span>',
241
if ( !EMPTY_TRASH_DAYS )
242
unset($stati['trash']);
263
if ( ! EMPTY_TRASH_DAYS ) {
264
unset( $stati['trash'] );
244
267
$link = admin_url( 'edit-comments.php' );
245
if ( !empty($comment_type) && 'all' != $comment_type )
268
if ( ! empty( $comment_type ) && 'all' != $comment_type ) {
246
269
$link = add_query_arg( 'comment_type', $comment_type, $link );
248
272
foreach ( $stati as $status => $label ) {
249
273
$current_link_attributes = '';
252
276
$current_link_attributes = ' class="current" aria-current="page"';
255
if ( !isset( $num_comments->$status ) )
279
if ( 'mine' === $status ) {
280
$current_user_id = get_current_user_id();
281
$num_comments->mine = get_comments(
283
'post_id' => $post_id ? $post_id : 0,
284
'user_id' => $current_user_id,
288
$link = add_query_arg( 'user_id', $current_user_id, $link );
290
$link = remove_query_arg( 'user_id', $link );
293
if ( ! isset( $num_comments->$status ) ) {
256
294
$num_comments->$status = 10;
257
296
$link = add_query_arg( 'comment_status', $status, $link );
259
298
$link = add_query_arg( 'p', absint( $post_id ), $link );
261
301
// I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
262
302
if ( !empty( $_REQUEST['s'] ) )
265
305
$status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf(
266
306
translate_nooped_plural( $label, $num_comments->$status ),
267
sprintf( '<span class="%s-count">%s</span>',
308
'<span class="%s-count">%s</span>',
268
309
( 'moderated' === $status ) ? 'pending' : $status,
269
310
number_format_i18n( $num_comments->$status )
275
316
* Filters the comment status links.
319
* @since 5.1.0 The 'Mine' link was added.
279
* @param array $status_links An array of fully-formed status links. Default 'All'.
280
* Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'.
321
* @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
322
* 'Pending', 'Approved', 'Spam', and 'Trash'.
282
324
return apply_filters( 'comment_status_links', $status_links );
287
328
* @global string $comment_status
292
333
global $comment_status;
294
335
$actions = array();
295
if ( in_array( $comment_status, array( 'all', 'approved' ) ) )
336
if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) {
296
337
$actions['unapprove'] = __( 'Unapprove' );
297
if ( in_array( $comment_status, array( 'all', 'moderated' ) ) )
339
if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) {
298
340
$actions['approve'] = __( 'Approve' );
299
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) )
342
if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) {
300
343
$actions['spam'] = _x( 'Mark as Spam', 'comment' );
302
346
if ( 'trash' === $comment_status ) {
303
347
$actions['untrash'] = __( 'Restore' );
305
349
$actions['unspam'] = _x( 'Not Spam', 'comment' );
308
if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS )
352
if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || ! EMPTY_TRASH_DAYS ) {
309
353
$actions['delete'] = __( 'Delete Permanently' );
311
355
$actions['trash'] = __( 'Move to Trash' );
318
362
* @global string $comment_status
319
363
* @global string $comment_type
327
371
if ( ! isset( $has_items ) ) {
328
372
$has_items = $this->has_items();
331
375
<div class="alignleft actions">
333
377
if ( 'top' === $which ) {
335
<label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
336
<select id="filter-by-comment-type" name="comment_type">
337
<option value=""><?php _e( 'All comment types' ); ?></option>
379
<label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
380
<select id="filter-by-comment-type" name="comment_type">
381
<option value=""><?php _e( 'All comment types' ); ?></option>
340
384
* Filters the comment types dropdown menu.
344
* @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
388
* @param string[] $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
346
$comment_types = apply_filters( 'admin_comment_types_dropdown', array(
347
'comment' => __( 'Comments' ),
348
'pings' => __( 'Pings' ),
390
$comment_types = apply_filters(
391
'admin_comment_types_dropdown',
393
'comment' => __( 'Comments' ),
394
'pings' => __( 'Pings' ),
351
foreach ( $comment_types as $type => $label )
352
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
398
foreach ( $comment_types as $type => $label ) {
399
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
357
405
* Fires just before the Filter submit button for comment types.
443
491
public function display() {
444
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
492
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
446
494
$this->display_tablenav( 'top' );
448
496
$this->screen->render_screen_reader_content( 'heading_list' );
451
499
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
507
561
unset( $GLOBALS['post'], $GLOBALS['comment'] );
511
* Generate and display row actions links.
515
* @global string $comment_status Status for the current listed comments.
517
* @param WP_Comment $comment The comment object.
518
* @param string $column_name Current column name.
519
* @param string $primary Primary column name.
520
* @return string|void Comment row actions output.
522
protected function handle_row_actions( $comment, $column_name, $primary ) {
523
global $comment_status;
565
* Generate and display row actions links.
569
* @global string $comment_status Status for the current listed comments.
571
* @param WP_Comment $comment The comment object.
572
* @param string $column_name Current column name.
573
* @param string $primary Primary column name.
574
* @return string|void Comment row actions output.
576
protected function handle_row_actions( $comment, $column_name, $primary ) {
577
global $comment_status;
525
579
if ( $primary !== $column_name ) {
529
if ( ! $this->user_can ) {
583
if ( ! $this->user_can ) {
533
587
$the_comment_status = wp_get_comment_status( $comment );
537
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
591
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
538
592
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
540
594
$url = "comment.php?c=$comment->comment_ID";
542
$approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
596
$approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
543
597
$unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
544
$spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
545
$unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
546
$trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
547
$untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
548
$delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
598
$spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
599
$unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
600
$trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
601
$untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
602
$delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
550
604
// Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
551
605
$actions = array(
552
'approve' => '', 'unapprove' => '',
554
609
'quickedit' => '',
556
'spam' => '', 'unspam' => '',
557
'trash' => '', 'untrash' => '', 'delete' => ''
560
618
// Not looking at all comments.
565
623
$actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' class='vim-a vim-destructive' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
568
$actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
626
$actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
569
627
$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
579
637
$actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the Trash' ) . "'>" . __( 'Restore' ) . '</a>';
582
if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || !EMPTY_TRASH_DAYS ) {
640
if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) {
583
641
$actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>';
585
643
$actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
588
646
if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
589
$actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>';
647
$actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>" . __( 'Edit' ) . '</a>';
591
$format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" aria-label="%s" href="#">%s</a>';
649
$format = '<button type="button" data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s button-link" aria-expanded="false" aria-label="%s">%s</button>';
593
651
$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' ) );
598
656
/** This filter is documented in wp-admin/includes/dashboard.php */
599
657
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
602
660
$out .= '<div class="row-actions">';
603
661
foreach ( $actions as $action => $link ) {
605
663
( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
607
665
// Reply and quickedit need a hide-if-no-js span when not added with ajax
608
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() )
666
if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
609
667
$action .= ' hide-if-no-js';
610
elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
611
if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
668
} elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
669
if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
612
670
$action .= ' approve';
614
672
$action .= ' unapprove';
617
676
$out .= "<span class='$action'>$sep$link</span>";
659
718
comment_text( $comment );
660
if ( $this->user_can ) { ?>
720
if ( $this->user_can ) {
721
/** This filter is documented in wp-admin/includes/comment.php */
722
$comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
661
724
<div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
662
<textarea class="comment" rows="1" cols="1"><?php
663
/** This filter is documented in wp-admin/includes/comment.php */
664
echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) );
666
<div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
667
<div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
668
<div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
669
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
725
<textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea>
726
<div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
727
<div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
728
<div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
729
<div class="comment_status"><?php echo $comment->comment_approved; ?></div>
677
736
* @global string $comment_status
679
738
* @param WP_Comment $comment The comment object.
688
747
$author_url_display = wp_html_excerpt( $author_url_display, 49, '…' );
691
echo "<strong>"; comment_author( $comment ); echo '</strong><br />';
751
comment_author( $comment );
752
echo '</strong><br />';
692
753
if ( ! empty( $author_url_display ) ) {
693
754
printf( '<a href="%s">%s</a><br />', esc_url( $author_url ), esc_html( $author_url_display ) );
706
767
$author_ip = get_comment_author_IP( $comment );
707
768
if ( $author_ip ) {
708
$author_ip_url = add_query_arg( array( 's' => $author_ip, 'mode' => 'detail' ), admin_url( 'edit-comments.php' ) );
769
$author_ip_url = add_query_arg(
774
admin_url( 'edit-comments.php' )
709
776
if ( 'spam' === $comment_status ) {
710
777
$author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
719
785
* @param WP_Comment $comment The comment object.
721
787
public function column_date( $comment ) {
722
788
/* translators: 1: comment date, 2: comment time */
723
$submitted = sprintf( __( '%1$s at %2$s' ),
789
$submitted = sprintf(
790
__( '%1$s at %2$s' ),
724
791
/* translators: comment date format. See https://secure.php.net/date */
725
792
get_comment_date( __( 'Y/m/d' ), $comment ),
726
793
get_comment_date( __( 'g:i a' ), $comment )
729
796
echo '<div class="submitted-on">';
730
if ( 'approved' === wp_get_comment_status( $comment ) && ! empty ( $comment->comment_post_ID ) ) {
797
if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
732
799
'<a href="%s">%s</a>',
733
800
esc_url( get_comment_link( $comment ) ),
753
if ( isset( $this->pending_count[$post->ID] ) ) {
754
$pending_comments = $this->pending_count[$post->ID];
819
if ( isset( $this->pending_count[ $post->ID ] ) ) {
820
$pending_comments = $this->pending_count[ $post->ID ];
756
822
$_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
757
$pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
823
$pending_comments = $this->pending_count[ $post->ID ] = $_pending_count_temp[ $post->ID ];
760
826
if ( current_user_can( 'edit_post', $post->ID ) ) {
761
$post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
827
$post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
762
828
$post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
764
830
$post_link = esc_html( get_the_title( $post->ID ) );