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 ){
ob_start();
//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';
include('email_header.php');
?>
<p>
<?php echo $comment->comment_type; ?> <?php echo $post->post_type; ?> Notification Message in here.<br />
<?php echo $comment->comment_content; ?>
</p>
<?php
include('email_footer.php');
$message = ob_get_contents();
//clear buffer
ob_end_clean();
//ob_start();
//wp_mail( $author->user_email, $email_subject, $message );
//ob_end_clean();
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.