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