22 $doaction = $wp_list_table->current_action(); |
22 $doaction = $wp_list_table->current_action(); |
23 |
23 |
24 if ( $doaction ) { |
24 if ( $doaction ) { |
25 check_admin_referer( 'bulk-comments' ); |
25 check_admin_referer( 'bulk-comments' ); |
26 |
26 |
27 if ( 'delete_all' == $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) { |
27 if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) { |
28 $comment_status = wp_unslash( $_REQUEST['comment_status'] ); |
28 $comment_status = wp_unslash( $_REQUEST['comment_status'] ); |
29 $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] ); |
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 ) ); |
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'; |
31 $doaction = 'delete'; |
32 } elseif ( isset( $_REQUEST['delete_comments'] ) ) { |
32 } elseif ( isset( $_REQUEST['delete_comments'] ) ) { |
33 $comment_ids = $_REQUEST['delete_comments']; |
33 $comment_ids = $_REQUEST['delete_comments']; |
34 $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2']; |
34 $doaction = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; |
35 } elseif ( isset( $_REQUEST['ids'] ) ) { |
35 } elseif ( isset( $_REQUEST['ids'] ) ) { |
36 $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) ); |
36 $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) ); |
37 } elseif ( wp_get_referer() ) { |
37 } elseif ( wp_get_referer() ) { |
38 wp_safe_redirect( wp_get_referer() ); |
38 wp_safe_redirect( wp_get_referer() ); |
39 exit; |
39 exit; |
40 } |
40 } |
41 |
41 |
42 $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; |
42 $approved = 0; |
|
43 $unapproved = 0; |
|
44 $spammed = 0; |
|
45 $unspammed = 0; |
|
46 $trashed = 0; |
|
47 $untrashed = 0; |
|
48 $deleted = 0; |
43 |
49 |
44 $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() ); |
50 $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 ); |
51 $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to ); |
46 |
52 |
47 wp_defer_comment_counting( true ); |
53 wp_defer_comment_counting( true ); |
48 |
54 |
49 foreach ( $comment_ids as $comment_id ) { // Check the permissions on each |
55 foreach ( $comment_ids as $comment_id ) { // Check the permissions on each. |
50 if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
56 if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
51 continue; |
57 continue; |
52 } |
58 } |
53 |
59 |
54 switch ( $doaction ) { |
60 switch ( $doaction ) { |
84 } |
90 } |
85 |
91 |
86 if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) { |
92 if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) { |
87 $screen = get_current_screen()->id; |
93 $screen = get_current_screen()->id; |
88 |
94 |
89 /** |
95 /** This action is documented in wp-admin/edit.php */ |
90 * Fires when a custom bulk action should be handled. |
96 $redirect_to = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to, $doaction, $comment_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
91 * |
|
92 * The redirect link should be modified with success or failure feedback |
|
93 * from the action to be used to display feedback to the user. |
|
94 * |
|
95 * The dynamic portion of the hook name, `$screen`, refers to the current screen ID. |
|
96 * |
|
97 * @since 4.7.0 |
|
98 * |
|
99 * @param string $redirect_url The redirect URL. |
|
100 * @param string $doaction The action being taken. |
|
101 * @param array $items The items to take the action on. |
|
102 */ |
|
103 $redirect_to = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to, $doaction, $comment_ids ); |
|
104 } |
97 } |
105 |
98 |
106 wp_defer_comment_counting( false ); |
99 wp_defer_comment_counting( false ); |
107 |
100 |
108 if ( $approved ) { |
101 if ( $approved ) { |
144 |
137 |
145 if ( $post_id ) { |
138 if ( $post_id ) { |
146 $comments_count = wp_count_comments( $post_id ); |
139 $comments_count = wp_count_comments( $post_id ); |
147 $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ); |
140 $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ); |
148 if ( $comments_count->moderated > 0 ) { |
141 if ( $comments_count->moderated > 0 ) { |
149 /* translators: 1: comments count, 2: post title */ |
|
150 $title = sprintf( |
142 $title = sprintf( |
|
143 /* translators: 1: Comments count, 2: Post title. */ |
151 __( 'Comments (%1$s) on “%2$s”' ), |
144 __( 'Comments (%1$s) on “%2$s”' ), |
152 number_format_i18n( $comments_count->moderated ), |
145 number_format_i18n( $comments_count->moderated ), |
153 $draft_or_post_title |
146 $draft_or_post_title |
154 ); |
147 ); |
155 } else { |
148 } else { |
156 /* translators: %s: post title */ |
|
157 $title = sprintf( |
149 $title = sprintf( |
|
150 /* translators: %s: Post title. */ |
158 __( 'Comments on “%s”' ), |
151 __( 'Comments on “%s”' ), |
159 $draft_or_post_title |
152 $draft_or_post_title |
160 ); |
153 ); |
161 } |
154 } |
162 } else { |
155 } else { |
163 $comments_count = wp_count_comments(); |
156 $comments_count = wp_count_comments(); |
164 if ( $comments_count->moderated > 0 ) { |
157 if ( $comments_count->moderated > 0 ) { |
165 /* translators: %s: comments count */ |
|
166 $title = sprintf( |
158 $title = sprintf( |
|
159 /* translators: %s: Comments count. */ |
167 __( 'Comments (%s)' ), |
160 __( 'Comments (%s)' ), |
168 number_format_i18n( $comments_count->moderated ) |
161 number_format_i18n( $comments_count->moderated ) |
169 ); |
162 ); |
170 } else { |
163 } else { |
171 $title = __( 'Comments' ); |
164 $title = __( 'Comments' ); |
177 get_current_screen()->add_help_tab( |
170 get_current_screen()->add_help_tab( |
178 array( |
171 array( |
179 'id' => 'overview', |
172 'id' => 'overview', |
180 'title' => __( 'Overview' ), |
173 'title' => __( 'Overview' ), |
181 'content' => |
174 'content' => |
182 '<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>', |
175 '<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>', |
183 ) |
176 ) |
184 ); |
177 ); |
185 get_current_screen()->add_help_tab( |
178 get_current_screen()->add_help_tab( |
186 array( |
179 array( |
187 'id' => 'moderating-comments', |
180 'id' => 'moderating-comments', |
188 'title' => __( 'Moderating Comments' ), |
181 'title' => __( 'Moderating Comments' ), |
189 'content' => |
182 'content' => |
190 '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' . |
183 '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' . |
191 '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author’s name, email address, and blog URL, the commenter’s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' . |
184 '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author’s name, email address, and blog URL, the commenter’s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' . |
192 '<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>' . |
185 '<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>' . |
193 '<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>' . |
186 '<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>' . |
194 '<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>' . |
187 '<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>' . |
195 '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>', |
188 '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>', |
196 ) |
189 ) |
197 ); |
190 ); |
198 |
191 |
199 get_current_screen()->set_help_sidebar( |
192 get_current_screen()->set_help_sidebar( |
200 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
193 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
201 '<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments">Documentation on Comments</a>' ) . '</p>' . |
194 '<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' . |
202 '<p>' . __( '<a href="https://codex.wordpress.org/Comment_Spam">Documentation on Comment Spam</a>' ) . '</p>' . |
195 '<p>' . __( '<a href="https://wordpress.org/support/article/comment-spam/">Documentation on Comment Spam</a>' ) . '</p>' . |
203 '<p>' . __( '<a href="https://codex.wordpress.org/Keyboard_Shortcuts">Documentation on Keyboard Shortcuts</a>' ) . '</p>' . |
196 '<p>' . __( '<a href="https://wordpress.org/support/article/keyboard-shortcuts/">Documentation on Keyboard Shortcuts</a>' ) . '</p>' . |
204 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
197 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
205 ); |
198 ); |
206 |
199 |
207 get_current_screen()->set_screen_reader_content( |
200 get_current_screen()->set_screen_reader_content( |
208 array( |
201 array( |
210 'heading_pagination' => __( 'Comments list navigation' ), |
203 'heading_pagination' => __( 'Comments list navigation' ), |
211 'heading_list' => __( 'Comments list' ), |
204 'heading_list' => __( 'Comments list' ), |
212 ) |
205 ) |
213 ); |
206 ); |
214 |
207 |
215 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
208 require_once ABSPATH . 'wp-admin/admin-header.php'; |
216 ?> |
209 ?> |
217 |
210 |
218 <div class="wrap"> |
211 <div class="wrap"> |
219 <h1 class="wp-heading-inline"> |
212 <h1 class="wp-heading-inline"> |
220 <?php |
213 <?php |
221 if ( $post_id ) { |
214 if ( $post_id ) { |
222 /* translators: %s: link to post */ |
|
223 printf( |
215 printf( |
|
216 /* translators: %s: Link to post. */ |
224 __( 'Comments on “%s”' ), |
217 __( 'Comments on “%s”' ), |
225 sprintf( |
218 sprintf( |
226 '<a href="%1$s">%2$s</a>', |
219 '<a href="%1$s">%2$s</a>', |
227 get_edit_post_link( $post_id ), |
220 get_edit_post_link( $post_id ), |
228 wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ) |
221 wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ) |
274 $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0; |
267 $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0; |
275 $same = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0; |
268 $same = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0; |
276 |
269 |
277 if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) { |
270 if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) { |
278 if ( $approved > 0 ) { |
271 if ( $approved > 0 ) { |
279 /* translators: %s: number of comments approved */ |
272 /* translators: %s: Number of comments. */ |
280 $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved ); |
273 $messages[] = sprintf( _n( '%s comment approved.', '%s comments approved.', $approved ), $approved ); |
281 } |
274 } |
282 |
275 |
283 if ( $spammed > 0 ) { |
276 if ( $spammed > 0 ) { |
284 $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0; |
277 $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0; |
285 /* translators: %s: number of comments marked as spam */ |
278 /* translators: %s: Number of comments. */ |
286 $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 />'; |
279 $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 />'; |
287 } |
280 } |
288 |
281 |
289 if ( $unspammed > 0 ) { |
282 if ( $unspammed > 0 ) { |
290 /* translators: %s: number of comments restored from the spam */ |
283 /* translators: %s: Number of comments. */ |
291 $messages[] = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed ); |
284 $messages[] = sprintf( _n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ), $unspammed ); |
292 } |
285 } |
293 |
286 |
294 if ( $trashed > 0 ) { |
287 if ( $trashed > 0 ) { |
295 $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0; |
288 $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0; |
296 /* translators: %s: number of comments moved to the Trash */ |
289 /* translators: %s: Number of comments. */ |
297 $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 />'; |
290 $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 />'; |
298 } |
291 } |
299 |
292 |
300 if ( $untrashed > 0 ) { |
293 if ( $untrashed > 0 ) { |
301 /* translators: %s: number of comments restored from the Trash */ |
294 /* translators: %s: Number of comments. */ |
302 $messages[] = sprintf( _n( '%s comment restored from the Trash', '%s comments restored from the Trash', $untrashed ), $untrashed ); |
295 $messages[] = sprintf( _n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ), $untrashed ); |
303 } |
296 } |
304 |
297 |
305 if ( $deleted > 0 ) { |
298 if ( $deleted > 0 ) { |
306 /* translators: %s: number of comments permanently deleted */ |
299 /* translators: %s: Number of comments. */ |
307 $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted ); |
300 $messages[] = sprintf( _n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ), $deleted ); |
308 } |
301 } |
309 |
302 |
310 if ( $same > 0 && $comment = get_comment( $same ) ) { |
303 if ( $same > 0 ) { |
311 switch ( $comment->comment_approved ) { |
304 $comment = get_comment( $same ); |
312 case '1': |
305 if ( $comment ) { |
313 $messages[] = __( 'This comment is already approved.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; |
306 switch ( $comment->comment_approved ) { |
314 break; |
307 case '1': |
315 case 'trash': |
308 $messages[] = __( 'This comment is already approved.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; |
316 $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>'; |
309 break; |
317 break; |
310 case 'trash': |
318 case 'spam': |
311 $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>'; |
319 $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; |
312 break; |
320 break; |
313 case 'spam': |
|
314 $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; |
|
315 break; |
|
316 } |
321 } |
317 } |
322 } |
318 } |
323 |
319 |
324 echo '<div id="moderated" class="updated notice is-dismissible"><p>' . implode( "<br/>\n", $messages ) . '</p></div>'; |
320 echo '<div id="moderated" class="updated notice is-dismissible"><p>' . implode( "<br/>\n", $messages ) . '</p></div>'; |
325 } |
321 } |