I have what I feel like is a unique situation here and have been pouring over how to do this for days.
First off I found some pretty useful threads here and around the web like
How to add a custom notifcation
I have a custom post type called "collaborations" and I have been developing a front end form and php class to handle the form. Pretty much the form allows registered users to create a post from the front end and save it as draft or publish it. I am also using the Co Authors extension so on the front end form users can select various members to collaborate with. All of this is working fine.
What I want to do is tap in to the default buddypress behavior so when someone shares a (draft) post to collaborate that it will notify each user in their notifications tab. I have a function to send them an email but want to also have it on the site under their notifications.
I am attaching my class here for reference: http://pastebin.com/HWNM8dHq
But here is my question. I see how to ADD a notification but how do I configure what to say and the fallbacks? I am assuming I need a function with my own component_action?
**************************************************
Buddypress Notifications - Custom
**************************************************/
function add_collaboration_notification($activity, $subject, $message, $content, $user_id) {
//bp_notifications_add_notification
if ( bp_is_active( 'notifications' ) ) {
bp_notifications_add_notification( array(
'user_id' => $user_id,
'item_id' => $activity->id,
'secondary_item_id' => $activity->user_id,
'component_name' => buddypress()->activity->id,
'component_action' => 'new_at_mention',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
) );
}
}
//Hook into BP action or possibly save_post action?
function function_format_notification() {
//use $component_action defined above
//look at friends_format_notifications() in bp-friends.php
}
//Hook in core components notification system
The end result should be each time a post is saved and my classes public function publish() or send_message runs that it also shows those users a notification. Here is that snippet from my class:
public function send_message($subject, $message) {
if($this->co_authors) {
//verify post is not a revision
if( wp_is_post_revision($this->post_id) )
{
return;
}
$recipients_object = array();
foreach($this->co_authors as $recipientID){
$user_info = get_userdata($recipientID);
$email = $user_info->user_email;
$recipients_object[] = $email;
}
$to = implode(", ", $recipients_object);
// Send it!
wp_mail( $to, $subject, $message );
}
//do_action('send_message'); Create action to plug in to add_notifications?
}