Skip to content

Commit cbfef88

Browse files
Queue note notifications with cron
Note: requires cron be active for notifications to work
1 parent 0daba4c commit cbfef88

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/wp-includes/comment.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,10 +2466,24 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
24662466
*/
24672467
function wp_new_comment_via_rest_notify_postauthor( $comment ) {
24682468
if ( 'note' === $comment->comment_type ) {
2469-
wp_new_comment_notify_postauthor( $comment->comment_ID );
2469+
// Queue up the email notification as a cron callback. The second parameter ensures each callback is executed.
2470+
wp_schedule_single_event( time(), 'wp_new_comment_via_rest_notify_postauthor', array( $comment->comment_ID, time() ) );
24702471
}
24712472
}
24722473

2474+
/**
2475+
* Cron callback to send an author email notifcation, keeping the action asynchronous.
2476+
*/
2477+
function wp_new_comment_via_rest_notify_postauthor_cron( $comment_id ) {
2478+
$comment = get_comment( $comment_id );
2479+
if ( $comment ) {
2480+
wp_new_comment_notify_postauthor( $comment_id );
2481+
}
2482+
}
2483+
2484+
// Add a custom hook for the note notification cron job.
2485+
add_action( 'wp_new_comment_via_rest_notify_postauthor', 'wp_new_comment_via_rest_notify_postauthor_cron' );
2486+
24732487
/**
24742488
* Sets the status of a comment.
24752489
*

0 commit comments

Comments
 (0)