• Hello,

    I’ve noticed that when comments are created using the WP API that notification emails are not sent out to the author or moderators.

    If I add the comment via the admin interface, it is working fine. On debugging, I noticed that the filter ‘comment_post’ is not being called when inserted via the API.

    For now, I found a workaround as follows:

    function mytheme_comment_inserted($comment_id, $comment_object) {
      wp_notify_postauthor( $comment_id );
    }
    
    add_action('wp_insert_comment','mytheme_comment_inserted');
    

    But I’m wondering if this is desired behaviour or in fact if this should be reported as a bug?

    Thanks!

    Chris

    • This topic was modified 7 years, 12 months ago by stickypixel.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You mean the WP REST API, right? I was not involved in the design of the REST API, so I’m only guessing, but I’m fairly sure not using wp_new_comment() (which fires “comment_post”) was an intentional choice. Doing so would have actually been simpler, but they chose to only implement part what the function does. The REST API is thought of as a somewhat low level interface. Individual requests are rather primitive in nature. It’s up to the app dev to string these together into a meaningful user experience.

    wp_new_comment() and “comment_post” are more of a high level function that itself strings together lower level calls. As a lower level API, it’s up to the dev to implement what is needed, just as you did by hooking “wp_insert_comment”. Better this than automatically doing several things as a high level function would do. It’s much harder to remove automatic “features” than it is to add them in when needed.

    Thread Starter stickypixel

    (@stickypixel)

    Thanks – Exactly, yeah, the REST API. It makes sense I suppose – any idea if there’s any specific documentation relating to this? (Or is it more or a ‘this is the concept, if you see an issue like this, it’s probably intentional’.)

    Moderator bcworkz

    (@bcworkz)

    Unfortunately, the official REST documentation is very sparse at this point. There’s nothing specific addressing this either way. As I said, I’m only guessing, based on my own experience and what I’ve seen by examining the source code. I could be wrong. Do not assume anything you see is intentional behavior. If you search through the Trac bug tracking system, you will find plenty of unintentional behaviors, though they tend to be obscure, fringe cases.

    If you feel this is really an unintentional bug, go ahead and file a bug report. Do ensure someone hasn’t already done so first. You’ll then get a more official response regarding this.

    Thread Starter stickypixel

    (@stickypixel)

    Okay – I searched the Trac, couldn’t see anything in there that looked related so submitted a ticket there. Thanks for the help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP API, Comments Not Sending Notifications’ is closed to new replies.