139 'approved' => 'approve', |
138 'approved' => 'approve', |
140 'all' => '', |
139 'all' => '', |
141 ); |
140 ); |
142 |
141 |
143 $args = array( |
142 $args = array( |
144 'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status, |
143 'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status, |
145 'search' => $search, |
144 'search' => $search, |
146 'user_id' => $user_id, |
145 'user_id' => $user_id, |
147 'offset' => $start, |
146 'offset' => $start, |
148 'number' => $number, |
147 'number' => $number, |
149 'post_id' => $post_id, |
148 'post_id' => $post_id, |
150 'type' => $comment_type, |
149 'type' => $comment_type, |
151 'orderby' => $orderby, |
150 'orderby' => $orderby, |
152 'order' => $order, |
151 'order' => $order, |
153 'post_type' => $post_type, |
152 'post_type' => $post_type, |
|
153 'update_comment_post_cache' => true, |
154 ); |
154 ); |
155 |
155 |
156 /** |
156 /** |
157 * Filters the arguments for the comment query in the comments list table. |
157 * Filters the arguments for the comment query in the comments list table. |
158 * |
158 * |
163 $args = apply_filters( 'comments_list_table_query_args', $args ); |
163 $args = apply_filters( 'comments_list_table_query_args', $args ); |
164 |
164 |
165 $_comments = get_comments( $args ); |
165 $_comments = get_comments( $args ); |
166 |
166 |
167 if ( is_array( $_comments ) ) { |
167 if ( is_array( $_comments ) ) { |
168 update_comment_cache( $_comments ); |
|
169 |
|
170 $this->items = array_slice( $_comments, 0, $comments_per_page ); |
168 $this->items = array_slice( $_comments, 0, $comments_per_page ); |
171 $this->extra_items = array_slice( $_comments, $comments_per_page ); |
169 $this->extra_items = array_slice( $_comments, $comments_per_page ); |
172 |
170 |
173 $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) ); |
171 $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) ); |
174 |
172 |
236 global $post_id, $comment_status, $comment_type; |
235 global $post_id, $comment_status, $comment_type; |
237 |
236 |
238 $status_links = array(); |
237 $status_links = array(); |
239 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); |
238 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); |
240 |
239 |
241 $stati = array( |
240 $statuses = array( |
242 /* translators: %s: Number of comments. */ |
241 /* translators: %s: Number of comments. */ |
243 'all' => _nx_noop( |
242 'all' => _nx_noop( |
244 'All <span class="count">(%s)</span>', |
243 'All <span class="count">(%s)</span>', |
245 'All <span class="count">(%s)</span>', |
244 'All <span class="count">(%s)</span>', |
246 'comments' |
245 'comments' |
281 'comments' |
280 'comments' |
282 ), |
281 ), |
283 ); |
282 ); |
284 |
283 |
285 if ( ! EMPTY_TRASH_DAYS ) { |
284 if ( ! EMPTY_TRASH_DAYS ) { |
286 unset( $stati['trash'] ); |
285 unset( $statuses['trash'] ); |
287 } |
286 } |
288 |
287 |
289 $link = admin_url( 'edit-comments.php' ); |
288 $link = admin_url( 'edit-comments.php' ); |
290 |
289 |
291 if ( ! empty( $comment_type ) && 'all' !== $comment_type ) { |
290 if ( ! empty( $comment_type ) && 'all' !== $comment_type ) { |
292 $link = add_query_arg( 'comment_type', $comment_type, $link ); |
291 $link = add_query_arg( 'comment_type', $comment_type, $link ); |
293 } |
292 } |
294 |
293 |
295 foreach ( $stati as $status => $label ) { |
294 foreach ( $statuses as $status => $label ) { |
296 $current_link_attributes = ''; |
|
297 |
|
298 if ( $status === $comment_status ) { |
|
299 $current_link_attributes = ' class="current" aria-current="page"'; |
|
300 } |
|
301 |
|
302 if ( 'mine' === $status ) { |
295 if ( 'mine' === $status ) { |
303 $current_user_id = get_current_user_id(); |
296 $current_user_id = get_current_user_id(); |
304 $num_comments->mine = get_comments( |
297 $num_comments->mine = get_comments( |
305 array( |
298 array( |
306 'post_id' => $post_id ? $post_id : 0, |
299 'post_id' => $post_id ? $post_id : 0, |
307 'user_id' => $current_user_id, |
300 'user_id' => $current_user_id, |
308 'count' => true, |
301 'count' => true, |
|
302 'orderby' => 'none', |
309 ) |
303 ) |
310 ); |
304 ); |
311 $link = add_query_arg( 'user_id', $current_user_id, $link ); |
305 $link = add_query_arg( 'user_id', $current_user_id, $link ); |
312 } else { |
306 } else { |
313 $link = remove_query_arg( 'user_id', $link ); |
307 $link = remove_query_arg( 'user_id', $link ); |
327 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark |
321 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark |
328 if ( !empty( $_REQUEST['s'] ) ) |
322 if ( !empty( $_REQUEST['s'] ) ) |
329 $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); |
323 $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); |
330 */ |
324 */ |
331 |
325 |
332 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf( |
326 $status_links[ $status ] = array( |
333 translate_nooped_plural( $label, $num_comments->$status ), |
327 'url' => esc_url( $link ), |
334 sprintf( |
328 'label' => sprintf( |
335 '<span class="%s-count">%s</span>', |
329 translate_nooped_plural( $label, $num_comments->$status ), |
336 ( 'moderated' === $status ) ? 'pending' : $status, |
330 sprintf( |
337 number_format_i18n( $num_comments->$status ) |
331 '<span class="%s-count">%s</span>', |
338 ) |
332 ( 'moderated' === $status ) ? 'pending' : $status, |
339 ) . '</a>'; |
333 number_format_i18n( $num_comments->$status ) |
|
334 ) |
|
335 ), |
|
336 'current' => $status === $comment_status, |
|
337 ); |
340 } |
338 } |
341 |
339 |
342 /** |
340 /** |
343 * Filters the comment status links. |
341 * Filters the comment status links. |
344 * |
342 * |
346 * @since 5.1.0 The 'Mine' link was added. |
344 * @since 5.1.0 The 'Mine' link was added. |
347 * |
345 * |
348 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine', |
346 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine', |
349 * 'Pending', 'Approved', 'Spam', and 'Trash'. |
347 * 'Pending', 'Approved', 'Spam', and 'Trash'. |
350 */ |
348 */ |
351 return apply_filters( 'comment_status_links', $status_links ); |
349 return apply_filters( 'comment_status_links', $this->get_views_links( $status_links ) ); |
352 } |
350 } |
353 |
351 |
354 /** |
352 /** |
355 * @global string $comment_status |
353 * @global string $comment_status |
356 * |
354 * |
437 * |
435 * |
438 * @since 2.5.0 |
436 * @since 2.5.0 |
439 * @since 5.6.0 The `$which` parameter was added. |
437 * @since 5.6.0 The `$which` parameter was added. |
440 * |
438 * |
441 * @param string $comment_status The comment status name. Default 'All'. |
439 * @param string $comment_status The comment status name. Default 'All'. |
442 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
440 * @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'. |
443 */ |
441 */ |
444 do_action( 'manage_comments_nav', $comment_status, $which ); |
442 do_action( 'manage_comments_nav', $comment_status, $which ); |
445 |
443 |
446 echo '</div>'; |
444 echo '</div>'; |
447 } |
445 } |
507 'pings' => __( 'Pings' ), |
505 'pings' => __( 'Pings' ), |
508 ) |
506 ) |
509 ); |
507 ); |
510 |
508 |
511 if ( $comment_types && is_array( $comment_types ) ) { |
509 if ( $comment_types && is_array( $comment_types ) ) { |
512 printf( '<label class="screen-reader-text" for="filter-by-comment-type">%s</label>', __( 'Filter by comment type' ) ); |
510 printf( |
|
511 '<label class="screen-reader-text" for="filter-by-comment-type">%s</label>', |
|
512 /* translators: Hidden accessibility text. */ |
|
513 __( 'Filter by comment type' ) |
|
514 ); |
513 |
515 |
514 echo '<select id="filter-by-comment-type" name="comment_type">'; |
516 echo '<select id="filter-by-comment-type" name="comment_type">'; |
515 |
517 |
516 printf( "\t<option value=''>%s</option>", __( 'All comment types' ) ); |
518 printf( "\t<option value=''>%s</option>", __( 'All comment types' ) ); |
517 |
519 |
518 foreach ( $comment_types as $type => $label ) { |
520 foreach ( $comment_types as $type => $label ) { |
519 if ( get_comments( |
521 if ( get_comments( |
520 array( |
522 array( |
521 'number' => 1, |
523 'count' => true, |
522 'type' => $type, |
524 'orderby' => 'none', |
|
525 'type' => $type, |
523 ) |
526 ) |
524 ) ) { |
527 ) ) { |
525 printf( |
528 printf( |
526 "\t<option value='%s'%s>%s</option>\n", |
529 "\t<option value='%s'%s>%s</option>\n", |
527 esc_attr( $type ), |
530 esc_attr( $type ), |
538 /** |
541 /** |
539 * @return array |
542 * @return array |
540 */ |
543 */ |
541 protected function get_sortable_columns() { |
544 protected function get_sortable_columns() { |
542 return array( |
545 return array( |
543 'author' => 'comment_author', |
546 'author' => array( 'comment_author', false, __( 'Author' ), __( 'Table ordered by Comment Author.' ) ), |
544 'response' => 'comment_post_ID', |
547 'response' => array( 'comment_post_ID', false, _x( 'In Response To', 'column name' ), __( 'Table ordered by Post Replied To.' ) ), |
545 'date' => 'comment_date', |
548 'date' => 'comment_date', |
546 ); |
549 ); |
547 } |
550 } |
548 |
551 |
549 /** |
552 /** |
550 * Get the name of the default primary column. |
553 * Gets the name of the default primary column. |
551 * |
554 * |
552 * @since 4.3.0 |
555 * @since 4.3.0 |
553 * |
556 * |
554 * @return string Name of the default primary column, in this case, 'comment'. |
557 * @return string Name of the default primary column, in this case, 'comment'. |
555 */ |
558 */ |
578 |
581 |
579 $this->screen->render_screen_reader_content( 'heading_list' ); |
582 $this->screen->render_screen_reader_content( 'heading_list' ); |
580 |
583 |
581 ?> |
584 ?> |
582 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> |
585 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> |
|
586 <?php |
|
587 if ( ! isset( $_GET['orderby'] ) ) { |
|
588 // In the initial view, Comments are ordered by comment's date but there's no column for that. |
|
589 echo '<caption class="screen-reader-text">' . |
|
590 /* translators: Hidden accessibility text. */ |
|
591 __( 'Ordered by Comment Date, descending.' ) . |
|
592 '</caption>'; |
|
593 } else { |
|
594 $this->print_table_description(); |
|
595 } |
|
596 ?> |
583 <thead> |
597 <thead> |
584 <tr> |
598 <tr> |
585 <?php $this->print_column_headers(); ?> |
599 <?php $this->print_column_headers(); ?> |
586 </tr> |
600 </tr> |
587 </thead> |
601 </thead> |
622 * @param WP_Comment $item |
636 * @param WP_Comment $item |
623 */ |
637 */ |
624 public function single_row( $item ) { |
638 public function single_row( $item ) { |
625 global $post, $comment; |
639 global $post, $comment; |
626 |
640 |
|
641 // Restores the more descriptive, specific name for use within this method. |
627 $comment = $item; |
642 $comment = $item; |
|
643 |
|
644 if ( $comment->comment_post_ID > 0 ) { |
|
645 $post = get_post( $comment->comment_post_ID ); |
|
646 } |
|
647 |
|
648 $edit_post_cap = $post ? 'edit_post' : 'edit_posts'; |
|
649 |
|
650 if ( ! current_user_can( $edit_post_cap, $comment->comment_post_ID ) |
|
651 && ( post_password_required( $comment->comment_post_ID ) |
|
652 || ! current_user_can( 'read_post', $comment->comment_post_ID ) ) |
|
653 ) { |
|
654 // The user has no access to the post and thus cannot see the comments. |
|
655 return false; |
|
656 } |
628 |
657 |
629 $the_comment_class = wp_get_comment_status( $comment ); |
658 $the_comment_class = wp_get_comment_status( $comment ); |
630 |
659 |
631 if ( ! $the_comment_class ) { |
660 if ( ! $the_comment_class ) { |
632 $the_comment_class = ''; |
661 $the_comment_class = ''; |
633 } |
662 } |
634 |
663 |
635 $the_comment_class = implode( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) ); |
664 $the_comment_class = implode( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) ); |
636 |
|
637 if ( $comment->comment_post_ID > 0 ) { |
|
638 $post = get_post( $comment->comment_post_ID ); |
|
639 } |
|
640 |
665 |
641 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); |
666 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); |
642 |
667 |
643 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; |
668 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; |
644 $this->single_row_columns( $comment ); |
669 $this->single_row_columns( $comment ); |
646 |
671 |
647 unset( $GLOBALS['post'], $GLOBALS['comment'] ); |
672 unset( $GLOBALS['post'], $GLOBALS['comment'] ); |
648 } |
673 } |
649 |
674 |
650 /** |
675 /** |
651 * Generate and display row actions links. |
676 * Generates and displays row actions links. |
652 * |
677 * |
653 * @since 4.3.0 |
678 * @since 4.3.0 |
654 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. |
679 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. |
655 * |
680 * |
656 * @global string $comment_status Status for the current listed comments. |
681 * @global string $comment_status Status for the current listed comments. |
672 if ( ! $this->user_can ) { |
697 if ( ! $this->user_can ) { |
673 return ''; |
698 return ''; |
674 } |
699 } |
675 |
700 |
676 // Restores the more descriptive, specific name for use within this method. |
701 // Restores the more descriptive, specific name for use within this method. |
677 $comment = $item; |
702 $comment = $item; |
|
703 |
678 $the_comment_status = wp_get_comment_status( $comment ); |
704 $the_comment_status = wp_get_comment_status( $comment ); |
679 |
705 |
680 $out = ''; |
706 $output = ''; |
681 |
707 |
682 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); |
708 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); |
683 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); |
709 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); |
684 |
710 |
685 $url = "comment.php?c=$comment->comment_ID"; |
711 $url = "comment.php?c=$comment->comment_ID"; |
830 |
856 |
831 if ( 'excerpt' === $mode ) { |
857 if ( 'excerpt' === $mode ) { |
832 $always_visible = true; |
858 $always_visible = true; |
833 } |
859 } |
834 |
860 |
835 $out .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; |
861 $output .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; |
836 |
862 |
837 $i = 0; |
863 $i = 0; |
838 |
864 |
839 foreach ( $actions as $action => $link ) { |
865 foreach ( $actions as $action => $link ) { |
840 ++$i; |
866 ++$i; |
841 |
867 |
842 if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) |
868 if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) |
843 || 1 === $i |
869 || 1 === $i |
844 ) { |
870 ) { |
845 $sep = ''; |
871 $separator = ''; |
846 } else { |
872 } else { |
847 $sep = ' | '; |
873 $separator = ' | '; |
848 } |
874 } |
849 |
875 |
850 // Reply and quickedit need a hide-if-no-js span when not added with Ajax. |
876 // Reply and quickedit need a hide-if-no-js span when not added with Ajax. |
851 if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) { |
877 if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) { |
852 $action .= ' hide-if-no-js'; |
878 $action .= ' hide-if-no-js'; |
858 } else { |
884 } else { |
859 $action .= ' unapprove'; |
885 $action .= ' unapprove'; |
860 } |
886 } |
861 } |
887 } |
862 |
888 |
863 $out .= "<span class='$action'>$sep$link</span>"; |
889 $output .= "<span class='$action'>{$separator}{$link}</span>"; |
864 } |
890 } |
865 |
891 |
866 $out .= '</div>'; |
892 $output .= '</div>'; |
867 |
893 |
868 $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>'; |
894 $output .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . |
869 |
895 /* translators: Hidden accessibility text. */ |
870 return $out; |
896 __( 'Show more details' ) . |
|
897 '</span></button>'; |
|
898 |
|
899 return $output; |
871 } |
900 } |
872 |
901 |
873 /** |
902 /** |
874 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. |
903 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. |
875 * |
904 * |
879 // Restores the more descriptive, specific name for use within this method. |
908 // Restores the more descriptive, specific name for use within this method. |
880 $comment = $item; |
909 $comment = $item; |
881 |
910 |
882 if ( $this->user_can ) { |
911 if ( $this->user_can ) { |
883 ?> |
912 ?> |
884 <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label> |
|
885 <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> |
913 <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> |
|
914 <label for="cb-select-<?php echo $comment->comment_ID; ?>"> |
|
915 <span class="screen-reader-text"> |
|
916 <?php |
|
917 /* translators: Hidden accessibility text. */ |
|
918 _e( 'Select comment' ); |
|
919 ?> |
|
920 </span> |
|
921 </label> |
886 <?php |
922 <?php |
887 } |
923 } |
888 } |
924 } |
889 |
925 |
890 /** |
926 /** |
915 /** This filter is documented in wp-admin/includes/comment.php */ |
951 /** This filter is documented in wp-admin/includes/comment.php */ |
916 $comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content ); |
952 $comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content ); |
917 ?> |
953 ?> |
918 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> |
954 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> |
919 <textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea> |
955 <textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea> |
920 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div> |
956 <div class="author-email"><?php echo esc_html( $comment->comment_author_email ); ?></div> |
921 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div> |
957 <div class="author"><?php echo esc_html( $comment->comment_author ); ?></div> |
922 <div class="author-url"><?php echo esc_url( $comment->comment_author_url ); ?></div> |
958 <div class="author-url"><?php echo esc_url( $comment->comment_author_url ); ?></div> |
923 <div class="comment_status"><?php echo $comment->comment_approved; ?></div> |
959 <div class="comment_status"><?php echo $comment->comment_approved; ?></div> |
924 </div> |
960 </div> |
925 <?php |
961 <?php |
926 } |
962 } |
1064 * |
1100 * |
1065 * @param WP_Comment $item The comment object. |
1101 * @param WP_Comment $item The comment object. |
1066 * @param string $column_name The custom column's name. |
1102 * @param string $column_name The custom column's name. |
1067 */ |
1103 */ |
1068 public function column_default( $item, $column_name ) { |
1104 public function column_default( $item, $column_name ) { |
|
1105 // Restores the more descriptive, specific name for use within this method. |
|
1106 $comment = $item; |
|
1107 |
1069 /** |
1108 /** |
1070 * Fires when the default column output is displayed for a single row. |
1109 * Fires when the default column output is displayed for a single row. |
1071 * |
1110 * |
1072 * @since 2.8.0 |
1111 * @since 2.8.0 |
1073 * |
1112 * |
1074 * @param string $column_name The custom column's name. |
1113 * @param string $column_name The custom column's name. |
1075 * @param string $comment_id The comment ID as a numeric string. |
1114 * @param string $comment_id The comment ID as a numeric string. |
1076 */ |
1115 */ |
1077 do_action( 'manage_comments_custom_column', $column_name, $item->comment_ID ); |
1116 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); |
1078 } |
1117 } |
1079 } |
1118 } |