25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

334 lines
10 KiB

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