Skip to content

Commit ebeed78

Browse files
Notes: refine post author notifications.
Code maintenance follow up to r61179. Move `wp_new_comment_via_rest_notify_postauthor` callback from REST API Comments controller to comment.php. Add default to `wp_notes_notify` for multisite compatibility. Props adamsilverstein, justlevine, mukesh27, mamaduka, peterwilsoncc, desros. See #64204. git-svn-id: https://develop.svn.wordpress.org/trunk@61199 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e1de7e9 commit ebeed78

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/wp-admin/includes/schema.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ function populate_options( array $options = array() ) {
563563

564564
// 6.9.0
565565
'wp_notes_notify' => 1,
566-
567566
);
568567

569568
// 3.3.0

src/wp-admin/options-discussion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<?php _e( 'A comment is held for moderation' ); ?> </label>
163163
<br />
164164
<label for="wp_notes_notify">
165-
<input name="wp_notes_notify" type="checkbox" id="wp_notes_notify" value="1" <?php checked( '1', get_option( 'wp_notes_notify' ) ); ?> />
165+
<input name="wp_notes_notify" type="checkbox" id="wp_notes_notify" value="1" <?php checked( '1', get_option( 'wp_notes_notify', 1 ) ); ?> />
166166
<?php _e( 'Anyone posts a note' ); ?> </label>
167167

168168
</fieldset></td>

src/wp-includes/comment.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
24272427
$comment = get_comment( $comment_id );
24282428
$is_note = ( $comment && 'note' === $comment->comment_type );
24292429

2430-
$maybe_notify = $is_note ? get_option( 'wp_notes_notify' ) : get_option( 'comments_notify' );
2430+
$maybe_notify = $is_note ? get_option( 'wp_notes_notify', 1 ) : get_option( 'comments_notify' );
24312431

24322432
/**
24332433
* Filters whether to send the post author new comment notification emails,
@@ -2458,6 +2458,19 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
24582458
return wp_notify_postauthor( $comment_id );
24592459
}
24602460

2461+
/**
2462+
* Send a notification to the post author when a new note is added via the REST API.
2463+
*
2464+
* @since 6.9.0
2465+
*
2466+
* @param WP_Comment $comment The comment object.
2467+
*/
2468+
function wp_new_comment_via_rest_notify_postauthor( $comment ) {
2469+
if ( $comment instanceof WP_Comment && 'note' === $comment->comment_type ) {
2470+
wp_new_comment_notify_postauthor( (int) $comment->comment_ID );
2471+
}
2472+
}
2473+
24612474
/**
24622475
* Sets the status of a comment.
24632476
*

src/wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@
522522
// Email notifications.
523523
add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
524524
add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
525-
add_action( 'rest_insert_comment', array( 'WP_REST_Comments_Controller', 'wp_new_comment_via_rest_notify_postauthor' ) );
525+
add_action( 'rest_insert_comment', 'wp_new_comment_via_rest_notify_postauthor' );
526526
add_action( 'after_password_reset', 'wp_password_change_notification' );
527527
add_action( 'register_new_user', 'wp_send_new_user_notifications' );
528528
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@ public function __construct() {
3636
$this->meta = new WP_REST_Comment_Meta_Fields();
3737
}
3838

39-
/**
40-
* Send a notification to the post author when a new note is added via the REST API.
41-
*
42-
* @since 6.9.0
43-
*
44-
* @param WP_Comment $comment The comment object.
45-
*/
46-
public static function wp_new_comment_via_rest_notify_postauthor( $comment ) {
47-
if ( 'note' === $comment->comment_type ) {
48-
wp_new_comment_notify_postauthor( $comment->comment_ID );
49-
}
50-
}
5139
/**
5240
* Registers the routes for comments.
5341
*

0 commit comments

Comments
 (0)