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("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
16 // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
17 if ( !current_user_can('edit_post', $post_id) )
19 if ( !empty( $_REQUEST['spamit'] ) ) {
20 wp_set_comment_status($comment, 'spam');
22 } elseif ( !empty( $_REQUEST['deleteit'] ) ) {
23 wp_set_comment_status($comment, 'delete');
25 } elseif ( !empty( $_REQUEST['approveit'] ) ) {
26 wp_set_comment_status($comment, 'approve');
28 } elseif ( !empty( $_REQUEST['unapproveit'] ) ) {
29 wp_set_comment_status($comment, 'hold');
30 $comments_unapproved++;
33 $redirect_to = basename( __FILE__ ) . '?deleted=' . $comments_deleted . '&approved=' . $comments_approved . '&spam=' . $comments_spammed . '&unapproved=' . $comments_unapproved;
34 if ( !empty($_REQUEST['mode']) )
35 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
36 if ( !empty($_REQUEST['comment_status']) )
37 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
38 if ( !empty($_REQUEST['s']) )
39 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
40 wp_redirect( $redirect_to );
41 } elseif ( !empty($_GET['_wp_http_referer']) ) {
42 wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
46 require_once('admin-header.php');
48 if ( empty($_GET['mode']) )
51 $mode = attribute_escape($_GET['mode']);
53 if ( isset($_GET['comment_status']) )
54 $comment_status = attribute_escape($_GET['comment_status']);
58 if ( isset($_GET['s']) )
59 $search_dirty = $_GET['s'];
62 $search = attribute_escape( $search_dirty );
65 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
66 $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
67 $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
68 $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
70 if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
71 echo '<div id="moderated" class="updated fade"><p>';
73 if ( $approved > 0 ) {
74 printf( __ngettext( '%s comment approved', '%s comments approved', $approved ), $approved );
79 printf( __ngettext( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
84 printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
93 <form id="posts-filter" action="" method="get">
94 <h2><?php _e('Manage Comments'); ?></h2>
96 <ul class="subsubsub">
98 $status_links = array();
99 $num_comments = wp_count_comments();
100 $stati = array('moderated' => sprintf(__ngettext('Awaiting Moderation (%s)', 'Awaiting Moderation (%s)', $num_comments->moderated), "<span class='comment-count'>$num_comments->moderated</span>"), 'approved' => _c('Approved|plural'));
101 $class = ( '' === $comment_status ) ? ' class="current"' : '';
102 $status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>";
103 foreach ( $stati as $status => $label ) {
106 if ( $status == $comment_status )
107 $class = ' class="current"';
109 $status_links[] = "<li><a href=\"edit-comments.php?comment_status=$status\"$class>" . $label . '</a>';
112 $status_links = apply_filters( 'comment_status_links', $status_links );
114 echo implode(' | </li>', $status_links) . '</li>';
115 unset($status_links);
120 <input type="text" id="post-search-input" name="s" value="<?php echo $search; ?>" />
121 <input type="submit" value="<?php _e( 'Search Comments' ); ?>" class="button" />
124 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
125 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
128 <ul class="view-switch">
129 <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>
130 <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>
135 if ( isset( $_GET['apage'] ) )
136 $page = abs( (int) $_GET['apage'] );
140 $start = $offset = ( $page - 1 ) * 20;
142 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, 25 ); // Grab a few extra
144 $comments = array_slice($_comments, 0, 20);
145 $extra_comments = array_slice($_comments, 20);
147 $page_links = paginate_links( array(
148 'base' => add_query_arg( 'apage', '%#%' ),
150 'total' => ceil($total / 20),
156 <form id="comments-form" action="" method="post">
158 <div class="tablenav">
162 echo "<div class='tablenav-pages'>$page_links</div>";
165 <div class="alignleft">
166 <?php if ( 'approved' != $comment_status ): ?>
167 <input type="submit" value="<?php _e('Approve'); ?>" name="approveit" class="button-secondary" />
169 <input type="submit" value="<?php _e('Mark as Spam'); ?>" name="spamit" class="button-secondary" />
170 <?php if ( 'moderated' != $comment_status ): ?>
171 <input type="submit" value="<?php _e('Unapprove'); ?>" name="unapproveit" class="button-secondary" />
173 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
174 <?php do_action('manage_comments_nav', $comment_status); ?>
175 <?php wp_nonce_field('bulk-comments'); ?>
186 <table class="widefat">
189 <th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('comments-form'));" /></th>
190 <th scope="col"><?php _e('Comment') ?></th>
191 <th scope="col"><?php _e('Date') ?></th>
192 <th scope="col" class="action-links"><?php _e('Actions') ?></th>
195 <tbody id="the-comment-list" class="list:comment">
197 foreach ($comments as $comment)
198 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
201 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
203 foreach ($extra_comments as $comment)
204 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
211 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
212 <input type="hidden" name="s" value="<?php echo $search; ?>" />
213 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
214 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
215 <input type="hidden" name="page" value="<?php echo isset($_REQUEST['page']) ? absint( $_REQUEST['page'] ) : 1; ?>" />
216 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
219 <div id="ajax-response"></div>
221 } elseif ( 'moderated' == $_GET['comment_status'] ) {
224 <?php _e('No comments awaiting moderation… yet.') ?>
230 <?php _e('No results found.') ?>
235 <div class="tablenav">
238 echo "<div class='tablenav-pages'>$page_links</div>";
245 <?php include('admin-footer.php'); ?>