| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * List Table API: WP_Comments_List_Table class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 3.1.0 8 */ 9 10 /** 11 * Core class used to implement displaying comments in a list table. 12 * 13 * @since 3.1.0 14 * 15 * @see WP_List_Table 16 */ 17 class WP_Comments_List_Table extends WP_List_Table { 18 19 public $checkbox = true; 20 21 public $pending_count = array(); 22 23 public $extra_items; 24 25 private $user_can; 26 27 /** 28 * Constructor. 29 * 30 * @since 3.1.0 31 * 32 * @see WP_List_Table::__construct() for more information on default arguments. 33 * 34 * @global int $post_id 35 * 36 * @param array $args An associative array of arguments. 37 */ 38 public function __construct( $args = array() ) { 39 global $post_id; 40 41 $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0; 42 43 if ( get_option( 'show_avatars' ) ) { 44 add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 ); 45 } 46 47 parent::__construct( 48 array( 49 'plural' => 'comments', 50 'singular' => 'comment', 51 'ajax' => true, 52 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 53 ) 54 ); 55 } 56 57 /** 58 * Adds avatars to comment author names. 59 * 60 * @since 3.1.0 61 * 62 * @param string $name Comment author name. 63 * @param int $comment_id Comment ID. 64 * @return string Avatar with the user name. 65 */ 66 public function floated_admin_avatar( $name, $comment_id ) { 67 $comment = get_comment( $comment_id ); 68 $avatar = get_avatar( $comment, 32, 'mystery' ); 69 return "$avatar $name"; 70 } 71 72 /** 73 * @return bool 74 */ 75 public function ajax_user_can() { 76 return current_user_can( 'edit_posts' ); 77 } 78 79 /** 80 * @global string $mode List table view mode. 81 * @global int $post_id 82 * @global string $comment_status 83 * @global string $comment_type 84 * @global string $search 85 */ 86 public function prepare_items() { 87 global $mode, $post_id, $comment_status, $comment_type, $search; 88 89 if ( ! empty( $_REQUEST['mode'] ) ) { 90 $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; 91 set_user_setting( 'posts_list_mode', $mode ); 92 } else { 93 $mode = get_user_setting( 'posts_list_mode', 'list' ); 94 } 95 96 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; 97 98 if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ), true ) ) { 99 $comment_status = 'all'; 100 } 101 102 $comment_type = ! empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : ''; 103 104 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; 105 106 $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : ''; 107 108 $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : ''; 109 110 $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : ''; 111 $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : ''; 112 113 $comments_per_page = $this->get_per_page( $comment_status ); 114 115 $doing_ajax = wp_doing_ajax(); 116 117 if ( isset( $_REQUEST['number'] ) ) { 118 $number = (int) $_REQUEST['number']; 119 } else { 120 $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra. 121 } 122 123 $page = $this->get_pagenum(); 124 125 if ( isset( $_REQUEST['start'] ) ) { 126 $start = $_REQUEST['start']; 127 } else { 128 $start = ( $page - 1 ) * $comments_per_page; 129 } 130 131 if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) { 132 $start += $_REQUEST['offset']; 133 } 134 135 $status_map = array( 136 'mine' => '', 137 'moderated' => 'hold', 138 'approved' => 'approve', 139 'all' => '', 140 ); 141 142 $args = array( 143 'status' => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status, 144 'search' => $search, 145 'user_id' => $user_id, 146 'offset' => $start, 147 'number' => $number, 148 'post_id' => $post_id, 149 'type' => $comment_type, 150 'orderby' => $orderby, 151 'order' => $order, 152 'post_type' => $post_type, 153 'update_comment_post_cache' => true, 154 'type__not_in' => array( 'note' ), 155 ); 156 157 /** 158 * Filters the arguments for the comment query in the comments list table. 159 * 160 * @since 5.1.0 161 * 162 * @param array $args An array of get_comments() arguments. 163 */ 164 $args = apply_filters( 'comments_list_table_query_args', $args ); 165 166 $_comments = get_comments( $args ); 167 168 if ( is_array( $_comments ) ) { 169 $this->items = array_slice( $_comments, 0, $comments_per_page ); 170 $this->extra_items = array_slice( $_comments, $comments_per_page ); 171 172 $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) ); 173 174 $this->pending_count = get_pending_comments_num( $_comment_post_ids ); 175 } 176 177 $total_comments = get_comments( 178 array_merge( 179 $args, 180 array( 181 'count' => true, 182 'offset' => 0, 183 'number' => 0, 184 'orderby' => 'none', 185 ) 186 ) 187 ); 188 189 $this->set_pagination_args( 190 array( 191 'total_items' => $total_comments, 192 'per_page' => $comments_per_page, 193 ) 194 ); 195 } 196 197 /** 198 * @param string $comment_status 199 * @return int 200 */ 201 public function get_per_page( $comment_status = 'all' ) { 202 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' ); 203 204 /** 205 * Filters the number of comments listed per page in the comments list table. 206 * 207 * @since 2.6.0 208 * 209 * @param int $comments_per_page The number of comments to list per page. 210 * @param string $comment_status The comment status name. Default 'All'. 211 */ 212 return apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); 213 } 214 215 /** 216 * @global string $comment_status 217 */ 218 public function no_items() { 219 global $comment_status; 220 221 if ( 'moderated' === $comment_status ) { 222 _e( 'No comments awaiting moderation.' ); 223 } elseif ( 'trash' === $comment_status ) { 224 _e( 'No comments found in Trash.' ); 225 } else { 226 _e( 'No comments found.' ); 227 } 228 } 229 230 /** 231 * @global int $post_id 232 * @global string $comment_status 233 * @global string $comment_type 234 */ 235 protected function get_views() { 236 global $post_id, $comment_status, $comment_type; 237 238 $status_links = array(); 239 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); 240 241 $statuses = array( 242 /* translators: %s: Number of comments. */ 243 'all' => _nx_noop( 244 'All <span class="count">(%s)</span>', 245 'All <span class="count">(%s)</span>', 246 'comments' 247 ), // Singular not used. 248 249 /* translators: %s: Number of comments. */ 250 'mine' => _nx_noop( 251 'Mine <span class="count">(%s)</span>', 252 'Mine <span class="count">(%s)</span>', 253 'comments' 254 ), 255 256 /* translators: %s: Number of comments. */ 257 'moderated' => _nx_noop( 258 'Pending <span class="count">(%s)</span>', 259 'Pending <span class="count">(%s)</span>', 260 'comments' 261 ), 262 263 /* translators: %s: Number of comments. */ 264 'approved' => _nx_noop( 265 'Approved <span class="count">(%s)</span>', 266 'Approved <span class="count">(%s)</span>', 267 'comments' 268 ), 269 270 /* translators: %s: Number of comments. */ 271 'spam' => _nx_noop( 272 'Spam <span class="count">(%s)</span>', 273 'Spam <span class="count">(%s)</span>', 274 'comments' 275 ), 276 277 /* translators: %s: Number of comments. */ 278 'trash' => _nx_noop( 279 'Trash <span class="count">(%s)</span>', 280 'Trash <span class="count">(%s)</span>', 281 'comments' 282 ), 283 ); 284 285 if ( ! EMPTY_TRASH_DAYS ) { 286 unset( $statuses['trash'] ); 287 } 288 289 $link = admin_url( 'edit-comments.php' ); 290 291 if ( ! empty( $comment_type ) && 'all' !== $comment_type ) { 292 $link = add_query_arg( 'comment_type', $comment_type, $link ); 293 } 294 295 foreach ( $statuses as $status => $label ) { 296 if ( 'mine' === $status ) { 297 $current_user_id = get_current_user_id(); 298 $num_comments->mine = get_comments( 299 array( 300 'post_id' => $post_id ? $post_id : 0, 301 'user_id' => $current_user_id, 302 'count' => true, 303 'orderby' => 'none', 304 ) 305 ); 306 $link = add_query_arg( 'user_id', $current_user_id, $link ); 307 } else { 308 $link = remove_query_arg( 'user_id', $link ); 309 } 310 311 if ( ! isset( $num_comments->$status ) ) { 312 $num_comments->$status = 10; 313 } 314 315 $link = add_query_arg( 'comment_status', $status, $link ); 316 317 if ( $post_id ) { 318 $link = add_query_arg( 'p', absint( $post_id ), $link ); 319 } 320 321 /* 322 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark 323 if ( !empty( $_REQUEST['s'] ) ) 324 $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); 325 */ 326 327 $status_links[ $status ] = array( 328 'url' => esc_url( $link ), 329 'label' => sprintf( 330 translate_nooped_plural( $label, $num_comments->$status ), 331 sprintf( 332 '<span class="%s-count">%s</span>', 333 ( 'moderated' === $status ) ? 'pending' : $status, 334 number_format_i18n( $num_comments->$status ) 335 ) 336 ), 337 'current' => $status === $comment_status, 338 ); 339 } 340 341 /** 342 * Filters the comment status links. 343 * 344 * @since 2.5.0 345 * @since 5.1.0 The 'Mine' link was added. 346 * 347 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine', 348 * 'Pending', 'Approved', 'Spam', and 'Trash'. 349 */ 350 return apply_filters( 'comment_status_links', $this->get_views_links( $status_links ) ); 351 } 352 353 /** 354 * @global string $comment_status 355 * 356 * @return array 357 */ 358 protected function get_bulk_actions() { 359 global $comment_status; 360 361 if ( ! current_user_can( 'moderate_comments' ) ) { 362 return array(); // Return an empty array if the user doesn't have permission 363 } 364 365 $actions = array(); 366 367 if ( in_array( $comment_status, array( 'all', 'approved' ), true ) ) { 368 $actions['unapprove'] = __( 'Unapprove' ); 369 } 370 371 if ( in_array( $comment_status, array( 'all', 'moderated' ), true ) ) { 372 $actions['approve'] = __( 'Approve' ); 373 } 374 375 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ), true ) ) { 376 $actions['spam'] = _x( 'Mark as spam', 'comment' ); 377 } 378 379 if ( 'trash' === $comment_status ) { 380 $actions['untrash'] = __( 'Restore' ); 381 } elseif ( 'spam' === $comment_status ) { 382 $actions['unspam'] = _x( 'Not spam', 'comment' ); 383 } 384 385 if ( in_array( $comment_status, array( 'trash', 'spam' ), true ) || ! EMPTY_TRASH_DAYS ) { 386 $actions['delete'] = __( 'Delete permanently' ); 387 } else { 388 $actions['trash'] = __( 'Move to Trash' ); 389 } 390 391 return $actions; 392 } 393 394 /** 395 * @global string $comment_status 396 * @global string $comment_type 397 * 398 * @param string $which 399 */ 400 protected function extra_tablenav( $which ) { 401 global $comment_status, $comment_type; 402 static $has_items; 403 404 if ( ! isset( $has_items ) ) { 405 $has_items = $this->has_items(); 406 } 407 408 echo '<div class="alignleft actions">'; 409 410 if ( 'top' === $which ) { 411 ob_start(); 412 413 $this->comment_type_dropdown( $comment_type ); 414 415 /** 416 * Fires just before the Filter submit button for comment types. 417 * 418 * @since 3.5.0 419 */ 420 do_action( 'restrict_manage_comments' ); 421 422 $output = ob_get_clean(); 423 424 if ( ! empty( $output ) && $this->has_items() ) { 425 echo $output; 426 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 427 } 428 } 429 430 if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && $has_items 431 && current_user_can( 'moderate_comments' ) 432 ) { 433 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); 434 $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' ); 435 submit_button( $title, 'apply', 'delete_all', false ); 436 } 437 438 /** 439 * Fires after the Filter submit button for comment types. 440 * 441 * @since 2.5.0 442 * @since 5.6.0 The `$which` parameter was added. 443 * 444 * @param string $comment_status The comment status name. Default 'All'. 445 * @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'. 446 */ 447 do_action( 'manage_comments_nav', $comment_status, $which ); 448 449 echo '</div>'; 450 } 451 452 /** 453 * @return string|false 454 */ 455 public function current_action() { 456 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { 457 return 'delete_all'; 458 } 459 460 return parent::current_action(); 461 } 462 463 /** 464 * @global int $post_id 465 * 466 * @return string[] Array of column titles keyed by their column name. 467 */ 468 public function get_columns() { 469 global $post_id; 470 471 $columns = array(); 472 473 if ( $this->checkbox ) { 474 $columns['cb'] = '<input type="checkbox" />'; 475 } 476 477 $columns['author'] = __( 'Author' ); 478 $columns['comment'] = _x( 'Comment', 'column name' ); 479 480 if ( ! $post_id ) { 481 /* translators: Column name or table row header. */ 482 $columns['response'] = __( 'In response to' ); 483 } 484 485 $columns['date'] = _x( 'Submitted on', 'column name' ); 486 487 return $columns; 488 } 489 490 /** 491 * Displays a comment type drop-down for filtering on the Comments list table. 492 * 493 * @since 5.5.0 494 * @since 5.6.0 Renamed from `comment_status_dropdown()` to `comment_type_dropdown()`. 495 * 496 * @param string $comment_type The current comment type slug. 497 */ 498 protected function comment_type_dropdown( $comment_type ) { 499 /** 500 * Filters the comment types shown in the drop-down menu on the Comments list table. 501 * 502 * @since 2.7.0 503 * 504 * @param string[] $comment_types Array of comment type labels keyed by their name. 505 */ 506 $comment_types = apply_filters( 507 'admin_comment_types_dropdown', 508 array( 509 'comment' => __( 'Comments' ), 510 'pings' => __( 'Pings' ), 511 ) 512 ); 513 514 if ( $comment_types && is_array( $comment_types ) ) { 515 printf( 516 '<label class="screen-reader-text" for="filter-by-comment-type">%s</label>', 517 /* translators: Hidden accessibility text. */ 518 __( 'Filter by comment type' ) 519 ); 520 521 echo '<select id="filter-by-comment-type" name="comment_type">'; 522 523 printf( "\t<option value=''>%s</option>", __( 'All comment types' ) ); 524 525 foreach ( $comment_types as $type => $label ) { 526 if ( get_comments( 527 array( 528 'count' => true, 529 'orderby' => 'none', 530 'type' => $type, 531 ) 532 ) ) { 533 printf( 534 "\t<option value='%s'%s>%s</option>\n", 535 esc_attr( $type ), 536 selected( $comment_type, $type, false ), 537 esc_html( $label ) 538 ); 539 } 540 } 541 542 echo '</select>'; 543 } 544 } 545 546 /** 547 * @return array 548 */ 549 protected function get_sortable_columns() { 550 return array( 551 'author' => array( 'comment_author', false, __( 'Author' ), __( 'Table ordered by Comment Author.' ) ), 552 'response' => array( 'comment_post_ID', false, _x( 'In Response To', 'column name' ), __( 'Table ordered by Post Replied To.' ) ), 553 'date' => 'comment_date', 554 ); 555 } 556 557 /** 558 * Gets the name of the default primary column. 559 * 560 * @since 4.3.0 561 * 562 * @return string Name of the default primary column, in this case, 'comment'. 563 */ 564 protected function get_default_primary_column_name() { 565 return 'comment'; 566 } 567 568 /** 569 * Displays the comments table. 570 * 571 * Overrides the parent display() method to render extra comments. 572 * 573 * @since 3.1.0 574 */ 575 public function display() { 576 wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); 577 static $has_items; 578 579 if ( ! isset( $has_items ) ) { 580 $has_items = $this->has_items(); 581 582 if ( $has_items ) { 583 $this->display_tablenav( 'top' ); 584 } 585 } 586 587 $this->screen->render_screen_reader_content( 'heading_list' ); 588 589 ?> 590 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> 591 <?php 592 if ( ! isset( $_GET['orderby'] ) ) { 593 // In the initial view, Comments are ordered by comment's date but there's no column for that. 594 echo '<caption class="screen-reader-text">' . 595 /* translators: Hidden accessibility text. */ 596 __( 'Ordered by Comment Date, descending.' ) . 597 '</caption>'; 598 } else { 599 $this->print_table_description(); 600 } 601 ?> 602 <thead> 603 <tr> 604 <?php $this->print_column_headers(); ?> 605 </tr> 606 </thead> 607 608 <tbody id="the-comment-list" data-wp-lists="list:comment"> 609 <?php $this->display_rows_or_placeholder(); ?> 610 </tbody> 611 612 <tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;"> 613 <?php 614 /* 615 * Back up the items to restore after printing the extra items markup. 616 * The extra items may be empty, which will prevent the table nav from displaying later. 617 */ 618 $items = $this->items; 619 $this->items = $this->extra_items; 620 $this->display_rows_or_placeholder(); 621 $this->items = $items; 622 ?> 623 </tbody> 624 625 <tfoot> 626 <tr> 627 <?php $this->print_column_headers( false ); ?> 628 </tr> 629 </tfoot> 630 631 </table> 632 <?php 633 634 $this->display_tablenav( 'bottom' ); 635 } 636 637 /** 638 * @global WP_Post $post Global post object. 639 * @global WP_Comment $comment Global comment object. 640 * 641 * @param WP_Comment $item 642 */ 643 public function single_row( $item ) { 644 global $post, $comment; 645 646 // Restores the more descriptive, specific name for use within this method. 647 $comment = $item; 648 649 if ( $comment->comment_post_ID > 0 ) { 650 $post = get_post( $comment->comment_post_ID ); 651 } 652 653 $edit_post_cap = $post ? 'edit_post' : 'edit_posts'; 654 655 if ( ! current_user_can( $edit_post_cap, $comment->comment_post_ID ) 656 && ( post_password_required( $comment->comment_post_ID ) 657 || ! current_user_can( 'read_post', $comment->comment_post_ID ) ) 658 ) { 659 // The user has no access to the post and thus cannot see the comments. 660 return false; 661 } 662 663 $the_comment_class = wp_get_comment_status( $comment ); 664 665 if ( ! $the_comment_class ) { 666 $the_comment_class = ''; 667 } 668 669 $the_comment_class = implode( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) ); 670 671 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); 672 673 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; 674 $this->single_row_columns( $comment ); 675 echo "</tr>\n"; 676 677 unset( $GLOBALS['post'], $GLOBALS['comment'] ); 678 } 679 680 /** 681 * Generates and displays row actions links. 682 * 683 * @since 4.3.0 684 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. 685 * 686 * @global string $comment_status Status for the current listed comments. 687 * 688 * @param WP_Comment $item The comment object. 689 * @param string $column_name Current column name. 690 * @param string $primary Primary column name. 691 * @return string Row actions output for comments. An empty string 692 * if the current column is not the primary column, 693 * or if the current user cannot edit the comment. 694 */ 695 protected function handle_row_actions( $item, $column_name, $primary ) { 696 global $comment_status; 697 698 if ( $primary !== $column_name ) { 699 return ''; 700 } 701 702 if ( ! $this->user_can ) { 703 return ''; 704 } 705 706 // Restores the more descriptive, specific name for use within this method. 707 $comment = $item; 708 709 $the_comment_status = wp_get_comment_status( $comment ); 710 711 $output = ''; 712 713 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'approve-comment_' . $comment->comment_ID ) ); 714 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) ); 715 716 $action_string = 'comment.php?action=%s&c=' . $comment->comment_ID . '&%s'; 717 718 $approve_url = sprintf( $action_string, 'approvecomment', $approve_nonce ); 719 $unapprove_url = sprintf( $action_string, 'unapprovecomment', $approve_nonce ); 720 $spam_url = sprintf( $action_string, 'spamcomment', $del_nonce ); 721 $unspam_url = sprintf( $action_string, 'unspamcomment', $del_nonce ); 722 $trash_url = sprintf( $action_string, 'trashcomment', $del_nonce ); 723 $untrash_url = sprintf( $action_string, 'untrashcomment', $del_nonce ); 724 $delete_url = sprintf( $action_string, 'deletecomment', $del_nonce ); 725 726 // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash. 727 $actions = array( 728 'approve' => '', 729 'unapprove' => '', 730 'reply' => '', 731 'quickedit' => '', 732 'edit' => '', 733 'spam' => '', 734 'unspam' => '', 735 'trash' => '', 736 'untrash' => '', 737 'delete' => '', 738 ); 739 740 // Not looking at all comments. 741 if ( $comment_status && 'all' !== $comment_status ) { 742 if ( 'approved' === $the_comment_status ) { 743 $actions['unapprove'] = sprintf( 744 '<a href="%s" data-wp-lists="%s" class="vim-u vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 745 esc_url( $unapprove_url ), 746 "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=unapproved", 747 esc_attr__( 'Unapprove this comment' ), 748 __( 'Unapprove' ) 749 ); 750 } elseif ( 'unapproved' === $the_comment_status ) { 751 $actions['approve'] = sprintf( 752 '<a href="%s" data-wp-lists="%s" class="vim-a vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 753 esc_url( $approve_url ), 754 "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=approved", 755 esc_attr__( 'Approve this comment' ), 756 __( 'Approve' ) 757 ); 758 } 759 } else { 760 $actions['approve'] = sprintf( 761 '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>', 762 esc_url( $approve_url ), 763 "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved", 764 esc_attr__( 'Approve this comment' ), 765 __( 'Approve' ) 766 ); 767 768 $actions['unapprove'] = sprintf( 769 '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>', 770 esc_url( $unapprove_url ), 771 "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved", 772 esc_attr__( 'Unapprove this comment' ), 773 __( 'Unapprove' ) 774 ); 775 } 776 777 if ( 'spam' !== $the_comment_status ) { 778 $actions['spam'] = sprintf( 779 '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 780 esc_url( $spam_url ), 781 "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1", 782 esc_attr__( 'Mark this comment as spam' ), 783 /* translators: "Mark as spam" link. */ 784 _x( 'Spam', 'verb' ) 785 ); 786 } elseif ( 'spam' === $the_comment_status ) { 787 $actions['unspam'] = sprintf( 788 '<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 789 esc_url( $unspam_url ), 790 "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1", 791 esc_attr__( 'Restore this comment from the spam' ), 792 _x( 'Not Spam', 'comment' ) 793 ); 794 } 795 796 if ( 'trash' === $the_comment_status ) { 797 $actions['untrash'] = sprintf( 798 '<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 799 esc_url( $untrash_url ), 800 "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1", 801 esc_attr__( 'Restore this comment from the Trash' ), 802 __( 'Restore' ) 803 ); 804 } 805 806 if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) { 807 $actions['delete'] = sprintf( 808 '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 809 esc_url( $delete_url ), 810 "delete:the-comment-list:comment-{$comment->comment_ID}::delete=1", 811 esc_attr__( 'Delete this comment permanently' ), 812 __( 'Delete Permanently' ) 813 ); 814 } else { 815 $actions['trash'] = sprintf( 816 '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 817 esc_url( $trash_url ), 818 "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1", 819 esc_attr__( 'Move this comment to the Trash' ), 820 _x( 'Trash', 'verb' ) 821 ); 822 } 823 824 if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) { 825 $actions['edit'] = sprintf( 826 '<a href="%s" aria-label="%s">%s</a>', 827 "comment.php?action=editcomment&c={$comment->comment_ID}", 828 esc_attr__( 'Edit this comment' ), 829 __( 'Edit' ) 830 ); 831 832 $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>'; 833 834 $actions['quickedit'] = sprintf( 835 $format, 836 $comment->comment_ID, 837 $comment->comment_post_ID, 838 'edit', 839 'vim-q comment-inline', 840 esc_attr__( 'Quick edit this comment inline' ), 841 __( 'Quick Edit' ) 842 ); 843 844 $actions['reply'] = sprintf( 845 $format, 846 $comment->comment_ID, 847 $comment->comment_post_ID, 848 'replyto', 849 'vim-r comment-inline', 850 esc_attr__( 'Reply to this comment' ), 851 __( 'Reply' ) 852 ); 853 } 854 855 /** 856 * Filters the action links displayed for each comment in the Comments list table. 857 * 858 * @since 2.6.0 859 * 860 * @param string[] $actions An array of comment actions. Default actions include: 861 * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam', 862 * 'Delete', and 'Trash'. 863 * @param WP_Comment $comment The comment object. 864 */ 865 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); 866 867 $always_visible = false; 868 869 $mode = get_user_setting( 'posts_list_mode', 'list' ); 870 871 if ( 'excerpt' === $mode ) { 872 $always_visible = true; 873 } 874 875 $output .= '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; 876 877 $i = 0; 878 879 foreach ( $actions as $action => $link ) { 880 ++$i; 881 882 if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) 883 || 1 === $i 884 ) { 885 $separator = ''; 886 } else { 887 $separator = ' | '; 888 } 889 890 // Reply and quickedit need a hide-if-no-js span when not added with Ajax. 891 if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) { 892 $action .= ' hide-if-no-js'; 893 } elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status ) 894 || ( 'unspam' === $action && 'spam' === $the_comment_status ) 895 ) { 896 if ( '1' === get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) { 897 $action .= ' approve'; 898 } else { 899 $action .= ' unapprove'; 900 } 901 } 902 903 $output .= "<span class='$action'>{$separator}{$link}</span>"; 904 } 905 906 $output .= '</div>'; 907 908 $output .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . 909 /* translators: Hidden accessibility text. */ 910 __( 'Show more details' ) . 911 '</span></button>'; 912 913 return $output; 914 } 915 916 /** 917 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. 918 * 919 * @param WP_Comment $item The comment object. 920 */ 921 public function column_cb( $item ) { 922 // Restores the more descriptive, specific name for use within this method. 923 $comment = $item; 924 925 if ( $this->user_can ) { 926 ?> 927 <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> 928 <label for="cb-select-<?php echo $comment->comment_ID; ?>"> 929 <span class="screen-reader-text"> 930 <?php 931 /* translators: Hidden accessibility text. */ 932 _e( 'Select comment' ); 933 ?> 934 </span> 935 </label> 936 <?php 937 } 938 } 939 940 /** 941 * @param WP_Comment $comment The comment object. 942 */ 943 public function column_comment( $comment ) { 944 echo '<div class="comment-author">'; 945 $this->column_author( $comment ); 946 echo '</div>'; 947 948 if ( $comment->comment_parent ) { 949 $parent = get_comment( $comment->comment_parent ); 950 951 if ( $parent ) { 952 $parent_link = esc_url( get_comment_link( $parent ) ); 953 $name = get_comment_author( $parent ); 954 printf( 955 /* translators: %s: Comment link. */ 956 __( 'In reply to %s.' ), 957 '<a href="' . $parent_link . '">' . $name . '</a>' 958 ); 959 } 960 } 961 962 comment_text( $comment ); 963 964 if ( $this->user_can ) { 965 /** This filter is documented in wp-admin/includes/comment.php */ 966 $comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content ); 967 ?> 968 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> 969 <textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea> 970 <div class="author-email"><?php echo esc_html( $comment->comment_author_email ); ?></div> 971 <div class="author"><?php echo esc_html( $comment->comment_author ); ?></div> 972 <div class="author-url"><?php echo esc_url( $comment->comment_author_url ); ?></div> 973 <div class="comment_status"><?php echo $comment->comment_approved; ?></div> 974 </div> 975 <?php 976 } 977 } 978 979 /** 980 * @global string $comment_status 981 * 982 * @param WP_Comment $comment The comment object. 983 */ 984 public function column_author( $comment ) { 985 global $comment_status; 986 987 $author_url = get_comment_author_url( $comment ); 988 989 $author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) ); 990 991 if ( strlen( $author_url_display ) > 50 ) { 992 $author_url_display = wp_html_excerpt( $author_url_display, 49, '…' ); 993 } 994 995 echo '<strong>'; 996 comment_author( $comment ); 997 echo '</strong><br />'; 998 999 if ( ! empty( $author_url_display ) ) { 1000 // Print link to author URL, and disallow referrer information (without using target="_blank"). 1001 printf( 1002 '<a href="%s" rel="noopener noreferrer">%s</a><br />', 1003 esc_url( $author_url ), 1004 esc_html( $author_url_display ) 1005 ); 1006 } 1007 1008 if ( $this->user_can ) { 1009 if ( ! empty( $comment->comment_author_email ) ) { 1010 /** This filter is documented in wp-includes/comment-template.php */ 1011 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); 1012 1013 if ( ! empty( $email ) && '@' !== $email ) { 1014 printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) ); 1015 } 1016 } 1017 1018 $author_ip = get_comment_author_IP( $comment ); 1019 1020 if ( $author_ip ) { 1021 $author_ip_url = add_query_arg( 1022 array( 1023 's' => $author_ip, 1024 'mode' => 'detail', 1025 ), 1026 admin_url( 'edit-comments.php' ) 1027 ); 1028 1029 if ( 'spam' === $comment_status ) { 1030 $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url ); 1031 } 1032 1033 printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) ); 1034 } 1035 } 1036 } 1037 1038 /** 1039 * @param WP_Comment $comment The comment object. 1040 */ 1041 public function column_date( $comment ) { 1042 $submitted = sprintf( 1043 /* translators: 1: Comment date, 2: Comment time. */ 1044 __( '%1$s at %2$s' ), 1045 /* translators: Comment date format. See https://www.php.net/manual/datetime.format.php */ 1046 get_comment_date( __( 'Y/m/d' ), $comment ), 1047 /* translators: Comment time format. See https://www.php.net/manual/datetime.format.php */ 1048 get_comment_date( __( 'g:i a' ), $comment ) 1049 ); 1050 1051 echo '<div class="submitted-on">'; 1052 1053 if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) { 1054 printf( 1055 '<a href="%s">%s</a>', 1056 esc_url( get_comment_link( $comment ) ), 1057 $submitted 1058 ); 1059 } else { 1060 echo $submitted; 1061 } 1062 1063 echo '</div>'; 1064 } 1065 1066 /** 1067 * @param WP_Comment $comment The comment object. 1068 */ 1069 public function column_response( $comment ) { 1070 $post = get_post(); 1071 1072 if ( ! $post ) { 1073 return; 1074 } 1075 1076 if ( isset( $this->pending_count[ $post->ID ] ) ) { 1077 $pending_comments = $this->pending_count[ $post->ID ]; 1078 } else { 1079 $_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); 1080 $pending_comments = $_pending_count_temp[ $post->ID ]; 1081 $this->pending_count[ $post->ID ] = $pending_comments; 1082 } 1083 1084 if ( current_user_can( 'edit_post', $post->ID ) ) { 1085 $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>"; 1086 $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>'; 1087 } else { 1088 $post_link = esc_html( get_the_title( $post->ID ) ); 1089 } 1090 1091 echo '<div class="response-links">'; 1092 1093 if ( 'attachment' === $post->post_type ) { 1094 $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ); 1095 if ( $thumb ) { 1096 echo $thumb; 1097 } 1098 } 1099 1100 echo $post_link; 1101 1102 $post_type_object = get_post_type_object( $post->post_type ); 1103 echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>'; 1104 1105 echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">'; 1106 $this->comments_bubble( $post->ID, $pending_comments ); 1107 echo '</span> '; 1108 1109 echo '</div>'; 1110 } 1111 1112 /** 1113 * @since 5.9.0 Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. 1114 * 1115 * @param WP_Comment $item The comment object. 1116 * @param string $column_name The custom column's name. 1117 */ 1118 public function column_default( $item, $column_name ) { 1119 // Restores the more descriptive, specific name for use within this method. 1120 $comment = $item; 1121 1122 /** 1123 * Fires when the default column output is displayed for a single row. 1124 * 1125 * @since 2.8.0 1126 * 1127 * @param string $column_name The custom column's name. 1128 * @param string $comment_id The comment ID as a numeric string. 1129 */ 1130 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); 1131 } 1132 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Oct 30 08:20:06 2025 | Cross-referenced by PHPXref |