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


Generated : Mon Jul 15 08:20:02 2024 Cross-referenced by PHPXref