[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7