[ Index ]

PHP Cross Reference of WordPress

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


Generated: Wed Sep 18 01:00:03 2019 Cross-referenced by PHPXref 0.7.1