File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -2466,10 +2466,24 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
24662466 */
24672467function 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 *
You can’t perform that action at this time.
0 commit comments