[ Index ]

WordPress 5.4.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/wp-admin/includes/ -> class-wp-comments-list-table.php (source)

   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  	public function floated_admin_avatar( $name, $comment_ID ) {
  59          $comment = get_comment( $comment_ID );
  60          $avatar  = get_avatar( $comment, 32, 'mystery' );
  61          return "$avatar $name";
  62      }
  63  
  64      /**
  65       * @return bool
  66       */
  67  	public function ajax_user_can() {
  68          return current_user_can( 'edit_posts' );
  69      }
  70  
  71      /**
  72       * @global int    $post_id
  73       * @global string $comment_status
  74       * @global string $search
  75       * @global string $comment_type
  76       */
  77  	public function prepare_items() {
  78          global $post_id, $comment_status, $search, $comment_type;
  79  
  80          $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
  81          if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
  82              $comment_status = 'all';
  83          }
  84  
  85          $comment_type = ! empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
  86  
  87          $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
  88  
  89          $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : '';
  90  
  91          $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
  92  
  93          $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
  94          $order   = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
  95  
  96          $comments_per_page = $this->get_per_page( $comment_status );
  97  
  98          $doing_ajax = wp_doing_ajax();
  99  
 100          if ( isset( $_REQUEST['number'] ) ) {
 101              $number = (int) $_REQUEST['number'];
 102          } else {
 103              $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra.
 104          }
 105  
 106          $page = $this->get_pagenum();
 107  
 108          if ( isset( $_REQUEST['start'] ) ) {
 109              $start = $_REQUEST['start'];
 110          } else {
 111              $start = ( $page - 1 ) * $comments_per_page;
 112          }
 113  
 114          if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
 115              $start += $_REQUEST['offset'];
 116          }
 117  
 118          $status_map = array(
 119              'mine'      => '',
 120              'moderated' => 'hold',
 121              'approved'  => 'approve',
 122              'all'       => '',
 123          );
 124  
 125          $args = array(
 126              'status'    => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status,
 127              'search'    => $search,
 128              'user_id'   => $user_id,
 129              'offset'    => $start,
 130              'number'    => $number,
 131              'post_id'   => $post_id,
 132              'type'      => $comment_type,
 133              'orderby'   => $orderby,
 134              'order'     => $order,
 135              'post_type' => $post_type,
 136          );
 137  
 138          /**
 139           * Filters the arguments for the comment query in the comments list table.
 140           *
 141           * @since 5.1.0
 142           *
 143           * @param array $args An array of get_comments() arguments.
 144           */
 145          $args = apply_filters( 'comments_list_table_query_args', $args );
 146  
 147          $_comments = get_comments( $args );
 148          if ( is_array( $_comments ) ) {
 149              update_comment_cache( $_comments );
 150  
 151              $this->items       = array_slice( $_comments, 0, $comments_per_page );
 152              $this->extra_items = array_slice( $_comments, $comments_per_page );
 153  
 154              $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
 155  
 156              $this->pending_count = get_pending_comments_num( $_comment_post_ids );
 157          }
 158  
 159          $total_comments = get_comments(
 160              array_merge(
 161                  $args,
 162                  array(
 163                      'count'  => true,
 164                      'offset' => 0,
 165                      'number' => 0,
 166                  )
 167              )
 168          );
 169  
 170          $this->set_pagination_args(
 171              array(
 172                  'total_items' => $total_comments,
 173                  'per_page'    => $comments_per_page,
 174              )
 175          );
 176      }
 177  
 178      /**
 179       * @param string $comment_status
 180       * @return int
 181       */
 182  	public function get_per_page( $comment_status = 'all' ) {
 183          $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
 184          /**
 185           * Filters the number of comments listed per page in the comments list table.
 186           *
 187           * @since 2.6.0
 188           *
 189           * @param int    $comments_per_page The number of comments to list per page.
 190           * @param string $comment_status    The comment status name. Default 'All'.
 191           */
 192          return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
 193      }
 194  
 195      /**
 196       * @global string $comment_status
 197       */
 198  	public function no_items() {
 199          global $comment_status;
 200  
 201          if ( 'moderated' === $comment_status ) {
 202              _e( 'No comments awaiting moderation.' );
 203          } elseif ( 'trash' === $comment_status ) {
 204              _e( 'No comments found in Trash.' );
 205          } else {
 206              _e( 'No comments found.' );
 207          }
 208      }
 209  
 210      /**
 211       * @global int $post_id
 212       * @global string $comment_status
 213       * @global string $comment_type
 214       */
 215  	protected function get_views() {
 216          global $post_id, $comment_status, $comment_type;
 217  
 218          $status_links = array();
 219          $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
 220  
 221          $stati = array(
 222              /* translators: %s: Number of comments. */
 223              'all'       => _nx_noop(
 224                  'All <span class="count">(%s)</span>',
 225                  'All <span class="count">(%s)</span>',
 226                  'comments'
 227              ), // Singular not used.
 228  
 229              /* translators: %s: Number of comments. */
 230              'mine'      => _nx_noop(
 231                  'Mine <span class="count">(%s)</span>',
 232                  'Mine <span class="count">(%s)</span>',
 233                  'comments'
 234              ),
 235  
 236              /* translators: %s: Number of comments. */
 237              'moderated' => _nx_noop(
 238                  'Pending <span class="count">(%s)</span>',
 239                  'Pending <span class="count">(%s)</span>',
 240                  'comments'
 241              ),
 242  
 243              /* translators: %s: Number of comments. */
 244              'approved'  => _nx_noop(
 245                  'Approved <span class="count">(%s)</span>',
 246                  'Approved <span class="count">(%s)</span>',
 247                  'comments'
 248              ),
 249  
 250              /* translators: %s: Number of comments. */
 251              'spam'      => _nx_noop(
 252                  'Spam <span class="count">(%s)</span>',
 253                  'Spam <span class="count">(%s)</span>',
 254                  'comments'
 255              ),
 256  
 257              /* translators: %s: Number of comments. */
 258              'trash'     => _nx_noop(
 259                  'Trash <span class="count">(%s)</span>',
 260                  'Trash <span class="count">(%s)</span>',
 261                  'comments'
 262              ),
 263          );
 264  
 265          if ( ! EMPTY_TRASH_DAYS ) {
 266              unset( $stati['trash'] );
 267          }
 268  
 269          $link = admin_url( 'edit-comments.php' );
 270          if ( ! empty( $comment_type ) && 'all' != $comment_type ) {
 271              $link = add_query_arg( 'comment_type', $comment_type, $link );
 272          }
 273  
 274          foreach ( $stati as $status => $label ) {
 275              $current_link_attributes = '';
 276  
 277              if ( $status === $comment_status ) {
 278                  $current_link_attributes = ' class="current" aria-current="page"';
 279              }
 280  
 281              if ( 'mine' === $status ) {
 282                  $current_user_id    = get_current_user_id();
 283                  $num_comments->mine = get_comments(
 284                      array(
 285                          'post_id' => $post_id ? $post_id : 0,
 286                          'user_id' => $current_user_id,
 287                          'count'   => true,
 288                      )
 289                  );
 290                  $link               = add_query_arg( 'user_id', $current_user_id, $link );
 291              } else {
 292                  $link = remove_query_arg( 'user_id', $link );
 293              }
 294  
 295              if ( ! isset( $num_comments->$status ) ) {
 296                  $num_comments->$status = 10;
 297              }
 298              $link = add_query_arg( 'comment_status', $status, $link );
 299              if ( $post_id ) {
 300                  $link = add_query_arg( 'p', absint( $post_id ), $link );
 301              }
 302              /*
 303              // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
 304              if ( !empty( $_REQUEST['s'] ) )
 305                  $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link );
 306              */
 307              $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf(
 308                  translate_nooped_plural( $label, $num_comments->$status ),
 309                  sprintf(
 310                      '<span class="%s-count">%s</span>',
 311                      ( 'moderated' === $status ) ? 'pending' : $status,
 312                      number_format_i18n( $num_comments->$status )
 313                  )
 314              ) . '</a>';
 315          }
 316  
 317          /**
 318           * Filters the comment status links.
 319           *
 320           * @since 2.5.0
 321           * @since 5.1.0 The 'Mine' link was added.
 322           *
 323           * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
 324           *                              'Pending', 'Approved', 'Spam', and 'Trash'.
 325           */
 326          return apply_filters( 'comment_status_links', $status_links );
 327      }
 328  
 329      /**
 330       * @global string $comment_status
 331       *
 332       * @return array
 333       */
 334  	protected function get_bulk_actions() {
 335          global $comment_status;
 336  
 337          $actions = array();
 338          if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) {
 339              $actions['unapprove'] = __( 'Unapprove' );
 340          }
 341          if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) {
 342              $actions['approve'] = __( 'Approve' );
 343          }
 344          if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) {
 345              $actions['spam'] = _x( 'Mark as Spam', 'comment' );
 346          }
 347  
 348          if ( 'trash' === $comment_status ) {
 349              $actions['untrash'] = __( 'Restore' );
 350          } elseif ( 'spam' === $comment_status ) {
 351              $actions['unspam'] = _x( 'Not Spam', 'comment' );
 352          }
 353  
 354          if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || ! EMPTY_TRASH_DAYS ) {
 355              $actions['delete'] = __( 'Delete Permanently' );
 356          } else {
 357              $actions['trash'] = __( 'Move to Trash' );
 358          }
 359  
 360          return $actions;
 361      }
 362  
 363      /**
 364       * @global string $comment_status
 365       * @global string $comment_type
 366       *
 367       * @param string $which
 368       */
 369  	protected function extra_tablenav( $which ) {
 370          global $comment_status, $comment_type;
 371          static $has_items;
 372  
 373          if ( ! isset( $has_items ) ) {
 374              $has_items = $this->has_items();
 375          }
 376          ?>
 377          <div class="alignleft actions">
 378          <?php
 379          if ( 'top' === $which ) {
 380              ?>
 381      <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
 382      <select id="filter-by-comment-type" name="comment_type">
 383          <option value=""><?php _e( 'All comment types' ); ?></option>
 384              <?php
 385                  /**
 386                   * Filters the comment types dropdown menu.
 387                   *
 388                   * @since 2.7.0
 389                   *
 390                   * @param string[] $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
 391                   */
 392                  $comment_types = apply_filters(
 393                      'admin_comment_types_dropdown',
 394                      array(
 395                          'comment' => __( 'Comments' ),
 396                          'pings'   => __( 'Pings' ),
 397                      )
 398                  );
 399  
 400              foreach ( $comment_types as $type => $label ) {
 401                  echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
 402              }
 403              ?>
 404      </select>
 405              <?php
 406              /**
 407               * Fires just before the Filter submit button for comment types.
 408               *
 409               * @since 3.5.0
 410               */
 411              do_action( 'restrict_manage_comments' );
 412              submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
 413          }
 414  
 415          if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) {
 416              wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
 417              $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
 418              submit_button( $title, 'apply', 'delete_all', false );
 419          }
 420          /**
 421           * Fires after the Filter submit button for comment types.
 422           *
 423           * @since 2.5.0
 424           *
 425           * @param string $comment_status The comment status name. Default 'All'.
 426           */
 427          do_action( 'manage_comments_nav', $comment_status );
 428          echo '</div>';
 429      }
 430  
 431      /**
 432       * @return string|false
 433       */
 434  	public function current_action() {
 435          if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
 436              return 'delete_all';
 437          }
 438  
 439          return parent::current_action();
 440      }
 441  
 442      /**
 443       * @global int $post_id
 444       *
 445       * @return array
 446       */
 447  	public function get_columns() {
 448          global $post_id;
 449  
 450          $columns = array();
 451  
 452          if ( $this->checkbox ) {
 453              $columns['cb'] = '<input type="checkbox" />';
 454          }
 455  
 456          $columns['author']  = __( 'Author' );
 457          $columns['comment'] = _x( 'Comment', 'column name' );
 458  
 459          if ( ! $post_id ) {
 460              /* translators: Column name or table row header. */
 461              $columns['response'] = __( 'In Response To' );
 462          }
 463  
 464          $columns['date'] = _x( 'Submitted On', 'column name' );
 465  
 466          return $columns;
 467      }
 468  
 469      /**
 470       * @return array
 471       */
 472  	protected function get_sortable_columns() {
 473          return array(
 474              'author'   => 'comment_author',
 475              'response' => 'comment_post_ID',
 476              'date'     => 'comment_date',
 477          );
 478      }
 479  
 480      /**
 481       * Get the name of the default primary column.
 482       *
 483       * @since 4.3.0
 484       *
 485       * @return string Name of the default primary column, in this case, 'comment'.
 486       */
 487  	protected function get_default_primary_column_name() {
 488          return 'comment';
 489      }
 490  
 491      /**
 492       * Displays the comments table.
 493       *
 494       * Overrides the parent display() method to render extra comments.
 495       *
 496       * @since 3.1.0
 497       */
 498  	public function display() {
 499          wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
 500  
 501          $this->display_tablenav( 'top' );
 502  
 503          $this->screen->render_screen_reader_content( 'heading_list' );
 504  
 505          ?>
 506  <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
 507      <thead>
 508      <tr>
 509          <?php $this->print_column_headers(); ?>
 510      </tr>
 511      </thead>
 512  
 513      <tbody id="the-comment-list" data-wp-lists="list:comment">
 514          <?php $this->display_rows_or_placeholder(); ?>
 515      </tbody>
 516  
 517      <tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
 518          <?php
 519              /*
 520               * Back up the items to restore after printing the extra items markup.
 521               * The extra items may be empty, which will prevent the table nav from displaying later.
 522               */
 523              $items       = $this->items;
 524              $this->items = $this->extra_items;
 525              $this->display_rows_or_placeholder();
 526              $this->items = $items;
 527          ?>
 528      </tbody>
 529  
 530      <tfoot>
 531      <tr>
 532          <?php $this->print_column_headers( false ); ?>
 533      </tr>
 534      </tfoot>
 535  
 536  </table>
 537          <?php
 538  
 539          $this->display_tablenav( 'bottom' );
 540      }
 541  
 542      /**
 543       * @global WP_Post    $post    Global post object.
 544       * @global WP_Comment $comment Global comment object.
 545       *
 546       * @param WP_Comment $item
 547       */
 548  	public function single_row( $item ) {
 549          global $post, $comment;
 550  
 551          $comment = $item;
 552  
 553          $the_comment_class = wp_get_comment_status( $comment );
 554          if ( ! $the_comment_class ) {
 555              $the_comment_class = '';
 556          }
 557          $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
 558  
 559          if ( $comment->comment_post_ID > 0 ) {
 560              $post = get_post( $comment->comment_post_ID );
 561          }
 562          $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
 563  
 564          echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
 565          $this->single_row_columns( $comment );
 566          echo "</tr>\n";
 567  
 568          unset( $GLOBALS['post'], $GLOBALS['comment'] );
 569      }
 570  
 571      /**
 572       * Generate and display row actions links.
 573       *
 574       * @since 4.3.0
 575       *
 576       * @global string $comment_status Status for the current listed comments.
 577       *
 578       * @param WP_Comment $comment     The comment object.
 579       * @param string     $column_name Current column name.
 580       * @param string     $primary     Primary column name.
 581       * @return string Row actions output for comments. An empty string
 582       *                if the current column is not the primary column,
 583       *                or if the current user cannot edit the comment.
 584       */
 585  	protected function handle_row_actions( $comment, $column_name, $primary ) {
 586          global $comment_status;
 587  
 588          if ( $primary !== $column_name ) {
 589              return '';
 590          }
 591  
 592          if ( ! $this->user_can ) {
 593              return '';
 594          }
 595  
 596          $the_comment_status = wp_get_comment_status( $comment );
 597  
 598          $out = '';
 599  
 600          $del_nonce     = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
 601          $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
 602  
 603          $url = "comment.php?c=$comment->comment_ID";
 604  
 605          $approve_url   = esc_url( $url . "&action=approvecomment&$approve_nonce" );
 606          $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
 607          $spam_url      = esc_url( $url . "&action=spamcomment&$del_nonce" );
 608          $unspam_url    = esc_url( $url . "&action=unspamcomment&$del_nonce" );
 609          $trash_url     = esc_url( $url . "&action=trashcomment&$del_nonce" );
 610          $untrash_url   = esc_url( $url . "&action=untrashcomment&$del_nonce" );
 611          $delete_url    = esc_url( $url . "&action=deletecomment&$del_nonce" );
 612  
 613          // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
 614          $actions = array(
 615              'approve'   => '',
 616              'unapprove' => '',
 617              'reply'     => '',
 618              'quickedit' => '',
 619              'edit'      => '',
 620              'spam'      => '',
 621              'unspam'    => '',
 622              'trash'     => '',
 623              'untrash'   => '',
 624              'delete'    => '',
 625          );
 626  
 627          // Not looking at all comments.
 628          if ( $comment_status && 'all' != $comment_status ) {
 629              if ( 'approved' === $the_comment_status ) {
 630                  $actions['unapprove'] = sprintf(
 631                      '<a href="%s" data-wp-lists="%s" class="vim-u vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 632                      $unapprove_url,
 633                      "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=unapproved",
 634                      esc_attr__( 'Unapprove this comment' ),
 635                      __( 'Unapprove' )
 636                  );
 637              } elseif ( 'unapproved' === $the_comment_status ) {
 638                  $actions['approve'] = sprintf(
 639                      '<a href="%s" data-wp-lists="%s" class="vim-a vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 640                      $approve_url,
 641                      "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=approved",
 642                      esc_attr__( 'Approve this comment' ),
 643                      __( 'Approve' )
 644                  );
 645              }
 646          } else {
 647              $actions['approve'] = sprintf(
 648                  '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
 649                  $approve_url,
 650                  "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
 651                  esc_attr__( 'Approve this comment' ),
 652                  __( 'Approve' )
 653              );
 654  
 655              $actions['unapprove'] = sprintf(
 656                  '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
 657                  $unapprove_url,
 658                  "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
 659                  esc_attr__( 'Unapprove this comment' ),
 660                  __( 'Unapprove' )
 661              );
 662          }
 663  
 664          if ( 'spam' !== $the_comment_status ) {
 665              $actions['spam'] = sprintf(
 666                  '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 667                  $spam_url,
 668                  "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
 669                  esc_attr__( 'Mark this comment as spam' ),
 670                  /* translators: "Mark as spam" link. */
 671                  _x( 'Spam', 'verb' )
 672              );
 673          } elseif ( 'spam' === $the_comment_status ) {
 674              $actions['unspam'] = sprintf(
 675                  '<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 676                  $unspam_url,
 677                  "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1",
 678                  esc_attr__( 'Restore this comment from the spam' ),
 679                  _x( 'Not Spam', 'comment' )
 680              );
 681          }
 682  
 683          if ( 'trash' === $the_comment_status ) {
 684              $actions['untrash'] = sprintf(
 685                  '<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 686                  $untrash_url,
 687                  "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1",
 688                  esc_attr__( 'Restore this comment from the Trash' ),
 689                  __( 'Restore' )
 690              );
 691          }
 692  
 693          if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) {
 694              $actions['delete'] = sprintf(
 695                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 696                  $delete_url,
 697                  "delete:the-comment-list:comment-{$comment->comment_ID}::delete=1",
 698                  esc_attr__( 'Delete this comment permanently' ),
 699                  __( 'Delete Permanently' )
 700              );
 701          } else {
 702              $actions['trash'] = sprintf(
 703                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 704                  $trash_url,
 705                  "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
 706                  esc_attr__( 'Move this comment to the Trash' ),
 707                  _x( 'Trash', 'verb' )
 708              );
 709          }
 710  
 711          if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
 712              $actions['edit'] = sprintf(
 713                  '<a href="%s" aria-label="%s">%s</a>',
 714                  "comment.php?action=editcomment&amp;c={$comment->comment_ID}",
 715                  esc_attr__( 'Edit this comment' ),
 716                  __( 'Edit' )
 717              );
 718  
 719              $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>';
 720  
 721              $actions['quickedit'] = sprintf(
 722                  $format,
 723                  $comment->comment_ID,
 724                  $comment->comment_post_ID,
 725                  'edit',
 726                  'vim-q comment-inline',
 727                  esc_attr__( 'Quick edit this comment inline' ),
 728                  __( 'Quick&nbsp;Edit' )
 729              );
 730  
 731              $actions['reply'] = sprintf(
 732                  $format,
 733                  $comment->comment_ID,
 734                  $comment->comment_post_ID,
 735                  'replyto',
 736                  'vim-r comment-inline',
 737                  esc_attr__( 'Reply to this comment' ),
 738                  __( 'Reply' )
 739              );
 740          }
 741  
 742          /** This filter is documented in wp-admin/includes/dashboard.php */
 743          $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
 744  
 745          $i    = 0;
 746          $out .= '<div class="row-actions">';
 747          foreach ( $actions as $action => $link ) {
 748              ++$i;
 749              ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
 750  
 751              // Reply and quickedit need a hide-if-no-js span when not added with ajax.
 752              if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
 753                  $action .= ' hide-if-no-js';
 754              } elseif ( ( 'untrash' === $action && 'trash' === $the_comment_status ) || ( 'unspam' === $action && 'spam' === $the_comment_status ) ) {
 755                  if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
 756                      $action .= ' approve';
 757                  } else {
 758                      $action .= ' unapprove';
 759                  }
 760              }
 761  
 762              $out .= "<span class='$action'>$sep$link</span>";
 763          }
 764          $out .= '</div>';
 765  
 766          $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
 767  
 768          return $out;
 769      }
 770  
 771      /**
 772       * @param WP_Comment $comment The comment object.
 773       */
 774  	public function column_cb( $comment ) {
 775          if ( $this->user_can ) {
 776              ?>
 777          <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
 778          <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
 779              <?php
 780          }
 781      }
 782  
 783      /**
 784       * @param WP_Comment $comment The comment object.
 785       */
 786  	public function column_comment( $comment ) {
 787          echo '<div class="comment-author">';
 788              $this->column_author( $comment );
 789          echo '</div>';
 790  
 791          if ( $comment->comment_parent ) {
 792              $parent = get_comment( $comment->comment_parent );
 793              if ( $parent ) {
 794                  $parent_link = esc_url( get_comment_link( $parent ) );
 795                  $name        = get_comment_author( $parent );
 796                  printf(
 797                      /* translators: %s: Comment link. */
 798                      __( 'In reply to %s.' ),
 799                      '<a href="' . $parent_link . '">' . $name . '</a>'
 800                  );
 801              }
 802          }
 803  
 804          comment_text( $comment );
 805  
 806          if ( $this->user_can ) {
 807              /** This filter is documented in wp-admin/includes/comment.php */
 808              $comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
 809              ?>
 810          <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
 811              <textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea>
 812              <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
 813              <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
 814              <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
 815              <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
 816          </div>
 817              <?php
 818          }
 819      }
 820  
 821      /**
 822       * @global string $comment_status
 823       *
 824       * @param WP_Comment $comment The comment object.
 825       */
 826  	public function column_author( $comment ) {
 827          global $comment_status;
 828  
 829          $author_url = get_comment_author_url( $comment );
 830  
 831          $author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) );
 832          if ( strlen( $author_url_display ) > 50 ) {
 833              $author_url_display = wp_html_excerpt( $author_url_display, 49, '&hellip;' );
 834          }
 835  
 836          echo '<strong>';
 837          comment_author( $comment );
 838          echo '</strong><br />';
 839          if ( ! empty( $author_url_display ) ) {
 840              printf( '<a href="%s">%s</a><br />', esc_url( $author_url ), esc_html( $author_url_display ) );
 841          }
 842  
 843          if ( $this->user_can ) {
 844              if ( ! empty( $comment->comment_author_email ) ) {
 845                  /** This filter is documented in wp-includes/comment-template.php */
 846                  $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
 847  
 848                  if ( ! empty( $email ) && '@' !== $email ) {
 849                      printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) );
 850                  }
 851              }
 852  
 853              $author_ip = get_comment_author_IP( $comment );
 854              if ( $author_ip ) {
 855                  $author_ip_url = add_query_arg(
 856                      array(
 857                          's'    => $author_ip,
 858                          'mode' => 'detail',
 859                      ),
 860                      admin_url( 'edit-comments.php' )
 861                  );
 862                  if ( 'spam' === $comment_status ) {
 863                      $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
 864                  }
 865                  printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) );
 866              }
 867          }
 868      }
 869  
 870      /**
 871       * @param WP_Comment $comment The comment object.
 872       */
 873  	public function column_date( $comment ) {
 874          $submitted = sprintf(
 875              /* translators: 1: Comment date, 2: Comment time. */
 876              __( '%1$s at %2$s' ),
 877              /* translators: Comment date format. See https://www.php.net/date */
 878              get_comment_date( __( 'Y/m/d' ), $comment ),
 879              /* translators: Comment time format. See https://www.php.net/date */
 880              get_comment_date( __( 'g:i a' ), $comment )
 881          );
 882  
 883          echo '<div class="submitted-on">';
 884          if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
 885              printf(
 886                  '<a href="%s">%s</a>',
 887                  esc_url( get_comment_link( $comment ) ),
 888                  $submitted
 889              );
 890          } else {
 891              echo $submitted;
 892          }
 893          echo '</div>';
 894      }
 895  
 896      /**
 897       * @param WP_Comment $comment The comment object.
 898       */
 899  	public function column_response( $comment ) {
 900          $post = get_post();
 901  
 902          if ( ! $post ) {
 903              return;
 904          }
 905  
 906          if ( isset( $this->pending_count[ $post->ID ] ) ) {
 907              $pending_comments = $this->pending_count[ $post->ID ];
 908          } else {
 909              $_pending_count_temp              = get_pending_comments_num( array( $post->ID ) );
 910              $pending_comments                 = $_pending_count_temp[ $post->ID ];
 911              $this->pending_count[ $post->ID ] = $pending_comments;
 912          }
 913  
 914          if ( current_user_can( 'edit_post', $post->ID ) ) {
 915              $post_link  = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
 916              $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
 917          } else {
 918              $post_link = esc_html( get_the_title( $post->ID ) );
 919          }
 920  
 921          echo '<div class="response-links">';
 922          if ( 'attachment' === $post->post_type ) {
 923              $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true );
 924              if ( $thumb ) {
 925                  echo $thumb;
 926              }
 927          }
 928          echo $post_link;
 929          $post_type_object = get_post_type_object( $post->post_type );
 930          echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
 931          echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">';
 932          $this->comments_bubble( $post->ID, $pending_comments );
 933          echo '</span> ';
 934          echo '</div>';
 935      }
 936  
 937      /**
 938       * @param WP_Comment $comment     The comment object.
 939       * @param string     $column_name The custom column's name.
 940       */
 941  	public function column_default( $comment, $column_name ) {
 942          /**
 943           * Fires when the default column output is displayed for a single row.
 944           *
 945           * @since 2.8.0
 946           *
 947           * @param string $column_name         The custom column's name.
 948           * @param int    $comment->comment_ID The custom column's unique ID number.
 949           */
 950          do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
 951      }
 952  }


Generated: Tue May 19 15:51:04 2020 Cross-referenced by PHPXref 0.7.1