[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> edit-comments.php (source)

   1  <?php
   2  /**
   3   * Edit Comments Administration Screen.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once  __DIR__ . '/admin.php';
  11  if ( ! current_user_can( 'edit_posts' ) ) {
  12      wp_die(
  13          '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  14          '<p>' . __( 'Sorry, you are not allowed to edit comments.' ) . '</p>',
  15          403
  16      );
  17  }
  18  
  19  $wp_list_table = _get_list_table( 'WP_Comments_List_Table' );
  20  $pagenum       = $wp_list_table->get_pagenum();
  21  
  22  $doaction = $wp_list_table->current_action();
  23  
  24  if ( $doaction ) {
  25      check_admin_referer( 'bulk-comments' );
  26  
  27      if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
  28          /**
  29           * @global wpdb $wpdb WordPress database abstraction object.
  30           */
  31          global $wpdb;
  32  
  33          $comment_status = wp_unslash( $_REQUEST['comment_status'] );
  34          $delete_time    = wp_unslash( $_REQUEST['pagegen_timestamp'] );
  35          $comment_ids    = $wpdb->get_col(
  36              $wpdb->prepare(
  37                  "SELECT comment_ID FROM $wpdb->comments
  38                  WHERE comment_approved = %s AND %s > comment_date_gmt",
  39                  $comment_status,
  40                  $delete_time
  41              )
  42          );
  43          $doaction       = 'delete';
  44      } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
  45          $comment_ids = $_REQUEST['delete_comments'];
  46          $doaction    = $_REQUEST['action'];
  47      } elseif ( isset( $_REQUEST['ids'] ) ) {
  48          $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
  49      } elseif ( wp_get_referer() ) {
  50          wp_safe_redirect( wp_get_referer() );
  51          exit;
  52      }
  53  
  54      $approved   = 0;
  55      $unapproved = 0;
  56      $spammed    = 0;
  57      $unspammed  = 0;
  58      $trashed    = 0;
  59      $untrashed  = 0;
  60      $deleted    = 0;
  61  
  62      $redirect_to = remove_query_arg(
  63          array(
  64              'trashed',
  65              'untrashed',
  66              'deleted',
  67              'spammed',
  68              'unspammed',
  69              'approved',
  70              'unapproved',
  71              'ids',
  72          ),
  73          wp_get_referer()
  74      );
  75      $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
  76  
  77      wp_defer_comment_counting( true );
  78  
  79      foreach ( $comment_ids as $comment_id ) { // Check the permissions on each.
  80          if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
  81              continue;
  82          }
  83  
  84          switch ( $doaction ) {
  85              case 'approve':
  86                  wp_set_comment_status( $comment_id, 'approve' );
  87                  ++$approved;
  88                  break;
  89              case 'unapprove':
  90                  wp_set_comment_status( $comment_id, 'hold' );
  91                  ++$unapproved;
  92                  break;
  93              case 'spam':
  94                  wp_spam_comment( $comment_id );
  95                  ++$spammed;
  96                  break;
  97              case 'unspam':
  98                  wp_unspam_comment( $comment_id );
  99                  ++$unspammed;
 100                  break;
 101              case 'trash':
 102                  wp_trash_comment( $comment_id );
 103                  ++$trashed;
 104                  break;
 105              case 'untrash':
 106                  wp_untrash_comment( $comment_id );
 107                  ++$untrashed;
 108                  break;
 109              case 'delete':
 110                  wp_delete_comment( $comment_id );
 111                  ++$deleted;
 112                  break;
 113          }
 114      }
 115  
 116      if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {
 117          $screen = get_current_screen()->id;
 118  
 119          /** This action is documented in wp-admin/edit.php */
 120          $redirect_to = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to, $doaction, $comment_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 121      }
 122  
 123      wp_defer_comment_counting( false );
 124  
 125      if ( $approved ) {
 126          $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
 127      }
 128      if ( $unapproved ) {
 129          $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
 130      }
 131      if ( $spammed ) {
 132          $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
 133      }
 134      if ( $unspammed ) {
 135          $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
 136      }
 137      if ( $trashed ) {
 138          $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
 139      }
 140      if ( $untrashed ) {
 141          $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
 142      }
 143      if ( $deleted ) {
 144          $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
 145      }
 146      if ( $trashed || $spammed ) {
 147          $redirect_to = add_query_arg( 'ids', implode( ',', $comment_ids ), $redirect_to );
 148      }
 149  
 150      wp_safe_redirect( $redirect_to );
 151      exit;
 152  } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
 153      wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
 154      exit;
 155  }
 156  
 157  $wp_list_table->prepare_items();
 158  
 159  wp_enqueue_script( 'admin-comments' );
 160  enqueue_comment_hotkeys_js();
 161  
 162  /**
 163   * @global int $post_id
 164   */
 165  global $post_id;
 166  
 167  if ( $post_id ) {
 168      $comments_count      = wp_count_comments( $post_id );
 169      $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' );
 170  
 171      if ( $comments_count->moderated > 0 ) {
 172          // Used in the HTML title tag.
 173          $title = sprintf(
 174              /* translators: 1: Comments count, 2: Post title. */
 175              __( 'Comments (%1$s) on &#8220;%2$s&#8221;' ),
 176              number_format_i18n( $comments_count->moderated ),
 177              $draft_or_post_title
 178          );
 179      } else {
 180          // Used in the HTML title tag.
 181          $title = sprintf(
 182              /* translators: %s: Post title. */
 183              __( 'Comments on &#8220;%s&#8221;' ),
 184              $draft_or_post_title
 185          );
 186      }
 187  } else {
 188      $comments_count = wp_count_comments();
 189  
 190      if ( $comments_count->moderated > 0 ) {
 191          // Used in the HTML title tag.
 192          $title = sprintf(
 193              /* translators: %s: Comments count. */
 194              __( 'Comments (%s)' ),
 195              number_format_i18n( $comments_count->moderated )
 196          );
 197      } else {
 198          // Used in the HTML title tag.
 199          $title = __( 'Comments' );
 200      }
 201  }
 202  
 203  add_screen_option( 'per_page' );
 204  
 205  get_current_screen()->add_help_tab(
 206      array(
 207          'id'      => 'overview',
 208          'title'   => __( 'Overview' ),
 209          'content' =>
 210                  '<p>' . __( 'You can manage comments made on your site similar to the way you manage posts and other content. This screen is customizable in the same ways as other management screens, and you can act on comments using the on-hover action links or the bulk actions.' ) . '</p>',
 211      )
 212  );
 213  get_current_screen()->add_help_tab(
 214      array(
 215          'id'      => 'moderating-comments',
 216          'title'   => __( 'Moderating Comments' ),
 217          'content' =>
 218                      '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
 219                      '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and site URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
 220                      '<p>' . __( 'In the <strong>Comment</strong> column, hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
 221                      '<p>' . __( 'In the <strong>In response to</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows the number of approved comments that post has received. If there are pending comments, a red notification circle with the number of pending comments is displayed. Clicking the notification circle will filter the comments screen to show only pending comments on that post.' ) . '</p>' .
 222                      '<p>' . __( 'In the <strong>Submitted on</strong> column, the date and time the comment was left on your site appears. Clicking on the date/time link will take you to that comment on your live site.' ) . '</p>' .
 223                      '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>',
 224      )
 225  );
 226  
 227  get_current_screen()->set_help_sidebar(
 228      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 229      '<p>' . __( '<a href="https://wordpress.org/documentation/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' .
 230      '<p>' . __( '<a href="https://wordpress.org/documentation/article/understand-comment-spam/">Documentation on Comment Spam</a>' ) . '</p>' .
 231      '<p>' . __( '<a href="https://wordpress.org/documentation/article/keyboard-shortcuts-classic-editor/#keyboard-shortcuts-for-comments">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
 232      '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
 233  );
 234  
 235  get_current_screen()->set_screen_reader_content(
 236      array(
 237          'heading_views'      => __( 'Filter comments list' ),
 238          'heading_pagination' => __( 'Comments list navigation' ),
 239          'heading_list'       => __( 'Comments list' ),
 240      )
 241  );
 242  
 243  require_once  ABSPATH . 'wp-admin/admin-header.php';
 244  ?>
 245  
 246  <div class="wrap">
 247  <h1 class="wp-heading-inline">
 248  <?php
 249  if ( $post_id ) {
 250      printf(
 251          /* translators: %s: Link to post. */
 252          __( 'Comments on &#8220;%s&#8221;' ),
 253          sprintf(
 254              '<a href="%1$s">%2$s</a>',
 255              get_edit_post_link( $post_id ),
 256              wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' )
 257          )
 258      );
 259  } else {
 260      _e( 'Comments' );
 261  }
 262  ?>
 263  </h1>
 264  
 265  <?php
 266  if ( $post_id ) {
 267      $post_type_object = get_post_type_object( get_post_type( $post_id ) );
 268  
 269      if ( $post_type_object ) {
 270          printf(
 271              '<a href="%1$s" class="comments-view-item-link">%2$s</a>',
 272              get_permalink( $post_id ),
 273              $post_type_object->labels->view_item
 274          );
 275      }
 276  }
 277  
 278  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 279      echo '<span class="subtitle">';
 280      printf(
 281          /* translators: %s: Search query. */
 282          __( 'Search results for: %s' ),
 283          '<strong>' . esc_html( wp_unslash( $_REQUEST['s'] ) ) . '</strong>'
 284      );
 285      echo '</span>';
 286  }
 287  ?>
 288  
 289  <hr class="wp-header-end">
 290  
 291  <?php
 292  if ( isset( $_REQUEST['error'] ) ) {
 293      $error     = (int) $_REQUEST['error'];
 294      $error_msg = '';
 295      switch ( $error ) {
 296          case 1:
 297              $error_msg = __( 'Invalid comment ID.' );
 298              break;
 299          case 2:
 300              $error_msg = __( 'Sorry, you are not allowed to edit comments on this post.' );
 301              break;
 302      }
 303      if ( $error_msg ) {
 304          wp_admin_notice(
 305              $error_msg,
 306              array(
 307                  'id'                 => 'moderated',
 308                  'additional_classes' => array( 'error' ),
 309              )
 310          );
 311      }
 312  }
 313  
 314  if ( isset( $_REQUEST['approved'] )
 315      || isset( $_REQUEST['deleted'] )
 316      || isset( $_REQUEST['trashed'] )
 317      || isset( $_REQUEST['untrashed'] )
 318      || isset( $_REQUEST['spammed'] )
 319      || isset( $_REQUEST['unspammed'] )
 320      || isset( $_REQUEST['same'] )
 321  ) {
 322      $approved  = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
 323      $deleted   = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
 324      $trashed   = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
 325      $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
 326      $spammed   = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
 327      $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
 328      $same      = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
 329  
 330      if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
 331          if ( $approved > 0 ) {
 332              $messages[] = sprintf(
 333                  /* translators: %s: Number of comments. */
 334                  _n( '%s comment approved.', '%s comments approved.', $approved ),
 335                  $approved
 336              );
 337          }
 338  
 339          if ( $spammed > 0 ) {
 340              $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
 341  
 342              $messages[] = sprintf(
 343                  /* translators: %s: Number of comments. */
 344                  _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ),
 345                  $spammed
 346              ) . sprintf(
 347                  ' <a href="%1$s">%2$s</a><br />',
 348                  esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ),
 349                  __( 'Undo' )
 350              );
 351          }
 352  
 353          if ( $unspammed > 0 ) {
 354              $messages[] = sprintf(
 355                  /* translators: %s: Number of comments. */
 356                  _n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ),
 357                  $unspammed
 358              );
 359          }
 360  
 361          if ( $trashed > 0 ) {
 362              $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
 363  
 364              $messages[] = sprintf(
 365                  /* translators: %s: Number of comments. */
 366                  _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ),
 367                  $trashed
 368              ) . sprintf(
 369                  ' <a href="%1$s">%2$s</a><br />',
 370                  esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ),
 371                  __( 'Undo' )
 372              );
 373          }
 374  
 375          if ( $untrashed > 0 ) {
 376              $messages[] = sprintf(
 377                  /* translators: %s: Number of comments. */
 378                  _n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ),
 379                  $untrashed
 380              );
 381          }
 382  
 383          if ( $deleted > 0 ) {
 384              $messages[] = sprintf(
 385                  /* translators: %s: Number of comments. */
 386                  _n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ),
 387                  $deleted
 388              );
 389          }
 390  
 391          if ( $same > 0 ) {
 392              $comment = get_comment( $same );
 393              if ( $comment ) {
 394                  switch ( $comment->comment_approved ) {
 395                      case '1':
 396                          $messages[] = __( 'This comment is already approved.' ) . sprintf(
 397                              ' <a href="%1$s">%2$s</a>',
 398                              esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ),
 399                              __( 'Edit comment' )
 400                          );
 401                          break;
 402                      case 'trash':
 403                          $messages[] = __( 'This comment is already in the Trash.' ) . sprintf(
 404                              ' <a href="%1$s">%2$s</a>',
 405                              esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ),
 406                              __( 'View Trash' )
 407                          );
 408                          break;
 409                      case 'spam':
 410                          $messages[] = __( 'This comment is already marked as spam.' ) . sprintf(
 411                              ' <a href="%1$s">%2$s</a>',
 412                              esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ),
 413                              __( 'Edit comment' )
 414                          );
 415                          break;
 416                  }
 417              }
 418          }
 419  
 420          wp_admin_notice(
 421              implode( "<br />\n", $messages ),
 422              array(
 423                  'id'                 => 'moderated',
 424                  'additional_classes' => array( 'updated' ),
 425                  'dismissible'        => true,
 426              )
 427          );
 428      }
 429  }
 430  ?>
 431  
 432  <?php $wp_list_table->views(); ?>
 433  
 434  <form id="comments-form" method="get">
 435  
 436  <?php $wp_list_table->search_box( __( 'Search Comments' ), 'comment' ); ?>
 437  
 438  <?php if ( $post_id ) : ?>
 439  <input type="hidden" name="p" value="<?php echo esc_attr( (int) $post_id ); ?>" />
 440  <?php endif; ?>
 441  <input type="hidden" name="comment_status" value="<?php echo esc_attr( $comment_status ); ?>" />
 442  <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr( current_time( 'mysql', 1 ) ); ?>" />
 443  
 444  <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'total_items' ) ); ?>" />
 445  <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'per_page' ) ); ?>" />
 446  <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'page' ) ); ?>" />
 447  
 448  <?php if ( isset( $_REQUEST['paged'] ) ) { ?>
 449      <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
 450  <?php } ?>
 451  
 452  <?php $wp_list_table->display(); ?>
 453  </form>
 454  </div>
 455  
 456  <div id="ajax-response"></div>
 457  
 458  <?php
 459  wp_comment_reply( '-1', true, 'detail' );
 460  wp_comment_trashnotice();
 461  require_once  ABSPATH . 'wp-admin/admin-footer.php'; ?>


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref