[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> comment.php (source)

   1  <?php
   2  /**
   3   * Comment Management Screen
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** Load WordPress Bootstrap */
  10  require_once( dirname( __FILE__ ) . '/admin.php' );
  11  
  12  $parent_file  = 'edit-comments.php';
  13  $submenu_file = 'edit-comments.php';
  14  
  15  /**
  16   * @global string $action
  17   */
  18  global $action;
  19  wp_reset_vars( array( 'action' ) );
  20  
  21  if ( isset( $_POST['deletecomment'] ) ) {
  22      $action = 'deletecomment';
  23  }
  24  
  25  if ( 'cdc' == $action ) {
  26      $action = 'delete';
  27  } elseif ( 'mac' == $action ) {
  28      $action = 'approve';
  29  }
  30  
  31  if ( isset( $_GET['dt'] ) ) {
  32      if ( 'spam' == $_GET['dt'] ) {
  33          $action = 'spam';
  34      } elseif ( 'trash' == $_GET['dt'] ) {
  35          $action = 'trash';
  36      }
  37  }
  38  
  39  switch ( $action ) {
  40  
  41      case 'editcomment':
  42          $title = __( 'Edit Comment' );
  43  
  44          get_current_screen()->add_help_tab(
  45              array(
  46                  'id'      => 'overview',
  47                  'title'   => __( 'Overview' ),
  48                  'content' =>
  49                      '<p>' . __( 'You can edit the information left in a comment if needed. This is often useful when you notice that a commenter has made a typographical error.' ) . '</p>' .
  50                      '<p>' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '</p>',
  51              )
  52          );
  53  
  54          get_current_screen()->set_help_sidebar(
  55              '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  56              '<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' .
  57              '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  58          );
  59  
  60          wp_enqueue_script( 'comment' );
  61          require_once( ABSPATH . 'wp-admin/admin-header.php' );
  62  
  63          $comment_id = absint( $_GET['c'] );
  64  
  65          $comment = get_comment( $comment_id );
  66          if ( ! $comment ) {
  67              comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'javascript:history.go(-1)' ) );
  68          }
  69  
  70          if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
  71              comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) );
  72          }
  73  
  74          if ( 'trash' == $comment->comment_approved ) {
  75              comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) );
  76          }
  77  
  78          $comment = get_comment_to_edit( $comment_id );
  79  
  80          include( ABSPATH . 'wp-admin/edit-form-comment.php' );
  81  
  82          break;
  83  
  84      case 'delete':
  85      case 'approve':
  86      case 'trash':
  87      case 'spam':
  88          $title = __( 'Moderate Comment' );
  89  
  90          $comment_id = absint( $_GET['c'] );
  91  
  92          $comment = get_comment( $comment_id );
  93          if ( ! $comment ) {
  94              wp_redirect( admin_url( 'edit-comments.php?error=1' ) );
  95              die();
  96          }
  97  
  98          if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
  99              wp_redirect( admin_url( 'edit-comments.php?error=2' ) );
 100              die();
 101          }
 102  
 103          // No need to re-approve/re-trash/re-spam a comment.
 104          if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
 105              wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
 106              die();
 107          }
 108  
 109          require_once( ABSPATH . 'wp-admin/admin-header.php' );
 110  
 111          $formaction    = $action . 'comment';
 112          $nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
 113          $nonce_action .= $comment_id;
 114  
 115          ?>
 116      <div class="wrap">
 117  
 118      <h1><?php echo esc_html( $title ); ?></h1>
 119  
 120          <?php
 121          switch ( $action ) {
 122              case 'spam':
 123                  $caution_msg = __( 'You are about to mark the following comment as spam:' );
 124                  $button      = _x( 'Mark as Spam', 'comment' );
 125                  break;
 126              case 'trash':
 127                  $caution_msg = __( 'You are about to move the following comment to the Trash:' );
 128                  $button      = __( 'Move to Trash' );
 129                  break;
 130              case 'delete':
 131                  $caution_msg = __( 'You are about to delete the following comment:' );
 132                  $button      = __( 'Permanently Delete Comment' );
 133                  break;
 134              default:
 135                  $caution_msg = __( 'You are about to approve the following comment:' );
 136                  $button      = __( 'Approve Comment' );
 137                  break;
 138          }
 139  
 140          if ( $comment->comment_approved != '0' ) { // if not unapproved
 141              $message = '';
 142              switch ( $comment->comment_approved ) {
 143                  case '1':
 144                      $message = __( 'This comment is currently approved.' );
 145                      break;
 146                  case 'spam':
 147                      $message = __( 'This comment is currently marked as spam.' );
 148                      break;
 149                  case 'trash':
 150                      $message = __( 'This comment is currently in the Trash.' );
 151                      break;
 152              }
 153              if ( $message ) {
 154                  echo '<div id="message" class="notice notice-info"><p>' . $message . '</p></div>';
 155              }
 156          }
 157          ?>
 158  <div id="message" class="notice notice-warning"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo $caution_msg; ?></p></div>
 159  
 160  <table class="form-table comment-ays">
 161  <tr>
 162  <th scope="row"><?php _e( 'Author' ); ?></th>
 163  <td><?php comment_author( $comment ); ?></td>
 164  </tr>
 165          <?php if ( get_comment_author_email( $comment ) ) { ?>
 166  <tr>
 167  <th scope="row"><?php _e( 'Email' ); ?></th>
 168  <td><?php comment_author_email( $comment ); ?></td>
 169  </tr>
 170  <?php } ?>
 171          <?php if ( get_comment_author_url( $comment ) ) { ?>
 172  <tr>
 173  <th scope="row"><?php _e( 'URL' ); ?></th>
 174  <td><a href="<?php comment_author_url( $comment ); ?>"><?php comment_author_url( $comment ); ?></a></td>
 175  </tr>
 176  <?php } ?>
 177  <tr>
 178      <th scope="row"><?php /* translators: Column name or table row header. */ _e( 'In Response To' ); ?></th>
 179      <td>
 180          <?php
 181          $post_id = $comment->comment_post_ID;
 182          if ( current_user_can( 'edit_post', $post_id ) ) {
 183              $post_link  = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
 184              $post_link .= esc_html( get_the_title( $post_id ) ) . '</a>';
 185          } else {
 186              $post_link = esc_html( get_the_title( $post_id ) );
 187          }
 188          echo $post_link;
 189  
 190          if ( $comment->comment_parent ) {
 191              $parent      = get_comment( $comment->comment_parent );
 192              $parent_link = esc_url( get_comment_link( $parent ) );
 193              $name        = get_comment_author( $parent );
 194              printf(
 195                  /* translators: %s: Comment link. */
 196                  ' | ' . __( 'In reply to %s.' ),
 197                  '<a href="' . $parent_link . '">' . $name . '</a>'
 198              );
 199          }
 200          ?>
 201      </td>
 202      </tr>
 203      <tr>
 204      <th scope="row"><?php _e( 'Submitted on' ); ?></th>
 205      <td>
 206          <?php
 207          $submitted = sprintf(
 208              /* translators: 1: Comment date, 2: Comment time. */
 209              __( '%1$s at %2$s' ),
 210              /* translators: Comment date format. See https://secure.php.net/date */
 211              get_comment_date( __( 'Y/m/d' ), $comment ),
 212              /* translators: Comment time format. See https://secure.php.net/date */
 213              get_comment_date( __( 'g:i a' ), $comment )
 214          );
 215          if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
 216              echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>';
 217          } else {
 218              echo $submitted;
 219          }
 220          ?>
 221          </td>
 222      </tr>
 223      <tr>
 224      <th scope="row"><?php /* translators: Field name in comment form. */ _ex( 'Comment', 'noun' ); ?></th>
 225      <td class="comment-content">
 226          <?php comment_text( $comment ); ?>
 227      <p class="edit-comment"><a href="<?php echo admin_url( "comment.php?action=editcomment&amp;c={$comment->comment_ID}" ); ?>"><?php esc_html_e( 'Edit' ); ?></a></p>
 228      </td>
 229      </tr>
 230      </table>
 231  
 232      <form action="comment.php" method="get" class="comment-ays-submit">
 233  
 234      <p>
 235          <?php submit_button( $button, 'primary', 'submit', false ); ?>
 236      <a href="<?php echo admin_url( 'edit-comments.php' ); ?>" class="button-cancel"><?php esc_html_e( 'Cancel' ); ?></a>
 237      </p>
 238  
 239          <?php wp_nonce_field( $nonce_action ); ?>
 240      <input type="hidden" name="action" value="<?php echo esc_attr( $formaction ); ?>" />
 241      <input type="hidden" name="c" value="<?php echo esc_attr( $comment->comment_ID ); ?>" />
 242      <input type="hidden" name="noredir" value="1" />
 243      </form>
 244  
 245      </div>
 246          <?php
 247          break;
 248  
 249      case 'deletecomment':
 250      case 'trashcomment':
 251      case 'untrashcomment':
 252      case 'spamcomment':
 253      case 'unspamcomment':
 254      case 'approvecomment':
 255      case 'unapprovecomment':
 256          $comment_id = absint( $_REQUEST['c'] );
 257  
 258          if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
 259              check_admin_referer( 'approve-comment_' . $comment_id );
 260          } else {
 261              check_admin_referer( 'delete-comment_' . $comment_id );
 262          }
 263  
 264          $noredir = isset( $_REQUEST['noredir'] );
 265  
 266          $comment = get_comment( $comment_id );
 267          if ( ! $comment ) {
 268              comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'edit-comments.php' ) );
 269          }
 270          if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
 271              comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
 272          }
 273  
 274          if ( '' != wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) {
 275              $redir = wp_get_referer();
 276          } elseif ( '' != wp_get_original_referer() && ! $noredir ) {
 277              $redir = wp_get_original_referer();
 278          } elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
 279              $redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
 280          } else {
 281              $redir = admin_url( 'edit-comments.php' );
 282          }
 283  
 284          $redir = remove_query_arg( array( 'spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved' ), $redir );
 285  
 286          switch ( $action ) {
 287              case 'deletecomment':
 288                  wp_delete_comment( $comment );
 289                  $redir = add_query_arg( array( 'deleted' => '1' ), $redir );
 290                  break;
 291              case 'trashcomment':
 292                  wp_trash_comment( $comment );
 293                  $redir = add_query_arg(
 294                      array(
 295                          'trashed' => '1',
 296                          'ids'     => $comment_id,
 297                      ),
 298                      $redir
 299                  );
 300                  break;
 301              case 'untrashcomment':
 302                  wp_untrash_comment( $comment );
 303                  $redir = add_query_arg( array( 'untrashed' => '1' ), $redir );
 304                  break;
 305              case 'spamcomment':
 306                  wp_spam_comment( $comment );
 307                  $redir = add_query_arg(
 308                      array(
 309                          'spammed' => '1',
 310                          'ids'     => $comment_id,
 311                      ),
 312                      $redir
 313                  );
 314                  break;
 315              case 'unspamcomment':
 316                  wp_unspam_comment( $comment );
 317                  $redir = add_query_arg( array( 'unspammed' => '1' ), $redir );
 318                  break;
 319              case 'approvecomment':
 320                  wp_set_comment_status( $comment, 'approve' );
 321                  $redir = add_query_arg( array( 'approved' => 1 ), $redir );
 322                  break;
 323              case 'unapprovecomment':
 324                  wp_set_comment_status( $comment, 'hold' );
 325                  $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
 326                  break;
 327          }
 328  
 329          wp_redirect( $redir );
 330          die;
 331  
 332      case 'editedcomment':
 333          $comment_id      = absint( $_POST['comment_ID'] );
 334          $comment_post_id = absint( $_POST['comment_post_ID'] );
 335  
 336          check_admin_referer( 'update-comment_' . $comment_id );
 337  
 338          edit_comment();
 339  
 340          $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
 341  
 342          /**
 343           * Filters the URI the user is redirected to after editing a comment in the admin.
 344           *
 345           * @since 2.1.0
 346           *
 347           * @param string $location The URI the user will be redirected to.
 348           * @param int $comment_id The ID of the comment being edited.
 349           */
 350          $location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
 351          wp_redirect( $location );
 352  
 353          exit();
 354  
 355      default:
 356          wp_die( __( 'Unknown action.' ) );
 357  
 358  } // end switch
 359  
 360  include( ABSPATH . 'wp-admin/admin-footer.php' );


Generated: Thu Sep 19 01:00:03 2019 Cross-referenced by PHPXref 0.7.1