3 * Edit Comments Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 wp_enqueue_script('admin-comments');
13 enqueue_comment_hotkeys_js();
15 $post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
17 if ( ( isset( $_REQUEST['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spam2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
18 check_admin_referer('bulk-spam-delete', '_spam_nonce');
20 $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
21 if ( current_user_can('moderate_comments')) {
22 $deleted_spam = $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" );
26 $redirect_to = 'edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam;
28 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
29 wp_redirect( $redirect_to );
30 } elseif ( isset($_REQUEST['delete_comments']) && isset($_REQUEST['action']) && ( -1 != $_REQUEST['action'] || -1 != $_REQUEST['action2'] ) ) {
31 check_admin_referer('bulk-comments');
32 $doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
34 $deleted = $approved = $unapproved = $spammed = 0;
35 foreach ( (array) $_REQUEST['delete_comments'] as $comment_id) : // Check the permissions on each
36 $comment_id = (int) $comment_id;
37 $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
39 if ( !current_user_can('edit_post', $_post_id) )
44 wp_set_comment_status($comment_id, 'spam');
48 wp_set_comment_status($comment_id, 'delete');
52 wp_set_comment_status($comment_id, 'approve');
56 wp_set_comment_status($comment_id, 'hold');
62 $redirect_to = 'edit-comments.php?deleted=' . $deleted . '&approved=' . $approved . '&spam=' . $spammed . '&unapproved=' . $unapproved;
64 $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
65 if ( isset($_REQUEST['apage']) )
66 $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
67 if ( !empty($_REQUEST['mode']) )
68 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
69 if ( !empty($_REQUEST['comment_status']) )
70 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
71 if ( !empty($_REQUEST['s']) )
72 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
73 wp_redirect( $redirect_to );
74 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
75 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
80 $title = sprintf(__('Edit Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
82 $title = __('Edit Comments');
84 require_once('admin-header.php');
86 $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : attribute_escape($_GET['mode']);
88 $comment_status = !empty($_GET['comment_status']) ? attribute_escape($_GET['comment_status']) : '';
90 $comment_type = !empty($_GET['comment_type']) ? attribute_escape($_GET['comment_type']) : '';
92 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
93 $search = attribute_escape( $search_dirty ); ?>
96 <?php screen_icon(); ?>
97 <h2><?php echo wp_specialchars( $title );
98 if ( isset($_GET['s']) && $_GET['s'] )
99 printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( wp_specialchars( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
103 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
104 $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
105 $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
106 $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
108 if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
109 echo '<div id="moderated" class="updated fade"><p>';
111 if ( $approved > 0 ) {
112 printf( __ngettext( '%s comment approved', '%s comments approved', $approved ), $approved );
116 if ( $deleted > 0 ) {
117 printf( __ngettext( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
122 printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
131 <form id="comments-form" action="" method="get">
132 <ul class="subsubsub">
134 $status_links = array();
135 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
136 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
137 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
139 'all' => __ngettext_noop('All', 'All'), // singular not used
140 'moderated' => __ngettext_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
141 'approved' => __ngettext_noop('Approved', 'Approved'), // singular not used
142 'spam' => __ngettext_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
144 $class = ( '' === $comment_status ) ? ' class="current"' : '';
145 // $status_links[] = "<li><a href='edit-comments.php'$class>" . __( 'All' ) . '</a>';
146 $link = 'edit-comments.php';
147 if ( !empty($comment_type) && 'all' != $comment_type )
148 $link = add_query_arg( 'comment_type', $comment_type, $link );
149 foreach ( $stati as $status => $label ) {
152 if ( str_replace( 'all', '', $status ) == $comment_status )
153 $class = ' class="current"';
154 if ( !isset( $num_comments->$status ) )
155 $num_comments->$status = 10;
156 if ( 'all' != $status )
157 $link = add_query_arg( 'comment_status', $status, $link );
159 $link = add_query_arg( 'p', absint( $post_id ), $link );
161 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
162 if ( !empty( $_GET['s'] ) )
163 $link = add_query_arg( 's', attribute_escape( stripslashes( $_GET['s'] ) ), $link );
165 $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
166 __ngettext( $label[0], $label[1], $num_comments->$status ),
167 number_format_i18n( $num_comments->$status )
171 $status_links = apply_filters( 'comment_status_links', $status_links );
173 echo implode( " |</li>\n", $status_links) . '</li>';
174 unset($status_links);
178 <p class="search-box">
179 <label class="hidden" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
180 <input type="text" class="search-input" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
181 <input type="submit" value="<?php _e( 'Search Comments' ); ?>" class="button" />
185 $comments_per_page = apply_filters('comments_per_page', 20, $comment_status);
187 if ( isset( $_GET['apage'] ) )
188 $page = abs( (int) $_GET['apage'] );
192 $start = $offset = ( $page - 1 ) * $comments_per_page;
194 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 5, $post_id, $comment_type ); // Grab a few extra
196 $_comment_post_ids = array();
197 foreach ( $_comments as $_c ) {
198 $_comment_post_ids[] = $_c->comment_post_ID;
200 $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
201 foreach ( (array) $_comment_post_ids as $_cpid )
202 $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
203 if ( empty($_comment_pending_count) )
204 $_comment_pending_count = array();
206 $comments = array_slice($_comments, 0, $comments_per_page);
207 $extra_comments = array_slice($_comments, $comments_per_page);
209 $page_links = paginate_links( array(
210 'base' => add_query_arg( 'apage', '%#%' ),
212 'prev_text' => __('«'),
213 'next_text' => __('»'),
214 'total' => ceil($total / $comments_per_page),
220 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
221 <?php if ( $post_id ) : ?>
222 <input type="hidden" name="p" value="<?php echo intval( $post_id ); ?>" />
224 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
225 <input type="hidden" name="pagegen_timestamp" value="<?php echo current_time('mysql', 1); ?>" />
227 <div class="tablenav">
229 <?php if ( $page_links ) : ?>
230 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
231 number_format_i18n( $start + 1 ),
232 number_format_i18n( min( $page * $comments_per_page, $total ) ),
233 number_format_i18n( $total ),
235 ); echo $page_links_text; ?></div>
238 <div class="alignleft actions">
239 <select name="action">
240 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
241 <?php if ( empty($comment_status) || 'approved' == $comment_status ): ?>
242 <option value="unapprove"><?php _e('Unapprove'); ?></option>
244 <?php if ( empty($comment_status) || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
245 <option value="approve"><?php _e('Approve'); ?></option>
247 <?php if ( 'spam' != $comment_status ): ?>
248 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
250 <option value="delete"><?php _e('Delete'); ?></option>
252 <input type="submit" name="doaction" id="doaction" value="<?php _e('Apply'); ?>" class="button-secondary apply" />
253 <?php wp_nonce_field('bulk-comments'); ?>
255 <?php if ( $comment_status ) echo "<input type='hidden' name='comment_status' value='$comment_status' />\n"; ?>
256 <select name="comment_type">
257 <option value="all"><?php _e('Show all comment types'); ?></option>
259 $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
260 'comment' => __('Comments'),
261 'pings' => __('Pings'),
264 foreach ( $comment_types as $type => $label ) {
265 echo " <option value='$type'";
266 selected( $comment_type, $type );
267 echo ">$label</option>\n";
271 <input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
273 <?php if ( isset($_GET['apage']) ) { ?>
274 <input type="hidden" name="apage" value="<?php echo absint( $_GET['apage'] ); ?>" />
277 if ( 'spam' == $comment_status ) {
278 wp_nonce_field('bulk-spam-delete', '_spam_nonce');
279 if ( current_user_can ('moderate_comments')) { ?>
280 <input type="submit" name="delete_all_spam" value="<?php _e('Delete All Spam'); ?>" class="button-secondary apply" />
283 <?php do_action('manage_comments_nav', $comment_status); ?>
290 <div class="clear"></div>
292 <?php if ( $comments ) { ?>
293 <table class="widefat comments fixed" cellspacing="0">
296 <?php print_column_headers('edit-comments'); ?>
302 <?php print_column_headers('edit-comments', false); ?>
306 <tbody id="the-comment-list" class="list:comment">
308 foreach ($comments as $comment)
309 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
312 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
314 foreach ($extra_comments as $comment)
315 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
320 <div class="tablenav">
323 echo "<div class='tablenav-pages'>$page_links_text</div>";
326 <div class="alignleft actions">
327 <select name="action2">
328 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
329 <?php if ( empty($comment_status) || 'approved' == $comment_status ): ?>
330 <option value="unapprove"><?php _e('Unapprove'); ?></option>
332 <?php if ( empty($comment_status) || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
333 <option value="approve"><?php _e('Approve'); ?></option>
335 <?php if ( 'spam' != $comment_status ): ?>
336 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
338 <option value="delete"><?php _e('Delete'); ?></option>
340 <input type="submit" name="doaction2" id="doaction2" value="<?php _e('Apply'); ?>" class="button-secondary apply" />
342 <?php if ( 'spam' == $comment_status ) { ?>
343 <input type="submit" name="delete_all_spam2" value="<?php _e('Delete All Spam'); ?>" class="button-secondary apply" />
345 <?php do_action('manage_comments_nav', $comment_status); ?>
353 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
354 <input type="hidden" name="s" value="<?php echo $search; ?>" />
355 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
356 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
357 <input type="hidden" name="page" value="<?php echo isset($_REQUEST['page']) ? absint( $_REQUEST['page'] ) : 1; ?>" />
358 <input type="hidden" name="p" value="<?php echo attribute_escape( $post_id ); ?>" />
359 <input type="hidden" name="comment_type" value="<?php echo attribute_escape( $comment_type ); ?>" />
360 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
363 <div id="ajax-response"></div>
365 <?php } elseif ( 'moderated' == $_GET['comment_status'] ) { ?>
366 <p><?php _e('No comments awaiting moderation… yet.') ?></p>
370 <p><?php _e('No results found.') ?></p>
376 <script type="text/javascript">
379 $(document).ready(function(){
380 $('#doaction, #doaction2').click(function(){
381 if ( $('select[name^="action"]').val() == 'delete' ) {
382 var m = '<?php echo js_escape(__("You are about to delete the selected comments.\n 'Cancel' to stop, 'OK' to delete.")); ?>';
383 return showNotice.warn(m);
392 wp_comment_reply('-1', true, 'detail');
393 include('admin-footer.php'); ?>