2 require_once('admin.php');
4 $title = __('Edit Comments');
5 $parent_file = 'edit-comments.php';
6 wp_enqueue_script( 'admin-comments' );
7 wp_enqueue_script('admin-forms');
9 if ( !empty( $_REQUEST['delete_comments'] ) ) {
10 check_admin_referer('bulk-comments');
12 $comments_deleted = $comments_approved = $comments_unapproved = $comments_spammed = 0;
13 foreach ($_REQUEST['delete_comments'] as $comment) : // Check the permissions on each
14 $comment = (int) $comment;
15 $post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment) );
16 if ( !current_user_can('edit_post', $post_id) )
18 if ( !empty( $_REQUEST['spamit'] ) ) {
19 wp_set_comment_status($comment, 'spam');
21 } elseif ( !empty( $_REQUEST['deleteit'] ) ) {
22 wp_set_comment_status($comment, 'delete');
24 } elseif ( !empty( $_REQUEST['approveit'] ) ) {
25 wp_set_comment_status($comment, 'approve');
27 } elseif ( !empty( $_REQUEST['unapproveit'] ) ) {
28 wp_set_comment_status($comment, 'hold');
29 $comments_unapproved++;
32 $redirect_to = basename( __FILE__ ) . '?deleted=' . $comments_deleted . '&approved=' . $comments_approved . '&spam=' . $comments_spammed . '&unapproved=' . $comments_unapproved;
33 if ( isset($_REQUEST['apage']) )
34 $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
35 if ( !empty($_REQUEST['mode']) )
36 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
37 if ( !empty($_REQUEST['comment_status']) )
38 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
39 if ( !empty($_REQUEST['s']) )
40 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
41 wp_redirect( $redirect_to );
42 } elseif ( !empty($_GET['_wp_http_referer']) ) {
43 wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
47 require_once('admin-header.php');
49 if ( empty($_GET['mode']) )
52 $mode = attribute_escape($_GET['mode']);
54 if ( isset($_GET['comment_status']) )
55 $comment_status = attribute_escape($_GET['comment_status']);
59 if ( isset($_GET['s']) )
60 $search_dirty = $_GET['s'];
63 $search = attribute_escape( $search_dirty );
66 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
67 $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
68 $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
69 $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
71 if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
72 echo '<div id="moderated" class="updated fade"><p>';
74 if ( $approved > 0 ) {
75 printf( __ngettext( '%s comment approved', '%s comments approved', $approved ), $approved );
80 printf( __ngettext( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
85 printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
94 <form id="posts-filter" action="" method="get">
95 <h2><?php _e('Manage Comments'); ?></h2>
97 <ul class="subsubsub">
99 $status_links = array();
100 $num_comments = wp_count_comments();
101 $stati = array('moderated' => sprintf(__ngettext('Awaiting Moderation (%s)', 'Awaiting Moderation (%s)', number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), 'approved' => _c('Approved|plural'));
102 $class = ( '' === $comment_status ) ? ' class="current"' : '';
103 $status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>";
104 foreach ( $stati as $status => $label ) {
107 if ( $status == $comment_status )
108 $class = ' class="current"';
110 $status_links[] = "<li><a href=\"edit-comments.php?comment_status=$status\"$class>" . $label . '</a>';
113 $status_links = apply_filters( 'comment_status_links', $status_links );
115 echo implode(' | </li>', $status_links) . '</li>';
116 unset($status_links);
121 <label class="hidden" for="post-search-input"><?php _e( 'Search Comments' ); ?>:</label>
122 <input type="text" id="post-search-input" name="s" value="<?php echo $search; ?>" />
123 <input type="submit" value="<?php _e( 'Search Comments' ); ?>" class="button" />
126 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
127 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
130 <ul class="view-switch">
131 <li <?php if ( 'detail' == $mode ) echo "class='current'" ?>><a href="<?php echo clean_url(add_query_arg('mode', 'detail', $_SERVER['REQUEST_URI'])) ?>"><?php _e('Detail View') ?></a></li>
132 <li <?php if ( 'list' == $mode ) echo "class='current'" ?>><a href="<?php echo clean_url(add_query_arg('mode', 'list', $_SERVER['REQUEST_URI'])) ?>"><?php _e('List View') ?></a></li>
137 $comments_per_page = apply_filters('comments_per_page', 20, $comment_status);
139 if ( isset( $_GET['apage'] ) )
140 $page = abs( (int) $_GET['apage'] );
144 $start = $offset = ( $page - 1 ) * $comments_per_page;
146 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 5 ); // Grab a few extra
148 $comments = array_slice($_comments, 0, $comments_per_page);
149 $extra_comments = array_slice($_comments, $comments_per_page);
151 $page_links = paginate_links( array(
152 'base' => add_query_arg( 'apage', '%#%' ),
154 'total' => ceil($total / $comments_per_page),
160 <form id="comments-form" action="" method="post">
162 <div class="tablenav">
166 echo "<div class='tablenav-pages'>$page_links</div>";
169 <div class="alignleft">
170 <?php if ( 'approved' != $comment_status ): ?>
171 <input type="submit" value="<?php _e('Approve'); ?>" name="approveit" class="button-secondary" />
173 <input type="submit" value="<?php _e('Mark as Spam'); ?>" name="spamit" class="button-secondary" />
174 <?php if ( 'moderated' != $comment_status ): ?>
175 <input type="submit" value="<?php _e('Unapprove'); ?>" name="unapproveit" class="button-secondary" />
177 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
178 <?php do_action('manage_comments_nav', $comment_status); ?>
179 <?php wp_nonce_field('bulk-comments'); ?>
180 <?php if ( isset($_GET['apage']) ) { ?>
181 <input type="hidden" name="apage" value="<?php echo absint( $_GET['apage'] ); ?>" />
193 <table class="widefat">
196 <th scope="col" class="check-column"><input type="checkbox" /></th>
197 <th scope="col"><?php _e('Comment') ?></th>
198 <th scope="col"><?php _e('Date') ?></th>
199 <th scope="col" class="action-links"><?php _e('Actions') ?></th>
202 <tbody id="the-comment-list" class="list:comment">
204 foreach ($comments as $comment)
205 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
208 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
210 foreach ($extra_comments as $comment)
211 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
218 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
219 <input type="hidden" name="s" value="<?php echo $search; ?>" />
220 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
221 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
222 <input type="hidden" name="page" value="<?php echo isset($_REQUEST['page']) ? absint( $_REQUEST['page'] ) : 1; ?>" />
223 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
226 <div id="ajax-response"></div>
228 } elseif ( 'moderated' == $_GET['comment_status'] ) {
231 <?php _e('No comments awaiting moderation… yet.') ?>
237 <?php _e('No results found.') ?>
242 <div class="tablenav">
245 echo "<div class='tablenav-pages'>$page_links</div>";
252 <?php include('admin-footer.php'); ?>