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


Generated : Wed Nov 25 08:20:02 2020 Cross-referenced by PHPXref