1

I'm trying to find the code to insert in my Comments.php to add the functionality of "Follow-up Comments Notification" but I can't find it.

I can't use a plug-in because it's for a theme that I'm starting to develop for a client and he doesn't want to use plug-ins. I know there has to be a way because I've been told that some themes come with that feature but I don't seem to understand where that piece of code is.

Any help or suggestions will be greatly appreciated.

Cheers

1 Answer 1

3

It's quite simple, just hook a function on comment_post in which you check if the comment is a reply and send the author of the parent comment an email:

add_action('comment_post', 'notify_author_of_reply', 10, 2);

function notify_author_of_reply($comment_id, $approved){
  if($approved){
    $comment = get_comment($comment_id);
    if($comment->comment_parent){
      $parent_comment = get_comment($comment->comment_parent);
      wp_mail($parent_comment->comment_author_email, 'Hello', 'Dude you got a reply...');
    }
  }
}

For handling unsubscriptions, you can add store emails of people who don't want notifications inside an option (and check if $parent_comment->comment_author_email is not within that list in the function above).

6
  • Wow! One Trick Pony, thanks for your reply. I'll jump to my theme and test your code. :-)
    – martin
    Commented Dec 15, 2011 at 19:02
  • I was finally able to test this code and IT WORKS! Thanks again for your help! :-) It took me some time because I was using and old Comments.php and it didn't have a "Reply" function, so I had to change that first. I have a new question, is there a way to get a link to the Post of the comment in the body of the Email Notification?
    – martin
    Commented Dec 20, 2011 at 5:04
  • yes, use get_permalink($comment->comment_post_ID); Commented Dec 23, 2011 at 12:23
  • I'm unable to make it work, but only because I don't know where to place that extra line of code. Could you be more specific? I have no knowledge of PHP so I'm doing it in the "Trial and Error" way but of all the combinations I've tried so far I can't get the link to show up :( Thanks, again!
    – martin
    Commented Dec 27, 2011 at 7:57
  • Ok, I tried placing that code everywhere with no luck. I took a look at the wp_mail function and I was able to change the name and email of the "Sender" using $headers BUT I still can't get the link of the Post to the body of my notification email. Any help is appreciated! Thanks
    – martin
    Commented Dec 29, 2011 at 6:29

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.