[ 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://codex.wordpress.org/Administration_Screens#Comments">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          /* translators: 1: comment date, 2: comment time */
 208          $submitted = sprintf(
 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              get_comment_date( __( 'g:i a' ), $comment )
 213          );
 214          if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
 215              echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>';
 216          } else {
 217              echo $submitted;
 218          }
 219          ?>
 220          </td>
 221      </tr>
 222      <tr>
 223      <th scope="row"><?php /* translators: field name in comment form */ _ex( 'Comment', 'noun' ); ?></th>
 224      <td class="comment-content">
 225          <?php comment_text( $comment ); ?>
 226      <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>
 227      </td>
 228      </tr>
 229      </table>
 230  
 231      <form action="comment.php" method="get" class="comment-ays-submit">
 232  
 233      <p>
 234          <?php submit_button( $button, 'primary', 'submit', false ); ?>
 235      <a href="<?php echo admin_url( 'edit-comments.php' ); ?>" class="button-cancel"><?php esc_html_e( 'Cancel' ); ?></a>
 236      </p>
 237  
 238          <?php wp_nonce_field( $nonce_action ); ?>
 239      <input type="hidden" name="action" value="<?php echo esc_attr( $formaction ); ?>" />
 240      <input type="hidden" name="c" value="<?php echo esc_attr( $comment->comment_ID ); ?>" />
 241      <input type="hidden" name="noredir" value="1" />
 242      </form>
 243  
 244      </div>
 245          <?php
 246          break;
 247  
 248      case 'deletecomment':
 249      case 'trashcomment':
 250      case 'untrashcomment':
 251      case 'spamcomment':
 252      case 'unspamcomment':
 253      case 'approvecomment':
 254      case 'unapprovecomment':
 255          $comment_id = absint( $_REQUEST['c'] );
 256  
 257          if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
 258              check_admin_referer( 'approve-comment_' . $comment_id );
 259          } else {
 260              check_admin_referer( 'delete-comment_' . $comment_id );
 261          }
 262  
 263          $noredir = isset( $_REQUEST['noredir'] );
 264  
 265          $comment = get_comment( $comment_id );
 266          if ( ! $comment ) {
 267              comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'edit-comments.php' ) );
 268          }
 269          if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
 270              comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
 271          }
 272  
 273          if ( '' != wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) {
 274              $redir = wp_get_referer();
 275          } elseif ( '' != wp_get_original_referer() && ! $noredir ) {
 276              $redir = wp_get_original_referer();
 277          } elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
 278              $redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
 279          } else {
 280              $redir = admin_url( 'edit-comments.php' );
 281          }
 282  
 283          $redir = remove_query_arg( array( 'spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved' ), $redir );
 284  
 285          switch ( $action ) {
 286              case 'deletecomment':
 287                  wp_delete_comment( $comment );
 288                  $redir = add_query_arg( array( 'deleted' => '1' ), $redir );
 289                  break;
 290              case 'trashcomment':
 291                  wp_trash_comment( $comment );
 292                  $redir = add_query_arg(
 293                      array(
 294                          'trashed' => '1',
 295                          'ids'     => $comment_id,
 296                      ),
 297                      $redir
 298                  );
 299                  break;
 300              case 'untrashcomment':
 301                  wp_untrash_comment( $comment );
 302                  $redir = add_query_arg( array( 'untrashed' => '1' ), $redir );
 303                  break;
 304              case 'spamcomment':
 305                  wp_spam_comment( $comment );
 306                  $redir = add_query_arg(
 307                      array(
 308                          'spammed' => '1',
 309                          'ids'     => $comment_id,
 310                      ),
 311                      $redir
 312                  );
 313                  break;
 314              case 'unspamcomment':
 315                  wp_unspam_comment( $comment );
 316                  $redir = add_query_arg( array( 'unspammed' => '1' ), $redir );
 317                  break;
 318              case 'approvecomment':
 319                  wp_set_comment_status( $comment, 'approve' );
 320                  $redir = add_query_arg( array( 'approved' => 1 ), $redir );
 321                  break;
 322              case 'unapprovecomment':
 323                  wp_set_comment_status( $comment, 'hold' );
 324                  $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
 325                  break;
 326          }
 327  
 328          wp_redirect( $redir );
 329          die;
 330  
 331      case 'editedcomment':
 332          $comment_id      = absint( $_POST['comment_ID'] );
 333          $comment_post_id = absint( $_POST['comment_post_ID'] );
 334  
 335          check_admin_referer( 'update-comment_' . $comment_id );
 336  
 337          edit_comment();
 338  
 339          $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
 340  
 341          /**
 342           * Filters the URI the user is redirected to after editing a comment in the admin.
 343           *
 344           * @since 2.1.0
 345           *
 346           * @param string $location The URI the user will be redirected to.
 347           * @param int $comment_id The ID of the comment being edited.
 348           */
 349          $location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
 350          wp_redirect( $location );
 351  
 352          exit();
 353  
 354      default:
 355          wp_die( __( 'Unknown action.' ) );
 356  
 357  } // end switch
 358  
 359  include( ABSPATH . 'wp-admin/admin-footer.php' );


Generated: Wed Jul 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1