1 | <?php
|
---|
2 | /**
|
---|
3 | * Edit Comments Administration Panel.
|
---|
4 | *
|
---|
5 | * @package WordPress
|
---|
6 | * @subpackage Administration
|
---|
7 | */
|
---|
8 |
|
---|
9 | /** WordPress Administration Bootstrap */
|
---|
10 | require_once('admin.php');
|
---|
11 |
|
---|
12 | wp_enqueue_script('admin-comments');
|
---|
13 | enqueue_comment_hotkeys_js();
|
---|
14 |
|
---|
15 | $post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
|
---|
16 |
|
---|
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');
|
---|
19 |
|
---|
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" );
|
---|
23 | } else {
|
---|
24 | $deleted_spam = 0;
|
---|
25 | }
|
---|
26 | $redirect_to = 'edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam;
|
---|
27 | if ( $post_id )
|
---|
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'];
|
---|
33 |
|
---|
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) );
|
---|
38 |
|
---|
39 | if ( !current_user_can('edit_post', $_post_id) )
|
---|
40 | continue;
|
---|
41 |
|
---|
42 | switch( $doaction ) {
|
---|
43 | case 'markspam' :
|
---|
44 | wp_set_comment_status($comment_id, 'spam');
|
---|
45 | $spammed++;
|
---|
46 | break;
|
---|
47 | case 'delete' :
|
---|
48 | wp_set_comment_status($comment_id, 'delete');
|
---|
49 | $deleted++;
|
---|
50 | break;
|
---|
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 | }
|
---|
60 | endforeach;
|
---|
61 |
|
---|
62 | $redirect_to = 'edit-comments.php?deleted=' . $deleted . '&approved=' . $approved . '&spam=' . $spammed . '&unapproved=' . $unapproved;
|
---|
63 | if ( $post_id )
|
---|
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']) ) );
|
---|
76 | exit;
|
---|
77 | }
|
---|
78 |
|
---|
79 | if ( $post_id )
|
---|
80 | $title = sprintf(__('Edit Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
|
---|
81 | else
|
---|
82 | $title = __('Edit Comments');
|
---|
83 |
|
---|
84 | require_once('admin-header.php');
|
---|
85 |
|
---|
86 | $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
|
---|
87 |
|
---|
88 | $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
|
---|
89 | if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) )
|
---|
90 | $comment_status = 'all';
|
---|
91 |
|
---|
92 | $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
|
---|
93 |
|
---|
94 | $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
|
---|
95 | $search = esc_attr( $search_dirty ); ?>
|
---|
96 |
|
---|
97 | <div class="wrap">
|
---|
98 | <?php screen_icon(); ?>
|
---|
99 | <h2><?php echo esc_html( $title );
|
---|
100 | if ( isset($_GET['s']) && $_GET['s'] )
|
---|
101 | printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
|
---|
102 | </h2>
|
---|
103 |
|
---|
104 | <?php
|
---|
105 | if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
|
---|
106 | $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
|
---|
107 | $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
|
---|
108 | $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
|
---|
109 |
|
---|
110 | if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
|
---|
111 | echo '<div id="moderated" class="updated fade"><p>';
|
---|
112 |
|
---|
113 | if ( $approved > 0 ) {
|
---|
114 | printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
|
---|
115 | echo '<br />';
|
---|
116 | }
|
---|
117 |
|
---|
118 | if ( $deleted > 0 ) {
|
---|
119 | printf( _n( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
|
---|
120 | echo '<br />';
|
---|
121 | }
|
---|
122 |
|
---|
123 | if ( $spam > 0 ) {
|
---|
124 | printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
|
---|
125 | echo '<br />';
|
---|
126 | }
|
---|
127 |
|
---|
128 | echo '</p></div>';
|
---|
129 | }
|
---|
130 | }
|
---|
131 | ?>
|
---|
132 |
|
---|
133 | <form id="comments-form" action="" method="get">
|
---|
134 | <ul class="subsubsub">
|
---|
135 | <?php
|
---|
136 | $status_links = array();
|
---|
137 | $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
|
---|
138 | //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
|
---|
139 | //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
|
---|
140 | $stati = array(
|
---|
141 | 'all' => _n_noop('All', 'All'), // singular not used
|
---|
142 | 'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
|
---|
143 | 'approved' => _n_noop('Approved', 'Approved'), // singular not used
|
---|
144 | 'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
|
---|
145 | );
|
---|
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 ) {
|
---|
150 | $class = '';
|
---|
151 |
|
---|
152 | if ( $status == $comment_status )
|
---|
153 | $class = ' class="current"';
|
---|
154 | if ( !isset( $num_comments->$status ) )
|
---|
155 | $num_comments->$status = 10;
|
---|
156 | $link = add_query_arg( 'comment_status', $status, $link );
|
---|
157 | if ( $post_id )
|
---|
158 | $link = add_query_arg( 'p', absint( $post_id ), $link );
|
---|
159 | /*
|
---|
160 | // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
|
---|
161 | if ( !empty( $_GET['s'] ) )
|
---|
162 | $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
|
---|
163 | */
|
---|
164 | $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
|
---|
165 | _n( $label[0], $label[1], $num_comments->$status ),
|
---|
166 | number_format_i18n( $num_comments->$status )
|
---|
167 | ) . '</a>';
|
---|
168 | }
|
---|
169 |
|
---|
170 | $status_links = apply_filters( 'comment_status_links', $status_links );
|
---|
171 |
|
---|
172 | echo implode( " |</li>\n", $status_links) . '</li>';
|
---|
173 | unset($status_links);
|
---|
174 | ?>
|
---|
175 | </ul>
|
---|
176 |
|
---|
177 | <p class="search-box">
|
---|
178 | <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
|
---|
179 | <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
|
---|
180 | <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" />
|
---|
181 | </p>
|
---|
182 |
|
---|
183 | <?php
|
---|
184 | $comments_per_page = get_user_option('edit_comments_per_page');
|
---|
185 | if ( empty($comments_per_page) )
|
---|
186 | $comments_per_page = 20;
|
---|
187 | $comments_per_page = apply_filters('comments_per_page', $comments_per_page, $comment_status);
|
---|
188 |
|
---|
189 | if ( isset( $_GET['apage'] ) )
|
---|
190 | $page = abs( (int) $_GET['apage'] );
|
---|
191 | else
|
---|
192 | $page = 1;
|
---|
193 |
|
---|
194 | $start = $offset = ( $page - 1 ) * $comments_per_page;
|
---|
195 |
|
---|
196 | list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
|
---|
197 |
|
---|
198 | $_comment_post_ids = array();
|
---|
199 | foreach ( $_comments as $_c ) {
|
---|
200 | $_comment_post_ids[] = $_c->comment_post_ID;
|
---|
201 | }
|
---|
202 | $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
|
---|
203 | foreach ( (array) $_comment_post_ids as $_cpid )
|
---|
204 | $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
|
---|
205 | if ( empty($_comment_pending_count) )
|
---|
206 | $_comment_pending_count = array();
|
---|
207 |
|
---|
208 | $comments = array_slice($_comments, 0, $comments_per_page);
|
---|
209 | $extra_comments = array_slice($_comments, $comments_per_page);
|
---|
210 |
|
---|
211 | $page_links = paginate_links( array(
|
---|
212 | 'base' => add_query_arg( 'apage', '%#%' ),
|
---|
213 | 'format' => '',
|
---|
214 | 'prev_text' => __('«'),
|
---|
215 | 'next_text' => __('»'),
|
---|
216 | 'total' => ceil($total / $comments_per_page),
|
---|
217 | 'current' => $page
|
---|
218 | ));
|
---|
219 |
|
---|
220 | ?>
|
---|
221 |
|
---|
222 | <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
|
---|
223 | <?php if ( $post_id ) : ?>
|
---|
224 | <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
|
---|
225 | <?php endif; ?>
|
---|
226 | <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
|
---|
227 | <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
|
---|
228 |
|
---|
229 | <div class="tablenav">
|
---|
230 |
|
---|
231 | <?php if ( $page_links ) : ?>
|
---|
232 | <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
|
---|
233 | number_format_i18n( $start + 1 ),
|
---|
234 | number_format_i18n( min( $page * $comments_per_page, $total ) ),
|
---|
235 | '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
|
---|
236 | $page_links
|
---|
237 | ); echo $page_links_text; ?></div>
|
---|
238 | <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
|
---|
239 | <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
|
---|
240 | <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
|
---|
241 | <?php endif; ?>
|
---|
242 |
|
---|
243 | <div class="alignleft actions">
|
---|
244 | <select name="action">
|
---|
245 | <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
|
---|
246 | <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
|
---|
247 | <option value="unapprove"><?php _e('Unapprove'); ?></option>
|
---|
248 | <?php endif; ?>
|
---|
249 | <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
|
---|
250 | <option value="approve"><?php _e('Approve'); ?></option>
|
---|
251 | <?php endif; ?>
|
---|
252 | <?php if ( 'spam' != $comment_status ): ?>
|
---|
253 | <option value="markspam"><?php _e('Mark as Spam'); ?></option>
|
---|
254 | <?php endif; ?>
|
---|
255 | <option value="delete"><?php _e('Delete'); ?></option>
|
---|
256 | </select>
|
---|
257 | <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
|
---|
258 | <?php wp_nonce_field('bulk-comments'); ?>
|
---|
259 |
|
---|
260 | <select name="comment_type">
|
---|
261 | <option value="all"><?php _e('Show all comment types'); ?></option>
|
---|
262 | <?php
|
---|
263 | $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
|
---|
264 | 'comment' => __('Comments'),
|
---|
265 | 'pings' => __('Pings'),
|
---|
266 | ) );
|
---|
267 |
|
---|
268 | foreach ( $comment_types as $type => $label ) {
|
---|
269 | echo " <option value='" . esc_attr($type) . "'";
|
---|
270 | selected( $comment_type, $type );
|
---|
271 | echo ">$label</option>\n";
|
---|
272 | }
|
---|
273 | ?>
|
---|
274 | </select>
|
---|
275 | <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
|
---|
276 |
|
---|
277 | <?php if ( isset($_GET['apage']) ) { ?>
|
---|
278 | <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
|
---|
279 | <?php }
|
---|
280 |
|
---|
281 | if ( 'spam' == $comment_status ) {
|
---|
282 | wp_nonce_field('bulk-spam-delete', '_spam_nonce');
|
---|
283 | if ( current_user_can ('moderate_comments')) { ?>
|
---|
284 | <input type="submit" name="delete_all_spam" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
|
---|
285 | <?php }
|
---|
286 | } ?>
|
---|
287 | <?php do_action('manage_comments_nav', $comment_status); ?>
|
---|
288 | </div>
|
---|
289 |
|
---|
290 | <br class="clear" />
|
---|
291 |
|
---|
292 | </div>
|
---|
293 |
|
---|
294 | <div class="clear"></div>
|
---|
295 |
|
---|
296 | <?php if ( $comments ) { ?>
|
---|
297 | <table class="widefat comments fixed" cellspacing="0">
|
---|
298 | <thead>
|
---|
299 | <tr>
|
---|
300 | <?php print_column_headers('edit-comments'); ?>
|
---|
301 | </tr>
|
---|
302 | </thead>
|
---|
303 |
|
---|
304 | <tfoot>
|
---|
305 | <tr>
|
---|
306 | <?php print_column_headers('edit-comments', false); ?>
|
---|
307 | </tr>
|
---|
308 | </tfoot>
|
---|
309 |
|
---|
310 | <tbody id="the-comment-list" class="list:comment">
|
---|
311 | <?php
|
---|
312 | foreach ($comments as $comment)
|
---|
313 | _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
|
---|
314 | ?>
|
---|
315 | </tbody>
|
---|
316 | <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
|
---|
317 | <?php
|
---|
318 | foreach ($extra_comments as $comment)
|
---|
319 | _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
|
---|
320 | ?>
|
---|
321 | </tbody>
|
---|
322 | </table>
|
---|
323 |
|
---|
324 | <div class="tablenav">
|
---|
325 | <?php
|
---|
326 | if ( $page_links )
|
---|
327 | echo "<div class='tablenav-pages'>$page_links_text</div>";
|
---|
328 | ?>
|
---|
329 |
|
---|
330 | <div class="alignleft actions">
|
---|
331 | <select name="action2">
|
---|
332 | <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
|
---|
333 | <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
|
---|
334 | <option value="unapprove"><?php _e('Unapprove'); ?></option>
|
---|
335 | <?php endif; ?>
|
---|
336 | <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
|
---|
337 | <option value="approve"><?php _e('Approve'); ?></option>
|
---|
338 | <?php endif; ?>
|
---|
339 | <?php if ( 'spam' != $comment_status ): ?>
|
---|
340 | <option value="markspam"><?php _e('Mark as Spam'); ?></option>
|
---|
341 | <?php endif; ?>
|
---|
342 | <option value="delete"><?php _e('Delete'); ?></option>
|
---|
343 | </select>
|
---|
344 | <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
|
---|
345 |
|
---|
346 | <?php if ( 'spam' == $comment_status ) { ?>
|
---|
347 | <input type="submit" name="delete_all_spam2" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
|
---|
348 | <?php } ?>
|
---|
349 | <?php do_action('manage_comments_nav', $comment_status); ?>
|
---|
350 | </div>
|
---|
351 |
|
---|
352 | <br class="clear" />
|
---|
353 | </div>
|
---|
354 |
|
---|
355 | </form>
|
---|
356 |
|
---|
357 | <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
|
---|
358 | <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
|
---|
359 | <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
|
---|
360 | <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
|
---|
361 | <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
|
---|
362 | <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
|
---|
363 | <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
|
---|
364 | <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
|
---|
365 | <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
|
---|
366 | </form>
|
---|
367 |
|
---|
368 | <div id="ajax-response"></div>
|
---|
369 |
|
---|
370 | <?php } elseif ( 'moderated' == $comment_status ) { ?>
|
---|
371 | <p><?php _e('No comments awaiting moderation… yet.') ?></p>
|
---|
372 | </form>
|
---|
373 |
|
---|
374 | <?php } else { ?>
|
---|
375 | <p><?php _e('No results found.') ?></p>
|
---|
376 | </form>
|
---|
377 |
|
---|
378 | <?php } ?>
|
---|
379 | </div>
|
---|
380 |
|
---|
381 | <?php
|
---|
382 | wp_comment_reply('-1', true, 'detail');
|
---|
383 | include('admin-footer.php'); ?>
|
---|