Ticket #33717: 33717.13.diff
| File 33717.13.diff, 18.0 KB (added by , 6 years ago) |
|---|
-
src/wp-admin/comment.php
165 165 ?> 166 166 <div id="message" class="notice notice-warning"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo $caution_msg; ?></p></div> 167 167 168 <?php 169 if ( '0' === $comment->comment_approved && get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) : 170 ?> 171 <div id="approval-message" class="notice notice-warning"> 172 <p> 173 <?php 174 /* translators: %s is the comment author name. */ 175 printf( 176 esc_html__( '%s has opted in to receive a notification upon approval.' ), 177 get_comment_author( $comment ) 178 ); 179 ?> 180 </p> 181 </div> 182 <?php endif; ?> 183 168 184 <table class="form-table comment-ays"> 169 185 <tr> 170 186 <th scope="row"><?php _e( 'Author' ); ?></th> -
src/wp-admin/css/dashboard.css
821 821 position: relative; 822 822 } 823 823 824 #activity-widget #the-comment-list .comment-item .attention { 825 display: none; 826 color: #d54e21; 827 font-size: 90%; 828 } 829 824 830 #activity-widget #the-comment-list .avatar { 825 831 position: absolute; 826 832 top: 12px; … … 857 863 width: 4px; 858 864 } 859 865 866 #activity-widget #the-comment-list .unapproved .attention { 867 display: block; 868 } 869 860 870 #activity-widget #the-comment-list .spam-undo-inside .avatar, 861 871 #activity-widget #the-comment-list .trash-undo-inside .avatar { 862 872 position: relative; -
src/wp-admin/css/list-tables.css
217 217 background-color: #f5f5f5; 218 218 } 219 219 220 #the-comment-list .comment .attention { 221 display: none; 222 color: #d54e21; 223 font-size: 90%; 224 } 225 220 226 #the-comment-list .unapproved th, 221 227 #the-comment-list .unapproved td { 222 228 background-color: #fef7f1; … … 230 236 margin-left: 4px; 231 237 } 232 238 239 #the-comment-list .comment.unapproved .attention { 240 display: block; 241 } 242 233 243 #the-comment-list .approve a { 234 244 color: #006505; 235 245 } -
src/wp-admin/edit-form-comment.php
16 16 <div class="wrap"> 17 17 <h1><?php _e( 'Edit Comment' ); ?></h1> 18 18 19 <?php 20 if ( '0' === $comment->comment_approved && get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) : 21 ?> 22 <div id="message" class="notice notice-warning"> 23 <p> 24 <?php 25 /* translators: %s is the comment author name. */ 26 printf( 27 esc_html__( '%s has opted in to receive a notification upon approval.' ), 28 get_comment_author( $comment ) 29 ); 30 ?> 31 </p> 32 </div> 33 <?php endif; ?> 34 19 35 <div id="poststuff"> 20 36 <input type="hidden" name="action" value="editedcomment" /> 21 37 <input type="hidden" name="comment_ID" value="<?php echo esc_attr( $comment->comment_ID ); ?>" /> -
src/wp-admin/includes/class-wp-comments-list-table.php
882 882 } 883 883 } 884 884 885 if ( '0' === $comment->comment_approved && get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) { 886 echo '<p class="attention"><span class="dashicons dashicons-info"></span> '; 887 /* translators: %s is the comment author name. */ 888 printf( 889 esc_html__( '%s has opted in to receive a notification upon approval.' ), 890 get_comment_author( $comment ) 891 ); 892 echo '</p>'; 893 } 894 885 895 comment_text( $comment ); 886 896 887 897 if ( $this->user_can ) { -
src/wp-admin/includes/dashboard.php
829 829 </p> 830 830 831 831 <?php 832 if ( '0' === $comment->comment_approved && get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) : 833 ?> 834 <p class="attention"> 835 <span class="dashicons dashicons-info"></span> 836 <?php 837 /* translators: %s is the comment author name. */ 838 printf( 839 esc_html__( '%s has opted in to receive a notification upon approval.' ), 840 get_comment_author( $comment ) 841 ); 842 ?> 843 </p> 844 <?php 845 endif; 832 846 else : 833 847 switch ( $comment->comment_type ) { 834 848 case 'pingback': -
src/wp-comments-post.php
22 22 23 23 nocache_headers(); 24 24 25 if ( isset( $_POST['wp-comment-approved-notification-optin'], $_POST['comment_ID'], $_POST['moderation-hash'] ) ) { 26 $comment = get_comment( $_POST['comment_ID'] ); 27 28 if ( ! is_null( $comment->comment_ID ) && hash_equals( $_POST['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) { 29 update_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ); 30 } else { 31 wp_die( 32 '<p>' . __( 'Sorry we haven’t found your comment.' ) . '</p>', 33 __( 'Comment Notification opt-in failure' ), 34 array( 35 'back_link' => true, 36 ) 37 ); 38 } 39 } else { 25 40 $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); 26 41 if ( is_wp_error( $comment ) ) { 27 42 $data = (int) $comment->get_error_data(); … … 53 68 * @param bool $cookies_consent Comment author's consent to store cookies. 54 69 */ 55 70 do_action( 'set_comment_cookies', $comment, $user, $cookies_consent ); 71 } 56 72 57 73 $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID; 58 74 -
src/wp-includes/class-walker-comment.php
41 41 ); 42 42 43 43 /** 44 * Backward compability checks. 45 * 46 * @since 5.7.0 47 * @var bool[] 48 */ 49 public $backcompat = array( 50 'needs_comment_approval_notification_output' => true, 51 ); 52 53 /** 44 54 * Starts the list before the elements are added. 45 55 * 46 56 * @since 2.7.0 … … 259 269 * to the comment cookies. 260 270 * 261 271 * @since 5.4.2 272 * @since 5.7.0 Adds backcompatibilty output if needed. 262 273 * 263 274 * @param string $comment_text Text of the current comment. 264 275 * @param WP_Comment|null $comment The comment object. Null if not found. … … 272 283 $comment_text = wp_kses( $comment_text, array() ); 273 284 } 274 285 286 /* 287 * Checks if we need to output the comment approval notification/form. 288 */ 289 if ( $this->backcompat['needs_comment_approval_notification_output'] ) { 290 $comment_text = $this->comment_approval_notification_form( $comment, true ) . "\n" . $comment_text; 291 } 292 275 293 return $comment_text; 276 294 } 277 295 278 296 /** 297 * Outputs the awaiting moderation text. 298 * 299 * @since 5.7.0 300 * 301 * @param WP_Comment $comment Comment to display. 302 */ 303 protected function awaiting_moderation_text( $comment ) { 304 if ( '0' !== $comment->comment_approved ) { 305 return; 306 } 307 308 $commenter = wp_get_current_commenter(); 309 310 if ( $commenter['comment_author_email'] ) { 311 $moderation_note = __( 'Your comment is awaiting moderation.' ); 312 } else { 313 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' ); 314 } 315 316 printf( 317 '<em class="comment-awaiting-moderation">%s</em>', 318 esc_html( $moderation_note ) 319 ); 320 } 321 322 /** 323 * Gets the comment's approval notification or form for opting in. 324 * 325 * @since 5.7.0 326 * 327 * @param WP_Comment $comment Comment to display. 328 * @param bool $skip_backcompat True to skip the backward compability output. 329 * False otherwise. 330 * @return string HTML output. 331 */ 332 protected function comment_approval_notification_form( $comment, $skip_backcompat = false ) { 333 $comment_approval_output = ''; 334 335 if ( '0' === $comment->comment_approved && has_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' ) ) { 336 if ( get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) { 337 $comment_approval_output = sprintf( 338 '<p><em class="wp-comment-approved-notification-optedin">%s</em></p>', 339 esc_html__( 'You will receive an email when your comment is approved.' ) 340 ); 341 } else { 342 $comment_approval_output = sprintf( 343 '<form action="%1$s" method="post"> 344 <p> 345 <label for="wp-comment-approved-notification-optin"> 346 <input type="checkbox" id="wp-comment-approved-notification-optin" name="wp-comment-approved-notification-optin"> 347 %2$s 348 </label> 349 </p> 350 <input type="hidden" name="comment_ID" value="%3$s"> 351 <input type="hidden" name="moderation-hash" value="%4$s"> 352 <input type="submit" class="button" value="%5$s"> 353 </form>', 354 esc_url( site_url( '/wp-comments-post.php' ) ), 355 esc_html__( 'I want to be notified by email when my comment is approved.' ), 356 absint( $comment->comment_ID ), 357 wp_hash( $comment->comment_date_gmt ), 358 esc_html_x( 'Save', 'comment approval notification form' ) 359 ); 360 } 361 } 362 363 // Skip the backcompat output. 364 if ( $skip_backcompat ) { 365 $this->backcompat['needs_comment_approval_notification_output'] = false; 366 } 367 368 // Return the approval notification/form. 369 return $comment_approval_output; 370 } 371 372 /** 279 373 * Outputs a single comment. 280 374 * 281 375 * @since 3.6.0 … … 297 391 298 392 $commenter = wp_get_current_commenter(); 299 393 $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author']; 300 301 if ( $commenter['comment_author_email'] ) {302 $moderation_note = __( 'Your comment is awaiting moderation.' );303 } else {304 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' );305 }306 394 ?> 307 395 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>"> 308 396 <?php if ( 'div' !== $args['style'] ) : ?> … … 328 416 ); 329 417 ?> 330 418 </div> 331 <?php if ( '0' == $comment->comment_approved ) : ?> 332 <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em> 333 <br /> 334 <?php endif; ?> 419 420 <?php 421 // Output the comment moderation feedback if needed. 422 $this->awaiting_moderation_text( $comment ); 423 424 // Output the comment approval notification form if needed. 425 echo $this->comment_approval_notification_form( $comment, true ); 426 ?> 335 427 336 428 <div class="comment-meta commentmetadata"> 337 429 <?php … … 401 493 402 494 $commenter = wp_get_current_commenter(); 403 495 $show_pending_links = ! empty( $commenter['comment_author'] ); 404 405 if ( $commenter['comment_author_email'] ) {406 $moderation_note = __( 'Your comment is awaiting moderation.' );407 } else {408 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' );409 }410 496 ?> 411 497 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>> 412 498 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> … … 450 536 ?> 451 537 </div><!-- .comment-metadata --> 452 538 453 <?php if ( '0' == $comment->comment_approved ) : ?> 454 <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em> 455 <?php endif; ?> 539 <?php 540 // Output the comment moderation feedback if needed. 541 $this->awaiting_moderation_text( $comment ); 542 543 // Output the comment approval notification form if needed. 544 echo $this->comment_approval_notification_form( $comment, true ); 545 ?> 456 546 </footer><!-- .comment-meta --> 457 547 458 548 <div class="comment-content"> -
src/wp-includes/comment.php
2349 2349 } 2350 2350 2351 2351 /** 2352 * Notifies the comment author when their comment gets approved. 2353 * 2354 * This notification is only sent once when the comment status 2355 * changes from unapproved to approved. 2356 * 2357 * @since 5.7.0 2358 * 2359 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. 2360 * @return bool Whether the email was sent successfully. 2361 */ 2362 function wp_new_comment_notify_comment_author( $comment_id ) { 2363 $comment = get_comment( $comment_id ); 2364 2365 if ( ! $comment ) { 2366 return false; 2367 } 2368 2369 $post = get_post( $comment->comment_post_ID ); 2370 2371 if ( ! $post ) { 2372 return false; 2373 } 2374 2375 // Make sure the comment author can be notified by email. 2376 if ( empty( $comment->comment_author_email ) ) { 2377 return false; 2378 } 2379 2380 if ( ! get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) { 2381 return false; 2382 } 2383 2384 /** 2385 * The blogname option is escaped with esc_html when 2386 * saved into the database, we need to reverse this for 2387 * the plain text area of the email. 2388 */ 2389 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 2390 2391 $subject = sprintf( 2392 /* translators: 1: blog name, 2: post title */ 2393 __( '[%1$s] Your comment on "%2$s" has been approved' ), 2394 $blogname, 2395 $post->post_title 2396 ); 2397 2398 if ( ! empty( $comment->comment_author ) ) { 2399 $notify_message = sprintf( 2400 /* translators: 1: comment author's name */ 2401 __( 'Howdy %s,' ), 2402 $comment->comment_author 2403 ) . "\r\n\r\n"; 2404 } else { 2405 $notify_message = __( 'Howdy,' ) . "\r\n\r\n"; 2406 } 2407 2408 $notify_message .= sprintf( 2409 /* translators: 1: post title */ 2410 __( 'Your comment on "%s" has been approved.' ), 2411 $post->post_title 2412 ) . "\r\n\r\n"; 2413 2414 $notify_message .= sprintf( 2415 /* translators: 1: comment permalink */ 2416 __( 'View comment: %s' ), 2417 get_comment_link( $comment ) 2418 ) . "\r\n"; 2419 2420 $email = array( 2421 'to' => $comment->comment_author_email, 2422 'subject' => $subject, 2423 'message' => $notify_message, 2424 'headers' => '', 2425 ); 2426 2427 /** 2428 * Filters the contents of the email sent to notify a comment author that their comment was approved. 2429 * 2430 * Content should be formatted for transmission via wp_mail(). 2431 * 2432 * @since 5.7.0 2433 * 2434 * @param array $email { 2435 * Used to build wp_mail(). 2436 * 2437 * @type string $to The email address of the comment author. 2438 * @type string $subject The subject of the email. 2439 * @type string $message The content of the email. 2440 * @type string $headers Headers. 2441 * } 2442 * @param WP_Comment $comment Comment object. 2443 */ 2444 $email = apply_filters( 'comment_approval_notification', $email, $comment ); 2445 2446 $sent = wp_mail( 2447 $email['to'], 2448 wp_specialchars_decode( $email['subject'] ), 2449 $email['message'], 2450 $email['headers'] 2451 ); 2452 2453 // Delete the opt-in now the notification has been sent. 2454 delete_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin' ); 2455 2456 return $sent; 2457 } 2458 2459 /** 2352 2460 * Sets the status of a comment. 2353 2461 * 2354 2462 * The {@see 'wp_set_comment_status'} action is called after the comment is handled. -
src/wp-includes/default-filters.php
467 467 add_action( 'after_password_reset', 'wp_password_change_notification' ); 468 468 add_action( 'register_new_user', 'wp_send_new_user_notifications' ); 469 469 add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 ); 470 add_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' ); 470 471 471 472 // REST API actions. 472 473 add_action( 'init', 'rest_api_init' ); -
tests/phpunit/tests/comment.php
555 555 } 556 556 557 557 /** 558 * @ticket 33717 559 */ 560 public function test_wp_new_comment_notify_comment_author_once_only() { 561 $c = self::factory()->comment->create( 562 array( 563 'comment_post_ID' => self::$post_id, 564 'comment_approved' => '0', 565 'comment_author_email' => 'foo@bar.mail', 566 ) 567 ); 568 569 // The user subscribed to receive an email once comment is approved. 570 update_comment_meta( $c, '_wp_comment_author_notification_optin', true ); 571 572 // For the purpose of the test we are removing this hook to directly use the function to notify the comment author. 573 remove_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' ); 574 575 // Approve the comment. 576 wp_set_comment_status( $c, 'approve' ); 577 578 $sent = wp_new_comment_notify_comment_author( $c ); 579 $resent = wp_new_comment_notify_comment_author( $c ); 580 581 $this->assertTrue( $sent ); 582 $this->assertFalse( $resent ); 583 } 584 585 /** 586 * @ticket 33717 587 */ 588 public function test_wp_new_comment_notify_comment_author_has_not_opted_in() { 589 $c = self::factory()->comment->create( 590 array( 591 'comment_post_ID' => self::$post_id, 592 'comment_approved' => '0', 593 'comment_author_email' => 'bat@man.mail', 594 ) 595 ); 596 597 // For the purpose of the test we are removing this hook to directly use the function to notify the comment author. 598 remove_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' ); 599 600 // Approve the comment. 601 wp_set_comment_status( $c, 'approve' ); 602 603 $sent = wp_new_comment_notify_comment_author( $c ); 604 605 // The user hasn't subscribed to receive an email, no email should be sent. 606 $this->assertFalse( $sent ); 607 } 608 609 /** 558 610 * @ticket 12431 559 611 */ 560 612 public function test_wp_new_comment_with_meta() {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)