PageRenderTime 46ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/edit-comments.php

https://bitbucket.org/djmdigital/total-auto-care-wordpress
PHP | 367 lines | 290 code | 45 blank | 32 comment | 56 complexity | 831745d541e43c8a1f1d7a487a183fe0 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, 0BSD
  1. <?php
  2. /**
  3. * Edit Comments Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once( dirname( __FILE__ ) . '/admin.php' );
  10. if ( ! current_user_can( 'edit_posts' ) ) {
  11. wp_die(
  12. '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  13. '<p>' . __( 'Sorry, you are not allowed to edit comments.' ) . '</p>',
  14. 403
  15. );
  16. }
  17. $wp_list_table = _get_list_table( 'WP_Comments_List_Table' );
  18. $pagenum = $wp_list_table->get_pagenum();
  19. $doaction = $wp_list_table->current_action();
  20. if ( $doaction ) {
  21. check_admin_referer( 'bulk-comments' );
  22. if ( 'delete_all' == $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
  23. $comment_status = wp_unslash( $_REQUEST['comment_status'] );
  24. $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
  25. $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) );
  26. $doaction = 'delete';
  27. } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
  28. $comment_ids = $_REQUEST['delete_comments'];
  29. $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
  30. } elseif ( isset( $_REQUEST['ids'] ) ) {
  31. $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
  32. } elseif ( wp_get_referer() ) {
  33. wp_safe_redirect( wp_get_referer() );
  34. exit;
  35. }
  36. $approved = 0;
  37. $unapproved = 0;
  38. $spammed = 0;
  39. $unspammed = 0;
  40. $trashed = 0;
  41. $untrashed = 0;
  42. $deleted = 0;
  43. $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
  44. $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
  45. wp_defer_comment_counting( true );
  46. foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
  47. if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
  48. continue;
  49. }
  50. switch ( $doaction ) {
  51. case 'approve':
  52. wp_set_comment_status( $comment_id, 'approve' );
  53. $approved++;
  54. break;
  55. case 'unapprove':
  56. wp_set_comment_status( $comment_id, 'hold' );
  57. $unapproved++;
  58. break;
  59. case 'spam':
  60. wp_spam_comment( $comment_id );
  61. $spammed++;
  62. break;
  63. case 'unspam':
  64. wp_unspam_comment( $comment_id );
  65. $unspammed++;
  66. break;
  67. case 'trash':
  68. wp_trash_comment( $comment_id );
  69. $trashed++;
  70. break;
  71. case 'untrash':
  72. wp_untrash_comment( $comment_id );
  73. $untrashed++;
  74. break;
  75. case 'delete':
  76. wp_delete_comment( $comment_id );
  77. $deleted++;
  78. break;
  79. }
  80. }
  81. if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {
  82. $screen = get_current_screen()->id;
  83. /**
  84. * Fires when a custom bulk action should be handled.
  85. *
  86. * The redirect link should be modified with success or failure feedback
  87. * from the action to be used to display feedback to the user.
  88. *
  89. * The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
  90. *
  91. * @since 4.7.0
  92. *
  93. * @param string $redirect_url The redirect URL.
  94. * @param string $doaction The action being taken.
  95. * @param array $items The items to take the action on.
  96. */
  97. $redirect_to = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to, $doaction, $comment_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  98. }
  99. wp_defer_comment_counting( false );
  100. if ( $approved ) {
  101. $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
  102. }
  103. if ( $unapproved ) {
  104. $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
  105. }
  106. if ( $spammed ) {
  107. $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
  108. }
  109. if ( $unspammed ) {
  110. $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
  111. }
  112. if ( $trashed ) {
  113. $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
  114. }
  115. if ( $untrashed ) {
  116. $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
  117. }
  118. if ( $deleted ) {
  119. $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
  120. }
  121. if ( $trashed || $spammed ) {
  122. $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
  123. }
  124. wp_safe_redirect( $redirect_to );
  125. exit;
  126. } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
  127. wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
  128. exit;
  129. }
  130. $wp_list_table->prepare_items();
  131. wp_enqueue_script( 'admin-comments' );
  132. enqueue_comment_hotkeys_js();
  133. if ( $post_id ) {
  134. $comments_count = wp_count_comments( $post_id );
  135. $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' );
  136. if ( $comments_count->moderated > 0 ) {
  137. $title = sprintf(
  138. /* translators: 1: Comments count, 2: Post title. */
  139. __( 'Comments (%1$s) on &#8220;%2$s&#8221;' ),
  140. number_format_i18n( $comments_count->moderated ),
  141. $draft_or_post_title
  142. );
  143. } else {
  144. $title = sprintf(
  145. /* translators: %s: Post title. */
  146. __( 'Comments on &#8220;%s&#8221;' ),
  147. $draft_or_post_title
  148. );
  149. }
  150. } else {
  151. $comments_count = wp_count_comments();
  152. if ( $comments_count->moderated > 0 ) {
  153. $title = sprintf(
  154. /* translators: %s: Comments count. */
  155. __( 'Comments (%s)' ),
  156. number_format_i18n( $comments_count->moderated )
  157. );
  158. } else {
  159. $title = __( 'Comments' );
  160. }
  161. }
  162. add_screen_option( 'per_page' );
  163. get_current_screen()->add_help_tab(
  164. array(
  165. 'id' => 'overview',
  166. 'title' => __( 'Overview' ),
  167. 'content' =>
  168. '<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>',
  169. )
  170. );
  171. get_current_screen()->add_help_tab(
  172. array(
  173. 'id' => 'moderating-comments',
  174. 'title' => __( 'Moderating Comments' ),
  175. 'content' =>
  176. '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
  177. '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and blog 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>' .
  178. '<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>' .
  179. '<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>' .
  180. '<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>' .
  181. '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>',
  182. )
  183. );
  184. get_current_screen()->set_help_sidebar(
  185. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  186. '<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' .
  187. '<p>' . __( '<a href="https://wordpress.org/support/article/comment-spam/">Documentation on Comment Spam</a>' ) . '</p>' .
  188. '<p>' . __( '<a href="https://wordpress.org/support/article/keyboard-shortcuts/">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
  189. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  190. );
  191. get_current_screen()->set_screen_reader_content(
  192. array(
  193. 'heading_views' => __( 'Filter comments list' ),
  194. 'heading_pagination' => __( 'Comments list navigation' ),
  195. 'heading_list' => __( 'Comments list' ),
  196. )
  197. );
  198. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  199. ?>
  200. <div class="wrap">
  201. <h1 class="wp-heading-inline">
  202. <?php
  203. if ( $post_id ) {
  204. printf(
  205. /* translators: %s: Link to post. */
  206. __( 'Comments on &#8220;%s&#8221;' ),
  207. sprintf(
  208. '<a href="%1$s">%2$s</a>',
  209. get_edit_post_link( $post_id ),
  210. wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' )
  211. )
  212. );
  213. } else {
  214. _e( 'Comments' );
  215. }
  216. ?>
  217. </h1>
  218. <?php
  219. if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
  220. echo '<span class="subtitle">';
  221. printf(
  222. /* translators: %s: Search query. */
  223. __( 'Search results for &#8220;%s&#8221;' ),
  224. wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '&hellip;' )
  225. );
  226. echo '</span>';
  227. }
  228. ?>
  229. <hr class="wp-header-end">
  230. <?php
  231. if ( isset( $_REQUEST['error'] ) ) {
  232. $error = (int) $_REQUEST['error'];
  233. $error_msg = '';
  234. switch ( $error ) {
  235. case 1:
  236. $error_msg = __( 'Invalid comment ID.' );
  237. break;
  238. case 2:
  239. $error_msg = __( 'Sorry, you are not allowed to edit comments on this post.' );
  240. break;
  241. }
  242. if ( $error_msg ) {
  243. echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
  244. }
  245. }
  246. if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) || isset( $_REQUEST['spammed'] ) || isset( $_REQUEST['unspammed'] ) || isset( $_REQUEST['same'] ) ) {
  247. $approved = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
  248. $deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
  249. $trashed = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
  250. $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
  251. $spammed = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
  252. $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
  253. $same = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
  254. if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
  255. if ( $approved > 0 ) {
  256. /* translators: %s: Number of comments. */
  257. $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
  258. }
  259. if ( $spammed > 0 ) {
  260. $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
  261. /* translators: %s: Number of comments. */
  262. $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />';
  263. }
  264. if ( $unspammed > 0 ) {
  265. /* translators: %s: Number of comments. */
  266. $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
  267. }
  268. if ( $trashed > 0 ) {
  269. $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
  270. /* translators: %s: Number of comments. */
  271. $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />';
  272. }
  273. if ( $untrashed > 0 ) {
  274. /* translators: %s: Number of comments. */
  275. $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed );
  276. }
  277. if ( $deleted > 0 ) {
  278. /* translators: %s: Number of comments. */
  279. $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
  280. }
  281. if ( $same > 0 ) {
  282. $comment = get_comment( $same );
  283. if ( $comment ) {
  284. switch ( $comment->comment_approved ) {
  285. case '1':
  286. $messages[] = __( 'This comment is already approved.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
  287. break;
  288. case 'trash':
  289. $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
  290. break;
  291. case 'spam':
  292. $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
  293. break;
  294. }
  295. }
  296. }
  297. echo '<div id="moderated" class="updated notice is-dismissible"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
  298. }
  299. }
  300. ?>
  301. <?php $wp_list_table->views(); ?>
  302. <form id="comments-form" method="get">
  303. <?php $wp_list_table->search_box( __( 'Search Comments' ), 'comment' ); ?>
  304. <?php if ( $post_id ) : ?>
  305. <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
  306. <?php endif; ?>
  307. <input type="hidden" name="comment_status" value="<?php echo esc_attr( $comment_status ); ?>" />
  308. <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr( current_time( 'mysql', 1 ) ); ?>" />
  309. <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'total_items' ) ); ?>" />
  310. <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'per_page' ) ); ?>" />
  311. <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'page' ) ); ?>" />
  312. <?php if ( isset( $_REQUEST['paged'] ) ) { ?>
  313. <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
  314. <?php } ?>
  315. <?php $wp_list_table->display(); ?>
  316. </form>
  317. </div>
  318. <div id="ajax-response"></div>
  319. <?php
  320. wp_comment_reply( '-1', true, 'detail' );
  321. wp_comment_trashnotice();
  322. include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>