2 require_once('admin.php');
4 $title = __('Edit Comments');
5 $parent_file = 'edit-comments.php';
6 wp_enqueue_script( 'admin-comments' );
8 require_once('admin-header.php');
9 if (empty($_GET['mode'])) $mode = 'view';
10 else $mode = attribute_escape($_GET['mode']);
13 <script type="text/javascript">
15 function checkAll(form)
17 for (i = 0, n = form.elements.length; i < n; i++) {
18 if(form.elements[i].type == "checkbox") {
19 if(form.elements[i].checked == true)
20 form.elements[i].checked = false;
22 form.elements[i].checked = true;
27 function getNumChecked(form)
30 for (i = 0, n = form.elements.length; i < n; i++) {
31 if(form.elements[i].type == "checkbox") {
32 if(form.elements[i].checked == true)
41 <h2><?php _e('Comments'); ?></h2>
42 <form name="searchform" action="" method="get" id="editcomments">
44 <legend><?php _e('Show Comments That Contain...') ?></legend>
45 <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" />
46 <input type="submit" name="submit" value="<?php _e('Search') ?>" />
47 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
48 <?php _e('(Searches within comment text, e-mail, URL, and IP address.)') ?>
51 <p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p>
53 if ( !empty( $_POST['delete_comments'] ) ) :
54 check_admin_referer('bulk-comments');
57 foreach ($_POST['delete_comments'] as $comment) : // Check the permissions on each
58 $comment = (int) $comment;
59 $post_id = (int) $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
60 // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
61 if ( current_user_can('edit_post', $post_id) ) {
62 if ( !empty( $_POST['spam_button'] ) )
63 wp_set_comment_status($comment, 'spam');
65 wp_set_comment_status($comment, 'delete');
69 echo '<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p>';
70 if ( !empty( $_POST['spam_button'] ) ) {
71 printf(__ngettext('%s comment marked as spam', '%s comments marked as spam.', $i), $i);
73 printf(__ngettext('%s comment deleted.', '%s comments deleted.', $i), $i);
78 if ( isset( $_GET['apage'] ) )
79 $page = abs( (int) $_GET['apage'] );
83 $start = $offset = ( $page - 1 ) * 20;
85 list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra
87 $comments = array_slice($_comments, 0, 20);
88 $extra_comments = array_slice($_comments, 20);
90 $page_links = paginate_links( array(
91 'base' => add_query_arg( 'apage', '%#%' ),
93 'total' => ceil($total / 20),
98 echo "<p class='pagenav'>$page_links</p>";
100 if ('view' == $mode) {
102 $offset = $offset + 1;
103 $start = " start='$offset'";
105 echo "<ol id='the-comment-list' class='commentlist' $start>\n";
107 foreach ( $comments as $comment ) {
108 get_comment( $comment ); // Cache it
109 _wp_comment_list_item( $comment->comment_ID, ++$i );
113 if ( $extra_comments ) : ?>
114 <div id="extra-comments" style="display:none">
115 <ul id="the-extra-comment-list" class="commentlist">
117 foreach ( $extra_comments as $comment ) {
118 get_comment( $comment ); // Cache it
119 _wp_comment_list_item( $comment->comment_ID, ++$i );
124 <?php endif; // $extra_comments ?>
126 <div id="ajax-response"></div>
129 } else { //no comments to show
133 <strong><?php _e('No comments found.') ?></strong></p>
136 } // end if ($comments)
137 } elseif ('edit' == $mode) {
140 echo '<form name="deletecomments" id="deletecomments" action="" method="post"> ';
141 wp_nonce_field('bulk-comments');
142 echo '<table class="widefat">
145 <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th>
146 <th scope="col">' . __('Name') . '</th>
147 <th scope="col">' . __('E-mail') . '</th>
148 <th scope="col">' . __('IP') . '</th>
149 <th scope="col">' . __('Comment Excerpt') . '</th>
150 <th scope="col" colspan="3" style="text-align: center">' . __('Actions') . '</th>
153 foreach ($comments as $comment) {
154 $post = get_post($comment->comment_post_ID);
155 $authordata = get_userdata($post->post_author);
156 $comment_status = wp_get_comment_status($comment->comment_ID);
157 $class = ('alternate' == $class) ? '' : 'alternate';
158 $class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
160 <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
161 <td style="text-align: center"><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td>
162 <td><?php comment_author_link() ?></td>
163 <td><?php comment_author_email_link() ?></td>
164 <td><a href="edit-comments.php?s=<?php comment_author_IP() ?>&mode=edit"><?php comment_author_IP() ?></a></td>
165 <td><?php comment_excerpt(); ?></td>
167 <?php if ('unapproved' == $comment_status) {
170 <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
173 <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
174 echo "<a href='comment.php?action=editcomment&c=$comment->comment_ID' class='edit'>" . __('Edit') . "</a>"; } ?></td>
175 <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
176 echo "<a href=\"comment.php?action=deletecomment&p=".$comment->comment_post_ID."&c=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to delete this comment by '%s'. \n 'Cancel' to stop, 'OK' to delete."), $comment->comment_author )) . "', theCommentList );\" class='delete'>" . __('Delete') . "</a> ";
182 <p class="submit"><input type="submit" name="delete_button" class="delete" value="<?php _e('Delete Checked Comments »') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php echo js_escape(__("Please select some comments to delete")); ?>'); return false } return confirm('<?php echo sprintf(js_escape(__("You are about to delete %s comments permanently \n 'Cancel' to stop, 'OK' to delete.")), "' + numchecked + '"); ?>')" />
183 <input type="submit" name="spam_button" value="<?php _e('Mark Checked Comments as Spam »') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php echo js_escape(__("Please select some comments to mark as spam")); ?>'); return false } return confirm('<?php echo sprintf(js_escape(__("You are about to mark %s comments as spam \n 'Cancel' to stop, 'OK' to mark as spam.")), "' + numchecked + '"); ?>')" /></p>
185 <div id="ajax-response"></div>
190 <strong><?php _e('No results found.') ?></strong>
193 } // end if ($comments)
197 echo "<p class='pagenav'>$page_links</p>";
203 <?php include('admin-footer.php'); ?>