PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/comment.php

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