[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sun Jun 7 08:20:01 2020 Cross-referenced by PHPXref