duansha8115 2015-07-20 18:57
浏览 39

Post Post上的自定义Buddypress通知

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?

        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致