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