[ 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       * Displays the comments table.
 491       *
 492       * Overrides the parent display() method to render extra comments.
 493       *
 494       * @since 3.1.0
 495       */
 496  	public function display() {
 497          wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
 498  
 499          $this->display_tablenav( 'top' );
 500  
 501          $this->screen->render_screen_reader_content( 'heading_list' );
 502  
 503          ?>
 504  <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
 505      <thead>
 506      <tr>
 507          <?php $this->print_column_headers(); ?>
 508      </tr>
 509      </thead>
 510  
 511      <tbody id="the-comment-list" data-wp-lists="list:comment">
 512          <?php $this->display_rows_or_placeholder(); ?>
 513      </tbody>
 514  
 515      <tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
 516          <?php
 517              /*
 518               * Back up the items to restore after printing the extra items markup.
 519               * The extra items may be empty, which will prevent the table nav from displaying later.
 520               */
 521              $items       = $this->items;
 522              $this->items = $this->extra_items;
 523              $this->display_rows_or_placeholder();
 524              $this->items = $items;
 525          ?>
 526      </tbody>
 527  
 528      <tfoot>
 529      <tr>
 530          <?php $this->print_column_headers( false ); ?>
 531      </tr>
 532      </tfoot>
 533  
 534  </table>
 535          <?php
 536  
 537          $this->display_tablenav( 'bottom' );
 538      }
 539  
 540      /**
 541       * @global WP_Post    $post    Global post object.
 542       * @global WP_Comment $comment Global comment object.
 543       *
 544       * @param WP_Comment $item
 545       */
 546  	public function single_row( $item ) {
 547          global $post, $comment;
 548  
 549          $comment = $item;
 550  
 551          $the_comment_class = wp_get_comment_status( $comment );
 552          if ( ! $the_comment_class ) {
 553              $the_comment_class = '';
 554          }
 555          $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
 556  
 557          if ( $comment->comment_post_ID > 0 ) {
 558              $post = get_post( $comment->comment_post_ID );
 559          }
 560          $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
 561  
 562          echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
 563          $this->single_row_columns( $comment );
 564          echo "</tr>\n";
 565  
 566          unset( $GLOBALS['post'], $GLOBALS['comment'] );
 567      }
 568  
 569      /**
 570       * Generate and display row actions links.
 571       *
 572       * @since 4.3.0
 573       *
 574       * @global string $comment_status Status for the current listed comments.
 575       *
 576       * @param WP_Comment $comment     The comment object.
 577       * @param string     $column_name Current column name.
 578       * @param string     $primary     Primary column name.
 579       * @return string Row actions output for comments. An empty string
 580       *                if the current column is not the primary column,
 581       *                or if the current user cannot edit the comment.
 582       */
 583  	protected function handle_row_actions( $comment, $column_name, $primary ) {
 584          global $comment_status;
 585  
 586          if ( $primary !== $column_name ) {
 587              return '';
 588          }
 589  
 590          if ( ! $this->user_can ) {
 591              return '';
 592          }
 593  
 594          $the_comment_status = wp_get_comment_status( $comment );
 595  
 596          $out = '';
 597  
 598          $del_nonce     = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
 599          $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
 600  
 601          $url = "comment.php?c=$comment->comment_ID";
 602  
 603          $approve_url   = esc_url( $url . "&action=approvecomment&$approve_nonce" );
 604          $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
 605          $spam_url      = esc_url( $url . "&action=spamcomment&$del_nonce" );
 606          $unspam_url    = esc_url( $url . "&action=unspamcomment&$del_nonce" );
 607          $trash_url     = esc_url( $url . "&action=trashcomment&$del_nonce" );
 608          $untrash_url   = esc_url( $url . "&action=untrashcomment&$del_nonce" );
 609          $delete_url    = esc_url( $url . "&action=deletecomment&$del_nonce" );
 610  
 611          // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
 612          $actions = array(
 613              'approve'   => '',
 614              'unapprove' => '',
 615              'reply'     => '',
 616              'quickedit' => '',
 617              'edit'      => '',
 618              'spam'      => '',
 619              'unspam'    => '',
 620              'trash'     => '',
 621              'untrash'   => '',
 622              'delete'    => '',
 623          );
 624  
 625          // Not looking at all comments.
 626          if ( $comment_status && 'all' != $comment_status ) {
 627              if ( 'approved' === $the_comment_status ) {
 628                  $actions['unapprove'] = sprintf(
 629                      '<a href="%s" data-wp-lists="%s" class="vim-u vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 630                      $unapprove_url,
 631                      "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=unapproved",
 632                      esc_attr__( 'Unapprove this comment' ),
 633                      __( 'Unapprove' )
 634                  );
 635              } elseif ( 'unapproved' === $the_comment_status ) {
 636                  $actions['approve'] = sprintf(
 637                      '<a href="%s" data-wp-lists="%s" class="vim-a vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 638                      $approve_url,
 639                      "delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&amp;new=approved",
 640                      esc_attr__( 'Approve this comment' ),
 641                      __( 'Approve' )
 642                  );
 643              }
 644          } else {
 645              $actions['approve'] = sprintf(
 646                  '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
 647                  $approve_url,
 648                  "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
 649                  esc_attr__( 'Approve this comment' ),
 650                  __( 'Approve' )
 651              );
 652  
 653              $actions['unapprove'] = sprintf(
 654                  '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
 655                  $unapprove_url,
 656                  "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
 657                  esc_attr__( 'Unapprove this comment' ),
 658                  __( 'Unapprove' )
 659              );
 660          }
 661  
 662          if ( 'spam' !== $the_comment_status ) {
 663              $actions['spam'] = sprintf(
 664                  '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 665                  $spam_url,
 666                  "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
 667                  esc_attr__( 'Mark this comment as spam' ),
 668                  /* translators: "Mark as spam" link. */
 669                  _x( 'Spam', 'verb' )
 670              );
 671          } elseif ( 'spam' === $the_comment_status ) {
 672              $actions['unspam'] = sprintf(
 673                  '<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 674                  $unspam_url,
 675                  "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1",
 676                  esc_attr__( 'Restore this comment from the spam' ),
 677                  _x( 'Not Spam', 'comment' )
 678              );
 679          }
 680  
 681          if ( 'trash' === $the_comment_status ) {
 682              $actions['untrash'] = sprintf(
 683                  '<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 684                  $untrash_url,
 685                  "delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1",
 686                  esc_attr__( 'Restore this comment from the Trash' ),
 687                  __( 'Restore' )
 688              );
 689          }
 690  
 691          if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || ! EMPTY_TRASH_DAYS ) {
 692              $actions['delete'] = sprintf(
 693                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 694                  $delete_url,
 695                  "delete:the-comment-list:comment-{$comment->comment_ID}::delete=1",
 696                  esc_attr__( 'Delete this comment permanently' ),
 697                  __( 'Delete Permanently' )
 698              );
 699          } else {
 700              $actions['trash'] = sprintf(
 701                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 702                  $trash_url,
 703                  "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
 704                  esc_attr__( 'Move this comment to the Trash' ),
 705                  _x( 'Trash', 'verb' )
 706              );
 707          }
 708  
 709          if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
 710              $actions['edit'] = sprintf(
 711                  '<a href="%s" aria-label="%s">%s</a>',
 712                  "comment.php?action=editcomment&amp;c={$comment->comment_ID}",
 713                  esc_attr__( 'Edit this comment' ),
 714                  __( 'Edit' )
 715              );
 716  
 717              $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>';
 718  
 719              $actions['quickedit'] = sprintf(
 720                  $format,
 721                  $comment->comment_ID,
 722                  $comment->comment_post_ID,
 723                  'edit',
 724                  'vim-q comment-inline',
 725                  esc_attr__( 'Quick edit this comment inline' ),
 726                  __( 'Quick&nbsp;Edit' )
 727              );
 728  
 729              $actions['reply'] = sprintf(
 730                  $format,
 731                  $comment->comment_ID,
 732                  $comment->comment_post_ID,
 733                  'replyto',
 734                  'vim-r comment-inline',
 735                  esc_attr__( 'Reply to this comment' ),
 736                  __( 'Reply' )
 737              );
 738          }
 739  
 740          /** This filter is documented in wp-admin/includes/dashboard.php */
 741          $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
 742  
 743          $i    = 0;
 744          $out .= '<div class="row-actions">';
 745          foreach ( $actions as $action => $link ) {
 746              ++$i;
 747              ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
 748  
 749              // Reply and quickedit need a hide-if-no-js span when not added with ajax
 750              if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
 751                  $action .= ' hide-if-no-js';
 752              } elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) {
 753                  if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) {
 754                      $action .= ' approve';
 755                  } else {
 756                      $action .= ' unapprove';
 757                  }
 758              }
 759  
 760              $out .= "<span class='$action'>$sep$link</span>";
 761          }
 762          $out .= '</div>';
 763  
 764          $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
 765  
 766          return $out;
 767      }
 768  
 769      /**
 770       * @param WP_Comment $comment The comment object.
 771       */
 772  	public function column_cb( $comment ) {
 773          if ( $this->user_can ) {
 774              ?>
 775          <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
 776          <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
 777              <?php
 778          }
 779      }
 780  
 781      /**
 782       * @param WP_Comment $comment The comment object.
 783       */
 784  	public function column_comment( $comment ) {
 785          echo '<div class="comment-author">';
 786              $this->column_author( $comment );
 787          echo '</div>';
 788  
 789          if ( $comment->comment_parent ) {
 790              $parent = get_comment( $comment->comment_parent );
 791              if ( $parent ) {
 792                  $parent_link = esc_url( get_comment_link( $parent ) );
 793                  $name        = get_comment_author( $parent );
 794                  printf(
 795                      /* translators: %s: Comment link. */
 796                      __( 'In reply to %s.' ),
 797                      '<a href="' . $parent_link . '">' . $name . '</a>'
 798                  );
 799              }
 800          }
 801  
 802          comment_text( $comment );
 803  
 804          if ( $this->user_can ) {
 805              /** This filter is documented in wp-admin/includes/comment.php */
 806              $comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
 807              ?>
 808          <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
 809              <textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( $comment_content ); ?></textarea>
 810              <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
 811              <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
 812              <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
 813              <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
 814          </div>
 815              <?php
 816          }
 817      }
 818  
 819      /**
 820       * @global string $comment_status
 821       *
 822       * @param WP_Comment $comment The comment object.
 823       */
 824  	public function column_author( $comment ) {
 825          global $comment_status;
 826  
 827          $author_url = get_comment_author_url( $comment );
 828  
 829          $author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) );
 830          if ( strlen( $author_url_display ) > 50 ) {
 831              $author_url_display = wp_html_excerpt( $author_url_display, 49, '&hellip;' );
 832          }
 833  
 834          echo '<strong>';
 835          comment_author( $comment );
 836          echo '</strong><br />';
 837          if ( ! empty( $author_url_display ) ) {
 838              printf( '<a href="%s">%s</a><br />', esc_url( $author_url ), esc_html( $author_url_display ) );
 839          }
 840  
 841          if ( $this->user_can ) {
 842              if ( ! empty( $comment->comment_author_email ) ) {
 843                  /** This filter is documented in wp-includes/comment-template.php */
 844                  $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
 845  
 846                  if ( ! empty( $email ) && '@' !== $email ) {
 847                      printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) );
 848                  }
 849              }
 850  
 851              $author_ip = get_comment_author_IP( $comment );
 852              if ( $author_ip ) {
 853                  $author_ip_url = add_query_arg(
 854                      array(
 855                          's'    => $author_ip,
 856                          'mode' => 'detail',
 857                      ),
 858                      admin_url( 'edit-comments.php' )
 859                  );
 860                  if ( 'spam' === $comment_status ) {
 861                      $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
 862                  }
 863                  printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) );
 864              }
 865          }
 866      }
 867  
 868      /**
 869       * @param WP_Comment $comment The comment object.
 870       */
 871  	public function column_date( $comment ) {
 872          $submitted = sprintf(
 873              /* translators: 1: Comment date, 2: Comment time. */
 874              __( '%1$s at %2$s' ),
 875              /* translators: Comment date format. See https://www.php.net/date */
 876              get_comment_date( __( 'Y/m/d' ), $comment ),
 877              /* translators: Comment time format. See https://www.php.net/date */
 878              get_comment_date( __( 'g:i a' ), $comment )
 879          );
 880  
 881          echo '<div class="submitted-on">';
 882          if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
 883              printf(
 884                  '<a href="%s">%s</a>',
 885                  esc_url( get_comment_link( $comment ) ),
 886                  $submitted
 887              );
 888          } else {
 889              echo $submitted;
 890          }
 891          echo '</div>';
 892      }
 893  
 894      /**
 895       * @param WP_Comment $comment The comment object.
 896       */
 897  	public function column_response( $comment ) {
 898          $post = get_post();
 899  
 900          if ( ! $post ) {
 901              return;
 902          }
 903  
 904          if ( isset( $this->pending_count[ $post->ID ] ) ) {
 905              $pending_comments = $this->pending_count[ $post->ID ];
 906          } else {
 907              $_pending_count_temp              = get_pending_comments_num( array( $post->ID ) );
 908              $pending_comments                 = $_pending_count_temp[ $post->ID ];
 909              $this->pending_count[ $post->ID ] = $pending_comments;
 910          }
 911  
 912          if ( current_user_can( 'edit_post', $post->ID ) ) {
 913              $post_link  = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
 914              $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
 915          } else {
 916              $post_link = esc_html( get_the_title( $post->ID ) );
 917          }
 918  
 919          echo '<div class="response-links">';
 920          if ( 'attachment' === $post->post_type ) {
 921              $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true );
 922              if ( $thumb ) {
 923                  echo $thumb;
 924              }
 925          }
 926          echo $post_link;
 927          $post_type_object = get_post_type_object( $post->post_type );
 928          echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
 929          echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">';
 930          $this->comments_bubble( $post->ID, $pending_comments );
 931          echo '</span> ';
 932          echo '</div>';
 933      }
 934  
 935      /**
 936       * @param WP_Comment $comment     The comment object.
 937       * @param string     $column_name The custom column's name.
 938       */
 939  	public function column_default( $comment, $column_name ) {
 940          /**
 941           * Fires when the default column output is displayed for a single row.
 942           *
 943           * @since 2.8.0
 944           *
 945           * @param string $column_name         The custom column's name.
 946           * @param int    $comment->comment_ID The custom column's unique ID number.
 947           */
 948          do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
 949      }
 950  }


Generated: Tue Jan 21 01:00:03 2020 Cross-referenced by PHPXref 0.7.1