]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-comments.php
WordPress 4.6.1
[autoinstalls/wordpress.git] / wp-admin / edit-comments.php
1 <?php
2 /**
3  * Edit Comments Administration Screen.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11 if ( ! current_user_can( 'edit_posts' ) ) {
12         wp_die(
13                 '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
14                 '<p>' . __( 'Sorry, you are not allowed to edit comments.' ) . '</p>',
15                 403
16         );
17 }
18
19 $wp_list_table = _get_list_table('WP_Comments_List_Table');
20 $pagenum = $wp_list_table->get_pagenum();
21
22 $doaction = $wp_list_table->current_action();
23
24 if ( $doaction ) {
25         check_admin_referer( 'bulk-comments' );
26
27         if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
28                 $comment_status = wp_unslash( $_REQUEST['comment_status'] );
29                 $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
30                 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) );
31                 $doaction = 'delete';
32         } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
33                 $comment_ids = $_REQUEST['delete_comments'];
34                 $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
35         } elseif ( isset( $_REQUEST['ids'] ) ) {
36                 $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
37         } elseif ( wp_get_referer() ) {
38                 wp_safe_redirect( wp_get_referer() );
39                 exit;
40         }
41
42         $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
43
44         $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
45         $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
46
47         wp_defer_comment_counting( true );
48
49         foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
50                 if ( !current_user_can( 'edit_comment', $comment_id ) )
51                         continue;
52
53                 switch ( $doaction ) {
54                         case 'approve' :
55                                 wp_set_comment_status( $comment_id, 'approve' );
56                                 $approved++;
57                                 break;
58                         case 'unapprove' :
59                                 wp_set_comment_status( $comment_id, 'hold' );
60                                 $unapproved++;
61                                 break;
62                         case 'spam' :
63                                 wp_spam_comment( $comment_id );
64                                 $spammed++;
65                                 break;
66                         case 'unspam' :
67                                 wp_unspam_comment( $comment_id );
68                                 $unspammed++;
69                                 break;
70                         case 'trash' :
71                                 wp_trash_comment( $comment_id );
72                                 $trashed++;
73                                 break;
74                         case 'untrash' :
75                                 wp_untrash_comment( $comment_id );
76                                 $untrashed++;
77                                 break;
78                         case 'delete' :
79                                 wp_delete_comment( $comment_id );
80                                 $deleted++;
81                                 break;
82                 }
83         }
84
85         wp_defer_comment_counting( false );
86
87         if ( $approved )
88                 $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
89         if ( $unapproved )
90                 $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
91         if ( $spammed )
92                 $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
93         if ( $unspammed )
94                 $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
95         if ( $trashed )
96                 $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
97         if ( $untrashed )
98                 $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
99         if ( $deleted )
100                 $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
101         if ( $trashed || $spammed )
102                 $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
103
104         wp_safe_redirect( $redirect_to );
105         exit;
106 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
107          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
108          exit;
109 }
110
111 $wp_list_table->prepare_items();
112
113 wp_enqueue_script('admin-comments');
114 enqueue_comment_hotkeys_js();
115
116 if ( $post_id ) {
117         $comments_count = wp_count_comments( $post_id );
118         $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' );
119         if ( $comments_count->moderated > 0 ) {
120                 /* translators: 1: comments count 2: post title */
121                 $title = sprintf( __( 'Comments (%1$s) on &#8220;%2$s&#8221;' ),
122                         number_format_i18n( $comments_count->moderated ),
123                         $draft_or_post_title
124                 );
125         } else {
126                 /* translators: %s: post title */
127                 $title = sprintf( __( 'Comments on &#8220;%s&#8221;' ),
128                         $draft_or_post_title
129                 );
130         }
131 } else {
132         $comments_count = wp_count_comments();
133         if ( $comments_count->moderated > 0 ) {
134                 /* translators: %s: comments count */
135                 $title = sprintf( __( 'Comments (%s)' ),
136                         number_format_i18n( $comments_count->moderated )
137                 );
138         } else {
139                 $title = __( 'Comments' );
140         }
141 }
142
143 add_screen_option( 'per_page' );
144
145 get_current_screen()->add_help_tab( array(
146 'id'            => 'overview',
147 'title'         => __('Overview'),
148 'content'       =>
149         '<p>' . __( 'You can manage comments made on your site similar to the way you manage posts and other content. This screen is customizable in the same ways as other management screens, and you can act on comments using the on-hover action links or the Bulk Actions.' ) . '</p>'
150 ) );
151 get_current_screen()->add_help_tab( array(
152 'id'            => 'moderating-comments',
153 'title'         => __('Moderating Comments'),
154 'content'       =>
155                 '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
156                 '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and blog URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
157                 '<p>' . __( 'In the <strong>Comment</strong> column, hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
158                 '<p>' . __( 'In the <strong>In Response To</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows the number of approved comments that post has received. If there are pending comments, a red notification circle with the number of pending comments is displayed. Clicking the notification circle will filter the comments screen to show only pending comments on that post.' ) . '</p>' .
159                 '<p>' . __( 'In the <strong>Submitted On</strong> column, the date and time the comment was left on your site appears. Clicking on the date/time link will take you to that comment on your live site.' ) . '</p>' .
160                 '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>'
161 ) );
162
163 get_current_screen()->set_help_sidebar(
164         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
165         '<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
166         '<p>' . __( '<a href="https://codex.wordpress.org/Comment_Spam" target="_blank">Documentation on Comment Spam</a>' ) . '</p>' .
167         '<p>' . __( '<a href="https://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
168         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
169 );
170
171 get_current_screen()->set_screen_reader_content( array(
172         'heading_views'      => __( 'Filter comments list' ),
173         'heading_pagination' => __( 'Comments list navigation' ),
174         'heading_list'       => __( 'Comments list' ),
175 ) );
176
177 require_once( ABSPATH . 'wp-admin/admin-header.php' );
178 ?>
179
180 <div class="wrap">
181 <h1><?php
182 if ( $post_id ) {
183         /* translators: %s: link to post */
184         printf( __( 'Comments on &#8220;%s&#8221;' ),
185                 sprintf( '<a href="%1$s">%2$s</a>',
186                         get_edit_post_link( $post_id ),
187                         wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' )
188                 )
189         );
190 } else {
191         _e( 'Comments' );
192 }
193
194 if ( isset($_REQUEST['s']) && strlen( $_REQUEST['s'] ) ) {
195         echo '<span class="subtitle">';
196         /* translators: %s: search keywords */
197         printf( __( 'Search results for &#8220;%s&#8221;' ),
198                 wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '&hellip;' )
199         );
200         echo '</span>';
201 }
202 ?></h1>
203
204 <?php
205 if ( isset( $_REQUEST['error'] ) ) {
206         $error = (int) $_REQUEST['error'];
207         $error_msg = '';
208         switch ( $error ) {
209                 case 1 :
210                         $error_msg = __( 'Invalid comment ID.' );
211                         break;
212                 case 2 :
213                         $error_msg = __( 'Sorry, you are not allowed to edit comments on this post.' );
214                         break;
215         }
216         if ( $error_msg )
217                 echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
218 }
219
220 if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQUEST['trashed']) || isset($_REQUEST['untrashed']) || isset($_REQUEST['spammed']) || isset($_REQUEST['unspammed']) || isset($_REQUEST['same']) ) {
221         $approved  = isset( $_REQUEST['approved']  ) ? (int) $_REQUEST['approved']  : 0;
222         $deleted   = isset( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
223         $trashed   = isset( $_REQUEST['trashed']   ) ? (int) $_REQUEST['trashed']   : 0;
224         $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
225         $spammed   = isset( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']   : 0;
226         $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
227         $same      = isset( $_REQUEST['same'] )      ? (int) $_REQUEST['same']      : 0;
228
229         if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
230                 if ( $approved > 0 ) {
231                         /* translators: %s: number of comments approved */
232                         $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
233                 }
234
235                 if ( $spammed > 0 ) {
236                         $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
237                         /* translators: %s: number of comments marked as spam */
238                         $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
239                 }
240
241                 if ( $unspammed > 0 ) {
242                         /* translators: %s: number of comments restored from the spam */
243                         $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
244                 }
245
246                 if ( $trashed > 0 ) {
247                         $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
248                         /* translators: %s: number of comments moved to the Trash */
249                         $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
250                 }
251
252                 if ( $untrashed > 0 ) {
253                         /* translators: %s: number of comments restored from the Trash */
254                         $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed );
255                 }
256
257                 if ( $deleted > 0 ) {
258                         /* translators: %s: number of comments permanently deleted */
259                         $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
260                 }
261
262                 if ( $same > 0 && $comment = get_comment( $same ) ) {
263                         switch ( $comment->comment_approved ) {
264                                 case '1' :
265                                         $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
266                                         break;
267                                 case 'trash' :
268                                         $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
269                                         break;
270                                 case 'spam' :
271                                         $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
272                                         break;
273                         }
274                 }
275
276                 echo '<div id="moderated" class="updated notice is-dismissible"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
277         }
278 }
279 ?>
280
281 <?php $wp_list_table->views(); ?>
282
283 <form id="comments-form" method="get">
284
285 <?php $wp_list_table->search_box( __( 'Search Comments' ), 'comment' ); ?>
286
287 <?php if ( $post_id ) : ?>
288 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
289 <?php endif; ?>
290 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
291 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
292
293 <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" />
294 <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" />
295 <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" />
296
297 <?php if ( isset($_REQUEST['paged']) ) { ?>
298         <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
299 <?php } ?>
300
301 <?php $wp_list_table->display(); ?>
302 </form>
303 </div>
304
305 <div id="ajax-response"></div>
306
307 <?php
308 wp_comment_reply('-1', true, 'detail');
309 wp_comment_trashnotice();
310 include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>