3 * Comment Management Screen
6 * @subpackage Administration
9 /** Load WordPress Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
12 $parent_file = 'edit-comments.php';
13 $submenu_file = 'edit-comments.php';
16 * @global string $action
19 wp_reset_vars( array('action') );
21 if ( isset( $_POST['deletecomment'] ) )
22 $action = 'deletecomment';
24 if ( 'cdc' == $action )
26 elseif ( 'mac' == $action )
29 if ( isset( $_GET['dt'] ) ) {
30 if ( 'spam' == $_GET['dt'] )
32 elseif ( 'trash' == $_GET['dt'] )
37 * Display error message at bottom of comments.
39 * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
41 function comment_footer_die( $msg ) {
42 echo "<div class='wrap'><p>$msg</p></div>";
43 include( ABSPATH . 'wp-admin/admin-footer.php' );
50 $title = __('Edit Comment');
52 get_current_screen()->add_help_tab( array(
54 'title' => __('Overview'),
56 '<p>' . __( 'You can edit the information left in a comment if needed. This is often useful when you notice that a commenter has made a typographical error.' ) . '</p>' .
57 '<p>' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '</p>'
60 get_current_screen()->set_help_sidebar(
61 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
62 '<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
63 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
66 wp_enqueue_script('comment');
67 require_once( ABSPATH . 'wp-admin/admin-header.php' );
69 $comment_id = absint( $_GET['c'] );
71 if ( !$comment = get_comment( $comment_id ) )
72 comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'javascript:history.go(-1)') );
74 if ( !current_user_can( 'edit_comment', $comment_id ) )
75 comment_footer_die( __('You are not allowed to edit this comment.') );
77 if ( 'trash' == $comment->comment_approved )
78 comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
80 $comment = get_comment_to_edit( $comment_id );
82 include( ABSPATH . 'wp-admin/edit-form-comment.php' );
91 $title = __('Moderate Comment');
93 $comment_id = absint( $_GET['c'] );
95 if ( !$comment = get_comment_to_edit( $comment_id ) ) {
96 wp_redirect( admin_url('edit-comments.php?error=1') );
100 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
101 wp_redirect( admin_url('edit-comments.php?error=2') );
105 // No need to re-approve/re-trash/re-spam a comment.
106 if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
107 wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
111 require_once( ABSPATH . 'wp-admin/admin-header.php' );
113 $formaction = $action . 'comment';
114 $nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
115 $nonce_action .= $comment_id;
120 <h1><?php echo esc_html( $title ); ?></h1>
125 $caution_msg = __('You are about to mark the following comment as spam:');
126 $button = _x( 'Mark as Spam', 'comment' );
129 $caution_msg = __('You are about to move the following comment to the Trash:');
130 $button = __('Move to Trash');
133 $caution_msg = __('You are about to delete the following comment:');
134 $button = __('Permanently Delete Comment');
137 $caution_msg = __('You are about to approve the following comment:');
138 $button = __('Approve Comment');
142 if ( $comment->comment_approved != '0' ) { // if not unapproved
144 switch ( $comment->comment_approved ) {
146 $message = __('This comment is currently approved.');
149 $message = __('This comment is currently marked as spam.');
152 $message = __('This comment is currently in the Trash.');
156 echo '<div class="notice notice-info"><p>' . $message . '</p></div>';
160 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
162 <table class="form-table comment-ays">
164 <th scope="row"><?php _e('Author'); ?></th>
165 <td><?php echo $comment->comment_author; ?></td>
167 <?php if ( $comment->comment_author_email ) { ?>
169 <th scope="row"><?php _e('E-mail'); ?></th>
170 <td><?php echo $comment->comment_author_email; ?></td>
173 <?php if ( $comment->comment_author_url ) { ?>
175 <th scope="row"><?php _e('URL'); ?></th>
176 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
180 <th scope="row"><?php /* translators: column name or table row header */ _e( 'In Response To' ); ?></th>
183 $post_id = $comment->comment_post_ID;
184 if ( current_user_can( 'edit_post', $post_id ) ) {
185 $post_link = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
186 $post_link .= esc_html( get_the_title( $post_id ) ) . '</a>';
188 $post_link = esc_html( get_the_title( $post_id ) );
192 if ( $comment->comment_parent ) {
193 $parent = get_comment( $comment->comment_parent );
194 $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
195 $name = get_comment_author( $parent->comment_ID );
196 printf( ' | ' . __( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
202 <th scope="row"><?php _e( 'Submitted on' ); ?></th>
205 /* translators: 2: comment date, 3: comment time */
206 printf( __( '<a href="%1$s">%2$s at %3$s</a>' ),
207 esc_url( get_comment_link( $comment->comment_ID ) ),
208 /* translators: comment date format. See http://php.net/date */
209 get_comment_date( __( 'Y/m/d' ) ),
210 get_comment_date( get_option( 'time_format' ) )
216 <th scope="row"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
217 <td><?php echo $comment->comment_content; ?></td>
221 <form action="comment.php" method="get" class="comment-ays-submit">
224 <?php submit_button( $button, 'primary', 'submit', false ); ?>
225 <a href="<?php echo admin_url('edit-comments.php'); ?>" class="button-cancel"><?php esc_attr_e( 'Cancel' ); ?></a></td>
228 <?php wp_nonce_field( $nonce_action ); ?>
229 <input type="hidden" name="action" value="<?php echo esc_attr($formaction); ?>" />
230 <input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID); ?>" />
231 <input type="hidden" name="noredir" value="1" />
238 case 'deletecomment' :
239 case 'trashcomment' :
240 case 'untrashcomment' :
242 case 'unspamcomment' :
243 case 'approvecomment' :
244 case 'unapprovecomment' :
245 $comment_id = absint( $_REQUEST['c'] );
247 if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
248 check_admin_referer( 'approve-comment_' . $comment_id );
250 check_admin_referer( 'delete-comment_' . $comment_id );
252 $noredir = isset($_REQUEST['noredir']);
254 if ( !$comment = get_comment($comment_id) )
255 comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') );
256 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
257 comment_footer_die( __('You are not allowed to edit comments on this post.') );
259 if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
260 $redir = wp_get_referer();
261 elseif ( '' != wp_get_original_referer() && ! $noredir )
262 $redir = wp_get_original_referer();
263 elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
264 $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
266 $redir = admin_url('edit-comments.php');
268 $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
271 case 'deletecomment' :
272 wp_delete_comment( $comment_id );
273 $redir = add_query_arg( array('deleted' => '1'), $redir );
275 case 'trashcomment' :
276 wp_trash_comment($comment_id);
277 $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
279 case 'untrashcomment' :
280 wp_untrash_comment($comment_id);
281 $redir = add_query_arg( array('untrashed' => '1'), $redir );
284 wp_spam_comment($comment_id);
285 $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
287 case 'unspamcomment' :
288 wp_unspam_comment($comment_id);
289 $redir = add_query_arg( array('unspammed' => '1'), $redir );
291 case 'approvecomment' :
292 wp_set_comment_status( $comment_id, 'approve' );
293 $redir = add_query_arg( array( 'approved' => 1 ), $redir );
295 case 'unapprovecomment' :
296 wp_set_comment_status( $comment_id, 'hold' );
297 $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
301 wp_redirect( $redir );
304 case 'editedcomment' :
306 $comment_id = absint( $_POST['comment_ID'] );
307 $comment_post_id = absint( $_POST['comment_post_ID'] );
309 check_admin_referer( 'update-comment_' . $comment_id );
313 $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
316 * Filter the URI the user is redirected to after editing a comment in the admin.
320 * @param string $location The URI the user will be redirected to.
321 * @param int $comment_id The ID of the comment being edited.
323 $location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
324 wp_redirect( $location );
329 wp_die( __('Unknown action.') );
333 include( ABSPATH . 'wp-admin/admin-footer.php' );