I am working on a small project for my family to share info, recipes etc. And I added a "@" mention feature. Now that the mention feature works I need to notify the user they were mentioned.

I thought that the WP comments already kind of do this and since my family would be getting comment notifications via email I decided to insert a comment when a mention happens into the DB. It uses comment type "mention" and set the comment_post_ID to 0 and add a bit of comment meta data to store the user who was mentioned and the one that did the mentioning. It works pretty well.

I can send an email using wp_mail no problem but since the "mentions" are "comments" I wanted to use anything WP already had to offer. I found two methods that may help: wp_notify_postauthor and comment_post.

Using comment_post worked but it only sent out for normal comments.

I tried filtering and hooking into wp_notify_postauthor with no luck. Here's what I have for filtering the wp_notify_postauthor:

add_filter('wp_notify_postauthor', 'smile_wp_send_member_notification', 10, 2);

function smile_wp_send_member_notification( $comment_id, $comment_type ){


    //get comment info
    $comment = get_comment( $comment_id );
    $from_user = $comment->user_id;
    $post = get_post( $comment->comment_post_ID );
    $author = get_userdata( $post->post_author );

    //set email subject
    $email_subject = $comment->comment_type.' notification title';


        <?php echo $comment->comment_type; ?> <?php echo $post->post_type; ?> Notification Message in here.<br />
        <?php echo $comment->comment_content; ?>



    $message = ob_get_contents();

    //clear buffer

    //wp_mail( $author->user_email, $email_subject, $message );

    return $message;

}//end smile_wp_send_member_notification

I though wp_notify_postauthor was pluggable but maybe not. If there is another way to perform this or get the email notification to send please let me know.

2 Answers 2


There is no wp_notify_postauthor filter, a pluggable function is one you override with your own function:

if( ! function_exists('wp_notify_postauthor') ) {
    function wp_notify_postauthor( $comment_id, $comment_type = '' ) {
        // your own wp_notify_postauthor code

I suggest looking at the function in source to see what it does.

  • Just did as you suggested and still no luck on my comment types. I even copied the entire wp_notify_postauthor method from pluggable.php to my plugin file and added an elseif for one of my comment types and nothing happened. The description of the method indicates that it accpets "comment", "trackback" and "pingback' as comment types, could this be my problem? Maybe since my comment types are not default values it won't recognize them?
    – dkmojo
    Commented Nov 19, 2012 at 15:35

Turns out the notification email is only sent if the comment_post_ID is not 0. I altered my notification comments code to set the comment_post_ID and now it all works!

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.