When I submit a comment on the WordPress website, it sends me a notification email.
but when I submit a comment through REST API, WordPress doesn't send me a notification email.
What should I do to make WordPress send a notification email when I submit a comment with REST API?

  • Never really used the wordpress api but here's what I would do. If the response was successful (don't know how wordpress returns it) use wp_mail to send yourself or the admin (if it's not you) an email Commented May 9, 2021 at 14:14

1 Answer 1


Here's an untested suggestion for the REST API case:

add_action( 'rest_after_insert_comment', 'wp_new_comment_notify_moderator' );

emulating the existing:

add_action( 'comment_post', 'wp_new_comment_notify_moderator' );

Note the different callback inputs between actions and that we use that get_comment() should handle both comment ID or comment object as an input.

  • When I use "rest_after_insert_comment" this error appears: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at example.com/wp-json/wp/v2/comments?post=6194. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). "
    – Sadegh
    Commented May 26, 2021 at 16:16
  • That sounds normal for cross-origin requests, not sure how that could be related to the hooking.
    – birgire
    Commented Jun 1, 2021 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.