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['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spam2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
21 check_admin_referer('bulk-spam-delete', '_spam_nonce');
23 $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
24 if ( current_user_can('moderate_comments')) {
25 $deleted_spam = $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" );
29 $redirect_to = 'edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam;
31 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
32 wp_redirect( $redirect_to );
33 } elseif ( isset($_REQUEST['delete_comments']) && isset($_REQUEST['action']) && ( -1 != $_REQUEST['action'] || -1 != $_REQUEST['action2'] ) ) {
34 check_admin_referer('bulk-comments');
35 $doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
37 $deleted = $approved = $unapproved = $spammed = 0;
38 foreach ( (array) $_REQUEST['delete_comments'] as $comment_id) : // Check the permissions on each
39 $comment_id = (int) $comment_id;
40 $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
42 if ( !current_user_can('edit_post', $_post_id) )
47 wp_set_comment_status($comment_id, 'spam');
51 wp_set_comment_status($comment_id, 'delete');
55 wp_set_comment_status($comment_id, 'approve');
59 wp_set_comment_status($comment_id, 'hold');
65 $redirect_to = 'edit-comments.php?deleted=' . $deleted . '&approved=' . $approved . '&spam=' . $spammed . '&unapproved=' . $unapproved;
67 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
68 if ( isset($_REQUEST['apage']) )
69 $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
70 if ( !empty($_REQUEST['mode']) )
71 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
72 if ( !empty($_REQUEST['comment_status']) )
73 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
74 if ( !empty($_REQUEST['s']) )
75 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
76 wp_redirect( $redirect_to );
77 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
78 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
83 $title = sprintf(__('Edit Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
85 $title = __('Edit Comments');
87 require_once('admin-header.php');
89 $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
91 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
92 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) )
93 $comment_status = 'all';
95 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
97 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
98 $search = esc_attr( $search_dirty ); ?>
101 <?php screen_icon(); ?>
102 <h2><?php echo esc_html( $title );
103 if ( isset($_GET['s']) && $_GET['s'] )
104 printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
108 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
109 $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
110 $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
111 $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
113 if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
114 echo '<div id="moderated" class="updated fade"><p>';
116 if ( $approved > 0 ) {
117 printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
121 if ( $deleted > 0 ) {
122 printf( _n( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
127 printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
136 <form id="comments-form" action="" method="get">
137 <ul class="subsubsub">
139 $status_links = array();
140 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
141 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
142 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
144 'all' => _n_noop('All', 'All'), // singular not used
145 'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
146 'approved' => _n_noop('Approved', 'Approved'), // singular not used
147 'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
149 $link = 'edit-comments.php';
150 if ( !empty($comment_type) && 'all' != $comment_type )
151 $link = add_query_arg( 'comment_type', $comment_type, $link );
152 foreach ( $stati as $status => $label ) {
155 if ( $status == $comment_status )
156 $class = ' class="current"';
157 if ( !isset( $num_comments->$status ) )
158 $num_comments->$status = 10;
159 $link = add_query_arg( 'comment_status', $status, $link );
161 $link = add_query_arg( 'p', absint( $post_id ), $link );
163 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
164 if ( !empty( $_GET['s'] ) )
165 $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
167 $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
168 _n( $label[0], $label[1], $num_comments->$status ),
169 number_format_i18n( $num_comments->$status )
173 $status_links = apply_filters( 'comment_status_links', $status_links );
175 echo implode( " |</li>\n", $status_links) . '</li>';
176 unset($status_links);
180 <p class="search-box">
181 <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
182 <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
183 <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" />
187 $comments_per_page = get_user_option('edit_comments_per_page');
188 if ( empty($comments_per_page) )
189 $comments_per_page = 20;
190 $comments_per_page = apply_filters('comments_per_page', $comments_per_page, $comment_status);
192 if ( isset( $_GET['apage'] ) )
193 $page = abs( (int) $_GET['apage'] );
197 $start = $offset = ( $page - 1 ) * $comments_per_page;
199 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
201 $_comment_post_ids = array();
202 foreach ( $_comments as $_c ) {
203 $_comment_post_ids[] = $_c->comment_post_ID;
205 $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
206 foreach ( (array) $_comment_post_ids as $_cpid )
207 $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
208 if ( empty($_comment_pending_count) )
209 $_comment_pending_count = array();
211 $comments = array_slice($_comments, 0, $comments_per_page);
212 $extra_comments = array_slice($_comments, $comments_per_page);
214 $page_links = paginate_links( array(
215 'base' => add_query_arg( 'apage', '%#%' ),
217 'prev_text' => __('«'),
218 'next_text' => __('»'),
219 'total' => ceil($total / $comments_per_page),
225 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
226 <?php if ( $post_id ) : ?>
227 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
229 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
230 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
232 <div class="tablenav">
234 <?php if ( $page_links ) : ?>
235 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
236 number_format_i18n( $start + 1 ),
237 number_format_i18n( min( $page * $comments_per_page, $total ) ),
238 '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
240 ); echo $page_links_text; ?></div>
241 <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
242 <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
243 <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
246 <div class="alignleft actions">
247 <select name="action">
248 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
249 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
250 <option value="unapprove"><?php _e('Unapprove'); ?></option>
252 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
253 <option value="approve"><?php _e('Approve'); ?></option>
255 <?php if ( 'spam' != $comment_status ): ?>
256 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
258 <option value="delete"><?php _e('Delete'); ?></option>
260 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
261 <?php wp_nonce_field('bulk-comments'); ?>
263 <select name="comment_type">
264 <option value="all"><?php _e('Show all comment types'); ?></option>
266 $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
267 'comment' => __('Comments'),
268 'pings' => __('Pings'),
271 foreach ( $comment_types as $type => $label ) {
272 echo " <option value='" . esc_attr($type) . "'";
273 selected( $comment_type, $type );
274 echo ">$label</option>\n";
278 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
280 <?php if ( isset($_GET['apage']) ) { ?>
281 <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
284 if ( 'spam' == $comment_status ) {
285 wp_nonce_field('bulk-spam-delete', '_spam_nonce');
286 if ( current_user_can ('moderate_comments')) { ?>
287 <input type="submit" name="delete_all_spam" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
290 <?php do_action('manage_comments_nav', $comment_status); ?>
297 <div class="clear"></div>
299 <?php if ( $comments ) { ?>
300 <table class="widefat comments fixed" cellspacing="0">
303 <?php print_column_headers('edit-comments'); ?>
309 <?php print_column_headers('edit-comments', false); ?>
313 <tbody id="the-comment-list" class="list:comment">
315 foreach ($comments as $comment)
316 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
319 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
321 foreach ($extra_comments as $comment)
322 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
327 <div class="tablenav">
330 echo "<div class='tablenav-pages'>$page_links_text</div>";
333 <div class="alignleft actions">
334 <select name="action2">
335 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
336 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
337 <option value="unapprove"><?php _e('Unapprove'); ?></option>
339 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
340 <option value="approve"><?php _e('Approve'); ?></option>
342 <?php if ( 'spam' != $comment_status ): ?>
343 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
345 <option value="delete"><?php _e('Delete'); ?></option>
347 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
349 <?php if ( 'spam' == $comment_status ) { ?>
350 <input type="submit" name="delete_all_spam2" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
352 <?php do_action('manage_comments_nav', $comment_status); ?>
360 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
361 <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
362 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
363 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
364 <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
365 <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
366 <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
367 <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
368 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
371 <div id="ajax-response"></div>
373 <?php } elseif ( 'moderated' == $comment_status ) { ?>
374 <p><?php _e('No comments awaiting moderation… yet.') ?></p>
378 <p><?php _e('No results found.') ?></p>
385 wp_comment_reply('-1', true, 'detail');
386 include('admin-footer.php'); ?>