3 * Edit Comments Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 if ( !current_user_can('edit_posts') )
13 wp_die(__('Cheatin’ uh?'));
15 wp_enqueue_script('admin-comments');
16 enqueue_comment_hotkeys_js();
18 $post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
20 if ( isset($_REQUEST['doaction']) || isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) {
21 check_admin_referer('bulk-comments');
23 if ( (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp']) ) {
24 $comment_status = $wpdb->escape($_REQUEST['comment_status']);
25 $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']);
26 $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
28 } elseif ( ($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments']) ) {
29 $comment_ids = $_REQUEST['delete_comments'];
30 $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
31 } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) {
32 $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) );
33 $doaction = $_REQUEST['action'];
35 wp_redirect( wp_get_referer() );
38 $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
39 $redirect_to = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids'), wp_get_referer() );
41 foreach ($comment_ids as $comment_id) { // Check the permissions on each
42 $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
44 if ( !current_user_can('edit_post', $_post_id) )
49 wp_set_comment_status($comment_id, 'approve');
53 wp_set_comment_status($comment_id, 'hold');
57 wp_spam_comment($comment_id);
61 wp_unspam_comment($comment_id);
65 wp_trash_comment($comment_id);
69 wp_untrash_comment($comment_id);
73 wp_delete_comment($comment_id);
80 $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
82 $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
84 $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
86 $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
88 $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
90 $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
92 $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
93 if ( $trashed || $spammed )
94 $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to );
96 wp_redirect( $redirect_to );
98 } elseif ( ! empty($_GET['_wp_http_referer']) ) {
99 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
104 $title = sprintf(__('Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
106 $title = __('Comments');
108 add_contextual_help( $current_screen, '<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>' .
109 '<p>' . __('A yellow row means the comment is waiting for you to moderate it.') . '</p>' .
110 '<p>' . __('In the Author column, in addition to the author’s name, email address, and blog URL, the commenter’s IP address is shown. Clicking on this link will show you all the comments made from this IP address.') . '</p>' .
111 '<p>' . __('In the Comment column, above each comment it says “Submitted on,” followed by the date and time the comment was left on your site. Clicking on the date/time link will take you to that comment on your live site.') . '</p>' .
112 '<p>' . __('In the In Response To 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 “#” permalink symbol below leads to that post on your live site. The small bubble with the number in it shows how many comments that post has received. If the bubble is gray, you have moderated all comments for that post. If it is blue, there are pending comments. Clicking the bubble will filter the comments screen to show only comments on that post.') . '</p>' .
113 '<p>' . __('Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link below to learn more.') . '</p>' .
114 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
115 '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Panels#Comments" target="_blank">Comments Documentation</a>' ) . '</p>' .
116 '<p>' . __( '<a href="http://codex.wordpress.org/Comment_Spam" target="_blank">Comment Spam Documentation</a>') . '</p>' .
117 '<p>' . __( '<a href="http://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">Keyboard Shortcuts Documentation</a>') . '</p>' .
118 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
120 require_once('./admin-header.php');
122 $mode = ( empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
124 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
125 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash')) )
126 $comment_status = 'all';
128 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
130 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
131 $search = esc_attr( $search_dirty ); ?>
134 <?php screen_icon(); ?>
135 <h2><?php echo esc_html( $title );
136 if ( isset($_GET['s']) && $_GET['s'] )
137 printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
141 if ( isset( $_GET['error'] ) ) {
142 $error = (int) $_GET['error'];
146 $error_msg = __( 'Oops, no comment with this ID.' );
149 $error_msg = __( 'You are not allowed to edit comments on this post.' );
153 echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
156 if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) || isset($_GET['same']) ) {
157 $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
158 $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
159 $trashed = isset( $_GET['trashed'] ) ? (int) $_GET['trashed'] : 0;
160 $untrashed = isset( $_GET['untrashed'] ) ? (int) $_GET['untrashed'] : 0;
161 $spammed = isset( $_GET['spammed'] ) ? (int) $_GET['spammed'] : 0;
162 $unspammed = isset( $_GET['unspammed'] ) ? (int) $_GET['unspammed'] : 0;
163 $same = isset( $_GET['same'] ) ? (int) $_GET['same'] : 0;
165 if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
167 $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
169 if ( $spammed > 0 ) {
170 $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
171 $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 />';
174 if ( $unspammed > 0 )
175 $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
177 if ( $trashed > 0 ) {
178 $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
179 $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 />';
182 if ( $untrashed > 0 )
183 $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed );
186 $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
188 if ( $same > 0 && $comment = get_comment( $same ) ) {
189 switch ( $comment->comment_approved ) {
191 $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
194 $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
197 $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
202 echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
207 <form id="comments-form" action="" method="get">
208 <ul class="subsubsub">
210 $status_links = array();
211 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
212 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
213 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
215 'all' => _nx_noop('All', 'All', 'comments'), // singular not used
216 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
217 'approved' => _n_noop('Approved', 'Approved'), // singular not used
218 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
219 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
222 if ( !EMPTY_TRASH_DAYS )
223 unset($stati['trash']);
225 $link = 'edit-comments.php';
226 if ( !empty($comment_type) && 'all' != $comment_type )
227 $link = add_query_arg( 'comment_type', $comment_type, $link );
229 foreach ( $stati as $status => $label ) {
230 $class = ( $status == $comment_status ) ? ' class="current"' : '';
232 if ( !isset( $num_comments->$status ) )
233 $num_comments->$status = 10;
234 $link = add_query_arg( 'comment_status', $status, $link );
236 $link = add_query_arg( 'p', absint( $post_id ), $link );
238 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
239 if ( !empty( $_GET['s'] ) )
240 $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
242 $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
243 _n( $label[0], $label[1], $num_comments->$status ),
244 number_format_i18n( $num_comments->$status )
248 $status_links = apply_filters( 'comment_status_links', $status_links );
250 echo implode( " |</li>\n", $status_links) . '</li>';
251 unset($status_links);
255 <p class="search-box">
256 <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
257 <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
258 <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" />
262 $comments_per_page = (int) get_user_option( 'edit_comments_per_page' );
263 if ( empty( $comments_per_page ) || $comments_per_page < 1 )
264 $comments_per_page = 20;
265 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
267 if ( isset( $_GET['apage'] ) )
268 $page = abs( (int) $_GET['apage'] );
272 $start = $offset = ( $page - 1 ) * $comments_per_page;
274 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
276 $_comment_post_ids = array();
277 foreach ( $_comments as $_c ) {
278 $_comment_post_ids[] = $_c->comment_post_ID;
281 $_comment_pending_count = get_pending_comments_num($_comment_post_ids);
283 $comments = array_slice($_comments, 0, $comments_per_page);
284 $extra_comments = array_slice($_comments, $comments_per_page);
286 $page_links = paginate_links( array(
287 'base' => add_query_arg( 'apage', '%#%' ),
289 'prev_text' => __('«'),
290 'next_text' => __('»'),
291 'total' => ceil($total / $comments_per_page),
297 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
298 <?php if ( $post_id ) : ?>
299 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
301 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
302 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
304 <div class="tablenav">
306 <?php if ( $page_links ) : ?>
307 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
308 number_format_i18n( $start + 1 ),
309 number_format_i18n( min( $page * $comments_per_page, $total ) ),
310 '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
312 ); echo $page_links_text; ?></div>
313 <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
314 <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
315 <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
318 <?php if ( $comments ) : ?>
319 <div class="alignleft actions">
320 <select name="action">
321 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
322 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
323 <option value="unapprove"><?php _e('Unapprove'); ?></option>
325 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
326 <option value="approve"><?php _e('Approve'); ?></option>
328 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
329 <option value="spam"><?php _ex('Mark as Spam', 'comment'); ?></option>
331 <?php if ( 'trash' == $comment_status ): ?>
332 <option value="untrash"><?php _e('Restore'); ?></option>
333 <?php elseif ( 'spam' == $comment_status ): ?>
334 <option value="unspam"><?php _ex('Not Spam', 'comment'); ?></option>
336 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
337 <option value="delete"><?php _e('Delete Permanently'); ?></option>
339 <option value="trash"><?php _e('Move to Trash'); ?></option>
342 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
343 <?php wp_nonce_field('bulk-comments'); ?>
347 <select name="comment_type">
348 <option value="all"><?php _e('Show all comment types'); ?></option>
350 $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
351 'comment' => __('Comments'),
352 'pings' => __('Pings'),
355 foreach ( $comment_types as $type => $label ) {
356 echo " <option value='" . esc_attr($type) . "'";
357 selected( $comment_type, $type );
358 echo ">$label</option>\n";
362 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
364 <?php if ( isset($_GET['apage']) ) { ?>
365 <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
368 if ( ( 'spam' == $comment_status || 'trash' == $comment_status) && current_user_can ('moderate_comments') ) {
369 wp_nonce_field('bulk-destroy', '_destroy_nonce');
370 if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
371 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
372 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
373 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
376 <?php do_action('manage_comments_nav', $comment_status); ?>
383 <div class="clear"></div>
384 <?php if ( $comments ) { ?>
386 <table class="widefat comments fixed" cellspacing="0">
389 <?php print_column_headers('edit-comments'); ?>
395 <?php print_column_headers('edit-comments', false); ?>
399 <tbody id="the-comment-list" class="list:comment">
401 foreach ($comments as $comment)
402 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
405 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
407 foreach ($extra_comments as $comment)
408 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
413 <div class="tablenav">
416 echo "<div class='tablenav-pages'>$page_links_text</div>";
419 <div class="alignleft actions">
420 <select name="action2">
421 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
422 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
423 <option value="unapprove"><?php _e('Unapprove'); ?></option>
425 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
426 <option value="approve"><?php _e('Approve'); ?></option>
428 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
429 <option value="spam"><?php _ex('Mark as Spam', 'comment'); ?></option>
431 <?php if ( 'trash' == $comment_status ): ?>
432 <option value="untrash"><?php _e('Restore'); ?></option>
434 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
435 <option value="delete"><?php _e('Delete Permanently'); ?></option>
436 <?php elseif ( 'spam' == $comment_status ): ?>
437 <option value="unspam"><?php _ex('Not Spam', 'comment'); ?></option>
439 <option value="trash"><?php _e('Move to Trash'); ?></option>
442 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
444 <?php if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
445 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
446 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
447 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
449 <?php do_action('manage_comments_nav', $comment_status); ?>
457 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
458 <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
459 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
460 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
461 <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
462 <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
463 <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
464 <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
465 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
468 <div id="ajax-response"></div>
470 <?php } elseif ( 'moderated' == $comment_status ) { ?>
471 <p><?php _e('No comments awaiting moderation… yet.') ?></p>
476 <p><?php _e('No comments found.') ?></p>
484 wp_comment_reply('-1', true, 'detail');
485 wp_comment_trashnotice();
486 include('./admin-footer.php'); ?>