[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Comment Management Screen 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** Load WordPress Bootstrap */ 10 require_once __DIR__ . '/admin.php'; 11 12 $parent_file = 'edit-comments.php'; 13 $submenu_file = 'edit-comments.php'; 14 15 /** 16 * @global string $action 17 */ 18 global $action; 19 wp_reset_vars( array( 'action' ) ); 20 21 if ( isset( $_POST['deletecomment'] ) ) { 22 $action = 'deletecomment'; 23 } 24 25 if ( 'cdc' === $action ) { 26 $action = 'delete'; 27 } elseif ( 'mac' === $action ) { 28 $action = 'approve'; 29 } 30 31 if ( isset( $_GET['dt'] ) ) { 32 if ( 'spam' === $_GET['dt'] ) { 33 $action = 'spam'; 34 } elseif ( 'trash' === $_GET['dt'] ) { 35 $action = 'trash'; 36 } 37 } 38 39 if ( isset( $_REQUEST['c'] ) ) { 40 $comment_id = absint( $_REQUEST['c'] ); 41 $comment = get_comment( $comment_id ); 42 43 // Prevent actions on a comment associated with a trashed post. 44 if ( $comment && 'trash' === get_post_status( $comment->comment_post_ID ) ) { 45 wp_die( 46 __( 'You can’t edit this comment because the associated post is in the Trash. Please restore the post first, then try again.' ) 47 ); 48 } 49 } else { 50 $comment = null; 51 } 52 53 switch ( $action ) { 54 55 case 'editcomment': 56 $title = __( 'Edit Comment' ); 57 58 get_current_screen()->add_help_tab( 59 array( 60 'id' => 'overview', 61 'title' => __( 'Overview' ), 62 'content' => 63 '<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>' . 64 '<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>', 65 ) 66 ); 67 68 get_current_screen()->set_help_sidebar( 69 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 70 '<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' . 71 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' 72 ); 73 74 wp_enqueue_script( 'comment' ); 75 require_once ABSPATH . 'wp-admin/admin-header.php'; 76 77 if ( ! $comment ) { 78 comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'javascript:history.go(-1)' ) ); 79 } 80 81 if ( ! current_user_can( 'edit_comment', $comment_id ) ) { 82 comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) ); 83 } 84 85 if ( 'trash' === $comment->comment_approved ) { 86 comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) ); 87 } 88 89 $comment = get_comment_to_edit( $comment_id ); 90 91 require ABSPATH . 'wp-admin/edit-form-comment.php'; 92 93 break; 94 95 case 'delete': 96 case 'approve': 97 case 'trash': 98 case 'spam': 99 $title = __( 'Moderate Comment' ); 100 101 if ( ! $comment ) { 102 wp_redirect( admin_url( 'edit-comments.php?error=1' ) ); 103 die(); 104 } 105 106 if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { 107 wp_redirect( admin_url( 'edit-comments.php?error=2' ) ); 108 die(); 109 } 110 111 // No need to re-approve/re-trash/re-spam a comment. 112 if ( str_replace( '1', 'approve', $comment->comment_approved ) === $action ) { 113 wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) ); 114 die(); 115 } 116 117 require_once ABSPATH . 'wp-admin/admin-header.php'; 118 119 $formaction = $action . 'comment'; 120 $nonce_action = ( 'approve' === $action ) ? 'approve-comment_' : 'delete-comment_'; 121 $nonce_action .= $comment_id; 122 123 ?> 124 <div class="wrap"> 125 126 <h1><?php echo esc_html( $title ); ?></h1> 127 128 <?php 129 switch ( $action ) { 130 case 'spam': 131 $caution_msg = __( 'You are about to mark the following comment as spam:' ); 132 $button = _x( 'Mark as spam', 'comment' ); 133 break; 134 case 'trash': 135 $caution_msg = __( 'You are about to move the following comment to the Trash:' ); 136 $button = __( 'Move to Trash' ); 137 break; 138 case 'delete': 139 $caution_msg = __( 'You are about to delete the following comment:' ); 140 $button = __( 'Permanently delete comment' ); 141 break; 142 default: 143 $caution_msg = __( 'You are about to approve the following comment:' ); 144 $button = __( 'Approve comment' ); 145 break; 146 } 147 148 if ( '0' !== $comment->comment_approved ) { // If not unapproved. 149 $message = ''; 150 switch ( $comment->comment_approved ) { 151 case '1': 152 $message = __( 'This comment is currently approved.' ); 153 break; 154 case 'spam': 155 $message = __( 'This comment is currently marked as spam.' ); 156 break; 157 case 'trash': 158 $message = __( 'This comment is currently in the Trash.' ); 159 break; 160 } 161 if ( $message ) { 162 echo '<div id="message" class="notice notice-info"><p>' . $message . '</p></div>'; 163 } 164 } 165 ?> 166 <div id="message" class="notice notice-warning"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo $caution_msg; ?></p></div> 167 168 <table class="form-table comment-ays"> 169 <tr> 170 <th scope="row"><?php _e( 'Author' ); ?></th> 171 <td><?php comment_author( $comment ); ?></td> 172 </tr> 173 <?php if ( get_comment_author_email( $comment ) ) { ?> 174 <tr> 175 <th scope="row"><?php _e( 'Email' ); ?></th> 176 <td><?php comment_author_email( $comment ); ?></td> 177 </tr> 178 <?php } ?> 179 <?php if ( get_comment_author_url( $comment ) ) { ?> 180 <tr> 181 <th scope="row"><?php _e( 'URL' ); ?></th> 182 <td><a href="<?php comment_author_url( $comment ); ?>"><?php comment_author_url( $comment ); ?></a></td> 183 </tr> 184 <?php } ?> 185 <tr> 186 <th scope="row"><?php /* translators: Column name or table row header. */ _e( 'In response to' ); ?></th> 187 <td> 188 <?php 189 $post_id = $comment->comment_post_ID; 190 if ( current_user_can( 'edit_post', $post_id ) ) { 191 $post_link = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>"; 192 $post_link .= esc_html( get_the_title( $post_id ) ) . '</a>'; 193 } else { 194 $post_link = esc_html( get_the_title( $post_id ) ); 195 } 196 echo $post_link; 197 198 if ( $comment->comment_parent ) { 199 $parent = get_comment( $comment->comment_parent ); 200 $parent_link = esc_url( get_comment_link( $parent ) ); 201 $name = get_comment_author( $parent ); 202 printf( 203 /* translators: %s: Comment link. */ 204 ' | ' . __( 'In reply to %s.' ), 205 '<a href="' . $parent_link . '">' . $name . '</a>' 206 ); 207 } 208 ?> 209 </td> 210 </tr> 211 <tr> 212 <th scope="row"><?php _e( 'Submitted on' ); ?></th> 213 <td> 214 <?php 215 $submitted = sprintf( 216 /* translators: 1: Comment date, 2: Comment time. */ 217 __( '%1$s at %2$s' ), 218 /* translators: Comment date format. See https://www.php.net/manual/datetime.format.php */ 219 get_comment_date( __( 'Y/m/d' ), $comment ), 220 /* translators: Comment time format. See https://www.php.net/manual/datetime.format.php */ 221 get_comment_date( __( 'g:i a' ), $comment ) 222 ); 223 if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) { 224 echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>'; 225 } else { 226 echo $submitted; 227 } 228 ?> 229 </td> 230 </tr> 231 <tr> 232 <th scope="row"><?php /* translators: Field name in comment form. */ _ex( 'Comment', 'noun' ); ?></th> 233 <td class="comment-content"> 234 <?php comment_text( $comment ); ?> 235 <p class="edit-comment"><a href="<?php echo admin_url( "comment.php?action=editcomment&c={$comment->comment_ID}" ); ?>"><?php esc_html_e( 'Edit' ); ?></a></p> 236 </td> 237 </tr> 238 </table> 239 240 <form action="comment.php" method="get" class="comment-ays-submit"> 241 242 <p> 243 <?php submit_button( $button, 'primary', 'submit', false ); ?> 244 <a href="<?php echo admin_url( 'edit-comments.php' ); ?>" class="button-cancel"><?php esc_html_e( 'Cancel' ); ?></a> 245 </p> 246 247 <?php wp_nonce_field( $nonce_action ); ?> 248 <input type="hidden" name="action" value="<?php echo esc_attr( $formaction ); ?>" /> 249 <input type="hidden" name="c" value="<?php echo esc_attr( $comment->comment_ID ); ?>" /> 250 <input type="hidden" name="noredir" value="1" /> 251 </form> 252 253 </div> 254 <?php 255 break; 256 257 case 'deletecomment': 258 case 'trashcomment': 259 case 'untrashcomment': 260 case 'spamcomment': 261 case 'unspamcomment': 262 case 'approvecomment': 263 case 'unapprovecomment': 264 $comment_id = absint( $_REQUEST['c'] ); 265 266 if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { 267 check_admin_referer( 'approve-comment_' . $comment_id ); 268 } else { 269 check_admin_referer( 'delete-comment_' . $comment_id ); 270 } 271 272 $noredir = isset( $_REQUEST['noredir'] ); 273 274 $comment = get_comment( $comment_id ); 275 if ( ! $comment ) { 276 comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'edit-comments.php' ) ); 277 } 278 if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { 279 comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) ); 280 } 281 282 if ( wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) { 283 $redir = wp_get_referer(); 284 } elseif ( wp_get_original_referer() && ! $noredir ) { 285 $redir = wp_get_original_referer(); 286 } elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { 287 $redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) ); 288 } else { 289 $redir = admin_url( 'edit-comments.php' ); 290 } 291 292 $redir = remove_query_arg( array( 'spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved' ), $redir ); 293 294 switch ( $action ) { 295 case 'deletecomment': 296 wp_delete_comment( $comment ); 297 $redir = add_query_arg( array( 'deleted' => '1' ), $redir ); 298 break; 299 case 'trashcomment': 300 wp_trash_comment( $comment ); 301 $redir = add_query_arg( 302 array( 303 'trashed' => '1', 304 'ids' => $comment_id, 305 ), 306 $redir 307 ); 308 break; 309 case 'untrashcomment': 310 wp_untrash_comment( $comment ); 311 $redir = add_query_arg( array( 'untrashed' => '1' ), $redir ); 312 break; 313 case 'spamcomment': 314 wp_spam_comment( $comment ); 315 $redir = add_query_arg( 316 array( 317 'spammed' => '1', 318 'ids' => $comment_id, 319 ), 320 $redir 321 ); 322 break; 323 case 'unspamcomment': 324 wp_unspam_comment( $comment ); 325 $redir = add_query_arg( array( 'unspammed' => '1' ), $redir ); 326 break; 327 case 'approvecomment': 328 wp_set_comment_status( $comment, 'approve' ); 329 $redir = add_query_arg( array( 'approved' => 1 ), $redir ); 330 break; 331 case 'unapprovecomment': 332 wp_set_comment_status( $comment, 'hold' ); 333 $redir = add_query_arg( array( 'unapproved' => 1 ), $redir ); 334 break; 335 } 336 337 wp_redirect( $redir ); 338 die; 339 340 case 'editedcomment': 341 $comment_id = absint( $_POST['comment_ID'] ); 342 $comment_post_id = absint( $_POST['comment_post_ID'] ); 343 344 check_admin_referer( 'update-comment_' . $comment_id ); 345 346 $updated = edit_comment(); 347 if ( is_wp_error( $updated ) ) { 348 wp_die( $updated->get_error_message() ); 349 } 350 351 $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id; 352 353 /** 354 * Filters the URI the user is redirected to after editing a comment in the admin. 355 * 356 * @since 2.1.0 357 * 358 * @param string $location The URI the user will be redirected to. 359 * @param int $comment_id The ID of the comment being edited. 360 */ 361 $location = apply_filters( 'comment_edit_redirect', $location, $comment_id ); 362 363 wp_redirect( $location ); 364 exit; 365 366 default: 367 wp_die( __( 'Unknown action.' ) ); 368 369 } // End switch. 370 371 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Mon Jan 18 08:20:02 2021 | Cross-referenced by PHPXref |