/**
  *
  * @param int $post_id
  * @param int $post_author_id
  * @param int $user_id
  *
  * @return int|bool  notification id on success or false
  */
 function add_notification($post_id, $post_author_id, $user_id)
 {
     global $rtmedia;
     $args_add_noification = array('item_id' => $post_id, 'user_id' => $post_author_id, 'component_name' => $this->component_id, 'component_action' => $this->component_action . $post_id, 'secondary_item_id' => $user_id, 'date_notified' => bp_core_current_time());
     if (isset($rtmedia->options['buddypress_enableNotification']) && 0 !== intval($rtmedia->options['buddypress_enableNotification'])) {
         return bp_notifications_add_notification($args_add_noification);
     }
     return false;
 }
function bp_course_add_notification($args = '')
{
    global $bp;
    if (!bp_is_active('notifications') || !function_exists('bp_notifications_add_notification')) {
        return;
    }
    $defaults = array('user_id' => $bp->loggedin_user->id, 'item_id' => false, 'secondary_item_id' => false, 'component_name' => 'course', 'component_action' => '', 'date_notified' => bp_core_current_time(), 'is_new' => 1);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    return bp_notifications_add_notification(array('user_id' => $user_id, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'component_name' => $component_name, 'component_action' => $component_action, 'date_notified' => $date_notified, 'is_new' => $is_new));
}
/**
 * Catch booking saves and add a BP notification.
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_add_booking_notification($result, $EM_Booking)
{
    global $bp;
    if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'pending_booking';
    } elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'confirmed_booking';
    } elseif ($EM_Booking->get_status() == 3) {
        $action = 'cancelled_booking';
    }
    if (!empty($action) && !(get_option('dbem_bookings_registration_disable') && get_option('dbem_bookings_registration_user') == $EM_Booking->get_event()->get_contact()->ID)) {
        bp_notifications_add_notification(array('item_id' => $EM_Booking->booking_id, 'secondary_item_id' => $EM_Booking->event_id, 'user_id' => $EM_Booking->get_event()->get_contact()->ID, 'component_name' => 'events', 'component_action' => $action));
    }
    return $result;
}
/**
 * Adds notification when a user follows another user.
 *
 * @since 1.2.1
 *
 * @param object $follow The BP_Follow object.
 */
function bp_follow_notifications_add_on_follow(BP_Follow $follow)
{
    // Add a screen notification
    //
    // BP 1.9+
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('item_id' => $follow->follower_id, 'user_id' => $follow->leader_id, 'component_name' => buddypress()->follow->id, 'component_action' => 'new_follow'));
        // BP < 1.9 - add notifications the old way
    } elseif (!class_exists('BP_Core_Login_Widget')) {
        global $bp;
        bp_core_add_notification($follow->follower_id, $follow->leader_id, $bp->follow->id, 'new_follow');
    }
    // Add an email notification
    bp_follow_new_follow_email_notification(array('leader_id' => $follow->leader_id, 'follower_id' => $follow->follower_id));
}
/**
 * Add a notification for a specific user, from a specific component
 *
 * @deprecated Deprecated since BuddyPress 1.9.0. Use
 *  bp_notifications_add_notification() instead.
 *
 * @since BuddyPress (1.0)
 * @param string $item_id
 * @param int $user_id
 * @param string $component_name
 * @param string $component_action
 * @param string $secondary_item_id
 * @param string $date_notified
 * @param int $is_new
 * @return boolean True on success, false on fail
 */
function bp_core_add_notification($item_id, $user_id, $component_name, $component_action, $secondary_item_id = 0, $date_notified = false, $is_new = 1)
{
    // Bail if notifications is not active
    if (!bp_is_active('notifications')) {
        return false;
    }
    // Trigger the deprecated function notice
    _deprecated_function(__FUNCTION__, '1.9', 'bp_notifications_add_notification()');
    // Notifications must always have a time
    if (false === $date_notified) {
        $date_notified = bp_core_current_time();
    }
    // Add the notification
    return bp_notifications_add_notification(array('item_id' => $item_id, 'user_id' => $user_id, 'component_name' => $component_name, 'component_action' => $component_action, 'secondary_item_id' => $secondary_item_id, 'date_notified' => $date_notified, 'is_new' => $is_new));
}
Exemple #6
0
function _likebtn_bp_notifications_add_notification($entity_name, $entity_id, $voter_id, $action)
{
    if (!in_array($action, array('like', 'dislike'))) {
        $action = 'like';
    }
    // No notifications from Anonymous
    if (!$voter_id) {
        return false;
    }
    $author_id = _likebtn_get_author_id($entity_name, $entity_id);
    if (!$author_id || $author_id == $voter_id) {
        return false;
    }
    bp_notifications_add_notification(array('user_id' => $author_id, 'item_id' => $entity_id, 'secondary_item_id' => $voter_id, 'component_name' => LIKEBTN_BP_COMPONENT_NAME, 'component_action' => 'likebtn_' . $entity_name . '_' . $action, 'date_notified' => bp_core_current_time(), 'is_new' => 1));
    // bp_notifications_add_meta($notification_id, 'entity_name', $entity_name, true)
}
Exemple #7
0
 public function add_new_comment_notification($comment)
 {
     $comment = (object) $comment;
     if (bp_is_active('notifications')) {
         global $bp;
         $post = get_post($comment->comment_post_ID);
         if ($post->post_type == 'answer') {
             $participants = ap_get_parti(false, false, $comment->comment_post_ID);
         }
         if ($post->post_type == 'question') {
             $participants = ap_get_parti($comment->comment_post_ID);
         }
         $notification_args = array('item_id' => $comment->comment_ID, 'secondary_item_id' => $comment->user_id, 'component_name' => $bp->ap_notifier->id, 'component_action' => 'new_comment_' . $post->ID, 'date_notified' => bp_core_current_time(), 'is_new' => 1);
         if (!empty($participants) && is_array($participants)) {
             foreach ($participants as $p) {
                 if ($p->apmeta_userid != $comment->user_id) {
                     $notification_args['user_id'] = $p->apmeta_userid;
                     bp_notifications_add_notification($notification_args);
                 }
             }
         }
     }
 }
Exemple #8
0
function create_discussion_child()
{
    $kt = $_POST['kt'];
    $user_receiver = $_POST["user_receiver"];
    $noidung = $_POST["cdcontent"];
    $tieude = $_POST["cdtitle"];
    $courseid = $_POST["cdcourseid"];
    $listauthor = wp_get_current_user();
    $author = $listauthor->display_name;
    $mail_author = $listauthor->user_mail;
    $parent_comment = $_POST["parent_comment"];
    $student_id_array = lay_danh_sach_hoc_vien_khoa_hoc($courseid);
    $data = array('comment_post_ID' => $courseid, 'comment_author' => $author, 'comment_content' => $noidung, 'user_id' => get_current_user_id(), 'comment_author_mail' => $mail_author, 'comment_parent' => $parent_comment);
    $getid = wp_insert_comment($data);
    update_comment_meta($getid, 'review_title', $tieude);
    update_comment_meta($getid, 'title_discussion', $tieude);
    //    Lấy id củ của bảng messages và cộng thêm 1 để tạo thành Thread_id
    global $wpdb;
    $old_id = 0;
    $old_id_message = $wpdb->get_results('SELECT id FROM itclass_songle_bp_messages_messages ORDER BY id DESC LIMIT 1 ');
    foreach ($old_id_message as $item) {
        $old_id = $item->id + 1;
    }
    //    Thêm dữ liệu vào bảng messages
    $user = get_userdata(get_current_user_id());
    //$user->user_nicename
    $time_messages = current_time('mysql');
    $messsage_title = $user->user_nicename . ' đã bình luận tại khóa học <a href=\\"' . get_permalink($courseid) . '\\"><b>' . get_the_title($courseid) . '</b></a>';
    $wpdb->get_results('INSERT INTO itclass_songle_bp_messages_messages (thread_id,sender_id,subject,message,date_sent) VALUES ("' . $old_id . '","' . get_current_user_id() . '","' . $messsage_title . '","' . $noidung . '","' . $time_messages . '")');
    if (!empty($student_id_array)) {
        foreach ($student_id_array as $student_id) {
            if ($student_id != get_current_user_id()) {
                //    Thêm hành động bình luận
                $datacomment = array('action' => 'Học viên đã bình luận tại khóa học ' . get_the_title($courseid), 'user_id' => get_current_user_id(), 'component' => 'comments_unit', 'type' => 'activity_update', 'content' => $noidung, 'primary_link' => get_permalink($courseid), 'item_id' => $courseid, 'secondary_item_id' => $student_id);
                $activity_id = bp_activity_add($datacomment);
                //    Thêm thông báo
                $datanotify = array('user_id' => $student_id, 'item_id' => $getid, 'secondary_item_id' => get_current_user_id(), 'component' => 'comments', 'component_name' => 'messages', 'is_new' => 1, 'component_action' => 'new_message');
                bp_notifications_add_notification($datanotify);
                $wpdb->get_results('INSERT INTO itclass_songle_bp_messages_recipients (user_id,thread_id,unread_count,sender_only,is_deleted) VALUES ("' . $student_id . '","' . $old_id . '",1,0,0)');
            }
        }
    }
    //    echo "<div class='result'>";
    $noidungsau = get_comment_text($getid);
    echo '<div class="result">';
    echo '<li>';
    echo '<div class="item-discustion child">';
    echo '<div class="cmtauthor child row">';
    echo '<div class="HieuChinh-ds child">';
    echo '<div class="Xoads"><i class="icon-x"></i> </div>';
    echo '<div class="Suads"><i class="icon-edit-pen-1"></i> </div>';
    echo '<input class="id-comment-ds" type="hidden" value="' . $getid . '">';
    echo '</div>';
    echo '<div class="col-md-1">';
    echo get_avatar(get_current_user_id(), 32);
    echo '</div>';
    echo '<div class="col-md-10">';
    echo '<span class="authorname">' . $author . '</span>' . '<span style="font-style:italic"> vừa xong </span>';
    echo '</div></div><br> ';
    echo '<div data-id="' . $getid . '" data-course-id="' . $courseid . '" class="NoiDungCMTUser row">';
    echo '<div class="col-md-1"></div>';
    echo '<div class="col-md-10">';
    echo '<div class="comment-title-user">' . get_comment_meta($getid, 'title_discussion', true) . ' </div>';
    echo '<div class="comment-content-user">' . $noidungsau . '</div>';
    echo '</div></div>';
    echo '<div class="edit_content_editor_child"></div>';
    echo '</div>';
    echo '</li>';
    die;
}
 public function notify($user_id, $comment)
 {
     $comment_id = $comment->comment_ID;
     bp_notifications_add_notification(array('item_id' => $comment_id, 'user_id' => $user_id, 'component_name' => $this->id, 'component_action' => 'new_blog_comment_' . $comment_id));
     $this->mark_notified($comment_id);
 }
/**
 * Notify a member when their nicename is mentioned in an activity stream item.
 *
 * Hooked to the 'bp_activity_sent_mention_email' action, we piggy back off the
 * existing email code for now, since it does the heavy lifting for us. In the
 * future when we separate emails from Notifications, this will need its own
 * 'bp_activity_at_name_send_emails' equivalent helper function.
 *
 * @since 1.9.0
 *
 * @param object $activity           Activity object.
 * @param string $subject (not used) Notification subject.
 * @param string $message (not used) Notification message.
 * @param string $content (not used) Notification content.
 * @param int    $receiver_user_id   ID of user receiving notification.
 */
function bp_activity_at_mention_add_notification($activity, $subject, $message, $content, $receiver_user_id)
{
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('user_id' => $receiver_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));
    }
}
/**
 * Notify a member they have been invited to a group.
 *
 * @since 1.0.0
 *
 * @param BP_Groups_Group  $group           Group object.
 * @param BP_Groups_Member $member          Member object.
 * @param int              $inviter_user_id ID of the user who sent the invite.
 */
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // Bail if member has already been invited.
    if (!empty($member->invite_sent)) {
        return;
    }
    // @todo $inviter_ud may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $invited_user_id = $member->user_id;
    // Trigger a BuddyPress Notification.
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('user_id' => $invited_user_id, 'item_id' => $group->id, 'component_name' => buddypress()->groups->id, 'component_action' => 'group_invite'));
    }
    // Bail if member opted out of receiving this email.
    if ('no' === bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
        return;
    }
    $invited_link = bp_core_get_user_domain($invited_user_id) . bp_get_groups_slug();
    $unsubscribe_args = array('user_id' => $invited_user_id, 'notification_type' => 'groups-invitation');
    $args = array('tokens' => array('group' => $group, 'group.url' => bp_get_group_permalink($group), 'group.name' => $group->name, 'inviter.name' => bp_core_get_userlink($inviter_user_id, true, false, true), 'inviter.url' => bp_core_get_user_domain($inviter_user_id), 'inviter.id' => $inviter_user_id, 'invites.url' => esc_url($invited_link . '/invites/'), 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args))));
    bp_send_email('groups-invitation', (int) $invited_user_id, $args);
}
Exemple #12
0
/**
 * Hooked into the new reply function, this notification action is responsible
 * for notifying topic and hierarchical reply authors of topic replies.
 *
 * @since 2.5.0 bbPress (r5156)
 *
 * @param int $reply_id
 * @param int $topic_id
 * @param int $forum_id (not used)
 * @param array $anonymous_data (not used)
 * @param int $author_id
 * @param bool $is_edit Used to bail if this gets hooked to an edit action
 * @param int $reply_to
 */
function bbp_buddypress_add_notification($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0)
{
    // Bail if somehow this is hooked to an edit action
    if (!empty($is_edit)) {
        return;
    }
    // Get autohr information
    $topic_author_id = bbp_get_topic_author_id($topic_id);
    $secondary_item_id = $author_id;
    // Hierarchical replies
    if (!empty($reply_to)) {
        $reply_to_item_id = bbp_get_topic_author_id($reply_to);
    }
    // Get some reply information
    $args = array('user_id' => $topic_author_id, 'item_id' => $topic_id, 'component_name' => bbp_get_component_name(), 'component_action' => 'bbp_new_reply', 'date_notified' => get_post($reply_id)->post_date);
    // Notify the topic author if not the current reply author
    if ($author_id !== $topic_author_id) {
        $args['secondary_item_id'] = $secondary_item_id;
        bp_notifications_add_notification($args);
    }
    // Notify the immediate reply author if not the current reply author
    if (!empty($reply_to) && $author_id !== $reply_to_item_id) {
        $args['secondary_item_id'] = $reply_to_item_id;
        bp_notifications_add_notification($args);
    }
}
Exemple #13
0
 /**
  * Save or update a new event
  * @version 2.0
  */
 function save_event($post_id, $post = '')
 {
     // Don't do anything if it's not an event
     if ('event' != $post->post_type) {
         return;
     }
     // Verify the nonce before proceeding.
     if (!isset($_POST['event-details-box']) || !wp_verify_nonce($_POST['event-details-box'], basename(__FILE__))) {
         return $post_id;
     }
     /* -----------------------------------
     			SAVE EVENT TIME 
     		------------------------------------*/
     // Retrieve the event time
     $event_time = date('Y-m-d H:i:s', strtotime($_POST['event-time']));
     $prior_time = $post->post_date;
     // Update the post object
     $post->post_date = $event_time;
     remove_action('save_post', array($this, 'save_event'));
     wp_update_post($post);
     add_action('save_post', array($this, 'save_event'), 10, 2);
     /* -----------------------------------
     			SAVE META INFORMATION 
     		------------------------------------ */
     // Define the meta to look for
     $meta = array('event_duration' => $_POST['event-duration'], 'event_capacity' => $_POST['event-capacity'], 'event_rsvp' => $_POST['event-rsvp'], 'event_role' => $_POST['event-role']);
     // Loop through each meta, saving it to the database
     foreach ($meta as $meta_key => $new_meta_value) {
         // Get the meta value of the custom field key.
         $meta_value = get_post_meta($post_id, $meta_key, true);
         // If there is no new meta value but an old value exists, delete it.
         if (current_user_can('delete_post_meta', $post_id, $meta_key) && '' == $new_meta_value && $meta_value) {
             delete_post_meta($post_id, $meta_key, $meta_value);
         } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) {
             add_post_meta($post_id, $meta_key, $new_meta_value, true);
         } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $new_meta_value && $new_meta_value != $meta_value) {
             update_post_meta($post_id, $meta_key, $new_meta_value);
         }
     }
     // Delete the RSVP meta if the date has changed
     if ($event_time != $prior_time) {
         delete_post_meta($post_id, 'event_rsvps');
     }
     /* -----------------------------------
     			BUDDYPRESS NOTIFICATION
     		------------------------------------ */
     // Get event data
     global $bp, $wpdb;
     if (!$user_id) {
         $user_id = $post->post_author;
     }
     // Figure out which calendars this event belongs to
     $calendars = wp_get_post_terms($post_id, 'calendar');
     $group_slugs = array();
     // For each calendar, check if it's a group calendar
     foreach ($calendars as $calendar) {
         if (is_group_calendar($calendar->term_id)) {
             $groups[] = $calendar;
         }
     }
     // If this event does not belong to a group, we can stop here
     if (empty($groups)) {
         return $post_id;
     }
     // Only register notifications for future or published events
     if (!in_array($post->post_status, array('publish', 'future'))) {
         return $post_id;
     }
     // Loop through each group, adding an activity entry for each one
     foreach ($groups as $group) {
         // Get the group data
         $group_id = groups_get_id($group->slug);
         $group_name = $group->name;
         // Configure the activity entry
         $post_permalink = get_permalink($post_id);
         $activity_action = sprintf('%1$s added the event %2$s to the %3$s.', bp_core_get_userlink($post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', $group_name . ' <a href="' . SITEURL . '/calendar/' . $group->slug . '">group calendar</a>');
         $activity_content = $post->post_content;
         // Check for existing entry
         $activity_id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $bp->groups->id, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
         // Record the entry
         groups_record_activity(array('id' => $activity_id, 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post_permalink, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
         // Update the group's last activity meta
         groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
         // Maybe notify every group member
         if ($_POST['event-rsvp']) {
             if (bp_group_has_members($args = array('group_id' => $group_id, 'exclude_admins_mods' => false, 'per_page' => 99999))) {
                 while (bp_members()) {
                     bp_the_member();
                     // Remove any existing notifications ( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false )
                     bp_notifications_delete_notifications_by_item_id(bp_get_group_member_id(), $group_id, $bp->groups->id, 'new_calendar_event', $post_id);
                     // Send a notification ( itemid , groupid , component, action , secondary )
                     bp_notifications_add_notification(array('user_id' => bp_get_group_member_id(), 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_calendar_event'));
                 }
             }
         }
     }
 }
 public static function notifyAllUsers()
 {
     global $wpdb;
     if (!empty($_GET['nonce']) and wp_verify_nonce($_GET['nonce'], CMA_BaseController::ADMIN_BP_NOTIFY)) {
         $usersIds = $wpdb->get_col("SELECT ID FROM {$wpdb->users}");
         if (!empty($_GET['post_id']) and $thread = CMA_Thread::getInstance($_GET['post_id'])) {
             $notification = array('item_id' => $thread->getId(), 'secondary_item_id' => 0, 'component_name' => 'cma_notifier', 'component_action' => self::ACTION_NOTIFICATION_THREAD, 'date_notified' => bp_core_current_time(), 'is_new' => 1, 'allow_duplicate' => true);
             foreach ($usersIds as $userId) {
                 if ($thread->isVisible($userId)) {
                     $notification['user_id'] = $userId;
                     bp_notifications_add_notification($notification);
                 }
             }
         }
         if (!empty($_GET['comment_id']) and $answer = CMA_Answer::getById($_GET['comment_id'])) {
             $notification = array('item_id' => $answer->getId(), 'secondary_item_id' => 0, 'component_name' => 'cma_notifier', 'component_action' => self::ACTION_NOTIFICATION_ANSWER, 'date_notified' => bp_core_current_time(), 'is_new' => 1, 'allow_duplicate' => true);
             foreach ($usersIds as $userId) {
                 if ($answer->isVisible($userId)) {
                     $notification['user_id'] = $userId;
                     bp_notifications_add_notification($notification);
                 }
             }
         }
     }
     wp_safe_redirect(CMA::getReferer());
     exit;
 }
/**
 * Notify a member they have been invited to a group.
 *
 * @since BuddyPress (1.0.0)
 *
 * @param BP_Groups_Group $group Group object.
 * @param BP_Groups_Member $member Member object.
 * @param int $inviter_user_id ID of the user who sent the invite.
 * @return bool|null False on failure.
 */
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // Bail if member has already been invited
    if (!empty($member->invite_sent)) {
        return;
    }
    // @todo $inviter_ud may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    // Setup the ID for the invited user
    $invited_user_id = $member->user_id;
    // Trigger a BuddyPress Notification
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('user_id' => $invited_user_id, 'item_id' => $group->id, 'component_name' => buddypress()->groups->id, 'component_action' => 'group_invite'));
    }
    // Bail if member opted out of receiving this email
    if ('no' === bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
        return false;
    }
    $invited_ud = bp_core_get_core_userdata($invited_user_id);
    $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
    $settings_link = bp_core_get_user_domain($invited_user_id) . $settings_slug . '/notifications/';
    $invited_link = bp_core_get_user_domain($invited_user_id);
    $invites_link = trailingslashit($invited_link . bp_get_groups_slug() . '/invites');
    // Set up and send the message
    $to = $invited_ud->user_email;
    $subject = bp_get_email_subject(array('text' => sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name)));
    $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link);
    // Only show the disable notifications line if the settings component is enabled
    if (bp_is_active('settings')) {
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
    }
    // Send the message
    $to = apply_filters('groups_notification_group_invites_to', $to);
    $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
    $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
    wp_mail($to, $subject, $message);
    do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
}
/**
 * Send a screen notifications & email one when an attendee set his preferences
 *
 * @package Rendez Vous
 * @subpackage Notifications
 *
 * @since Rendez Vous (1.0.0)
 */
function rendez_vous_notify_organizer($args = array(), $attendee_id = 0, $rendez_vous = null)
{
    $bp = buddypress();
    if (empty($attendee_id) || empty($rendez_vous) || $attendee_id == $rendez_vous->organizer) {
        return;
    }
    // Screen Notification
    bp_notifications_add_notification(array('user_id' => $rendez_vous->organizer, 'item_id' => $rendez_vous->id, 'secondary_item_id' => $attendee_id, 'component_name' => $bp->rendez_vous->id, 'component_action' => 'rendez_vous_schedule'));
    // Sending Emails
    if ('no' == get_user_meta($rendez_vous->organizer, 'notification_rendez_vous_schedule', true)) {
        return;
    }
    $rendez_vous_link = rendez_vous_get_single_link($rendez_vous->id, $rendez_vous->organizer);
    $rendez_vous_title = stripslashes($rendez_vous->title);
    $rendez_vous_content = wp_kses($rendez_vous_title, array());
    $attendee_name = bp_core_get_user_displayname($attendee_id);
    $attendee_name = stripslashes($attendee_name);
    $organizer_settings = false;
    $organizer_profile = bp_core_get_user_domain($rendez_vous->organizer);
    $organizer_email = bp_core_get_user_email($rendez_vous->organizer);
    $message = sprintf(__("%s set their preferences for the rendez-vous: %s\n\nTo view details, log in and visit: %s\n\n---------------------\n", 'rendez-vous'), $attendee_name, $rendez_vous_content, esc_url($rendez_vous_link));
    $subject = bp_get_email_subject(array('text' => sprintf(__('%s selected date(s) for a rendez-vous', 'rendez-vous'), $attendee_name)));
    // Set up and send the message
    $to = $organizer_email;
    // Only show the disable notifications line if the settings component is enabled
    if (bp_is_active('settings')) {
        $organizer_settings = trailingslashit($organizer_profile . bp_get_settings_slug() . '/notifications');
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'rendez-vous'), esc_url($organizer_settings));
    }
    /* Send the message */
    $to = apply_filters('rendez_vous_userset_notify_organizer', $to);
    $subject = apply_filters('rendez_vous_userset_notify_subject', $subject, $attendee_name);
    $mail_content = apply_filters('rendez_vous_userset_notify_message', $message, $rendez_vous, $attendee_name, $rendez_vous_content, $rendez_vous_link, $organizer_settings);
    wp_mail($to, $subject, $mail_content);
}
Exemple #17
0
 /**
  * @group bp_notifications_add_notification
  */
 public function test_bp_notifications_add_notification_allow_duplicate()
 {
     $args = array('user_id' => 5, 'item_id' => 10, 'secondary_item_id' => 25, 'component_name' => 'messages', 'component_action' => 'new_message');
     $this->factory->notification->create($args);
     $args['allow_duplicate'] = true;
     $this->assertNotEmpty(bp_notifications_add_notification($args));
 }
/**
 * Send notifications.
 *
 * @since 1.0.0
 *
 * @param array $params The data used to add a notification.
 */
function crowdmentions_send_notifications($params)
{
    // Exclude self from notifications.
    $key = array_search($params['user_id'], $params['user_ids']);
    if ($key !== false) {
        array_splice($params['user_ids'], $key, 1);
    }
    // Bail if no users to notify.
    if (empty($params['user_ids'])) {
        return;
    }
    $args = array('item_id' => $params['item_id'], 'secondary_item_id' => $params['secondary_item_id'], 'component_action' => $params['component_action'], 'component_name' => crowdmentions_get_component_name(), 'date_notified' => bp_core_current_time(), 'is_new' => 1);
    // Send a notification to each user.
    foreach ($params['user_ids'] as $user_id) {
        $args['user_id'] = $user_id;
        bp_notifications_add_notification($args);
    }
}
/**
 * Sends a screen notification to the author in case the idea received a vote
 *
 * @package WP Idea Stream
 * @subpackage buddypress/notifications
 *
 * @since  2.0.0
 *
 * @param  int $idea_id the ID of the idea
 * @param  int $user_id the ID of the user who rated the idea
 * @uses   bp_notifications_add_notification() to save a new notification
 * @uses   buddypress() to get BuddyPress instance
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 */
function wp_idea_stream_buddypress_rates_notify_idea_author($idea_id = 0, $user_id = 0)
{
    $author = get_post_field('post_author', $idea_id);
    // Bail, if no author or no user id or if both are same
    if (empty($author) || empty($user_id) || $author == $user_id) {
        return;
    }
    // Add the notification.
    bp_notifications_add_notification(array('user_id' => $author, 'item_id' => $idea_id, 'secondary_item_id' => $user_id, 'component_name' => buddypress()->ideastream->id, 'component_action' => 'new_' . wp_idea_stream_get_post_type() . '_rate', 'is_new' => 1));
}
/**
 * Add a notification when a compliment get submitted.
 *
 * @since 0.0.2
 * @package BuddyPress_Compliments
 *
 * @global object $bp BuddyPress instance.
 * @param BP_Compliments $compliment The compliment object.
 */
function bp_compliments_notifications_add_on_compliment(BP_Compliments $compliment)
{
    // Add a screen notification
    // BP 1.9+
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('item_id' => $compliment->sender_id, 'user_id' => $compliment->receiver_id, 'secondary_item_id' => $compliment->id, 'component_name' => buddypress()->compliments->id, 'component_action' => 'new_compliment'));
        // BP < 1.9 - add notifications the old way
    } elseif (!class_exists('BP_Core_Login_Widget')) {
        global $bp;
        bp_core_add_notification($compliment->sender_id, $compliment->receiver_id, $bp->compliments->id, 'new_compliment');
    }
    // Add an email notification
    bp_compliments_new_compliment_email_notification(array('receiver_id' => $compliment->receiver_id, 'sender_id' => $compliment->sender_id));
}
/**
 * Notify a member they have been invited to a group.
 *
 * @since 1.0.0
 *
 * @param BP_Groups_Group  $group           Group object.
 * @param BP_Groups_Member $member          Member object.
 * @param int              $inviter_user_id ID of the user who sent the invite.
 * @return null|false False on failure.
 */
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // Bail if member has already been invited.
    if (!empty($member->invite_sent)) {
        return;
    }
    // @todo $inviter_ud may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    // Setup the ID for the invited user.
    $invited_user_id = $member->user_id;
    // Trigger a BuddyPress Notification.
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('user_id' => $invited_user_id, 'item_id' => $group->id, 'component_name' => buddypress()->groups->id, 'component_action' => 'group_invite'));
    }
    // Bail if member opted out of receiving this email.
    if ('no' === bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
        return false;
    }
    $invited_ud = bp_core_get_core_userdata($invited_user_id);
    $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
    $settings_link = bp_core_get_user_domain($invited_user_id) . $settings_slug . '/notifications/';
    $invited_link = bp_core_get_user_domain($invited_user_id);
    $invites_link = trailingslashit($invited_link . bp_get_groups_slug() . '/invites');
    // Set up and send the message.
    $to = $invited_ud->user_email;
    $subject = bp_get_email_subject(array('text' => sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name)));
    $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link);
    // Only show the disable notifications line if the settings component is enabled.
    if (bp_is_active('settings')) {
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
    }
    /**
     * Filters the user email that the group invite notification will be sent to.
     *
     * @since 1.2.0
     *
     * @param string $to User email the invite notification is being sent to.
     */
    $to = apply_filters('groups_notification_group_invites_to', $to);
    /**
     * Filters the group invite notification subject that will be sent to user.
     *
     * @since 1.2.0
     *
     * @param string          $subject Invite notification email subject text.
     * @param BP_Groups_Group $group   Object holding the current group instance. Passed by reference.
     */
    $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
    /**
     * Filters the group invite notification message that will be sent to user.
     *
     * @since 1.2.0
     *
     * @param string          $message       Invite notification email message text.
     * @param BP_Groups_Group $group         Object holding the current group instance. Passed by reference.
     * @param string          $inviter_name  Username for the person doing the inviting.
     * @param string          $inviter_link  Profile link for the person doing the inviting.
     * @param string          $invites_link  URL permalink for the invited user's invite management screen.
     * @param string          $group_link    URL permalink for the group that the invite was related to.
     * @param string          $settings_link URL permalink for the user's notification settings area.
     */
    $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
    wp_mail($to, $subject, $message);
    /**
     * Fires after the notification is sent that a member has been invited to a group.
     *
     * @since 1.5.0
     *
     * @param int             $invited_user_id  ID of the user who was invited.
     * @param string          $subject          Email notification subject text.
     * @param string          $message          Email notification message text.
     * @param BP_Groups_Group $group            Group object.
     */
    do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
}
/**
 * Add a notification for post comments to the post author or post commenter.
 *
 * Requires "activity stream commenting on blog and forum posts" to be enabled.
 *
 * @since 2.6.0
 *
 * @param int        $activity_id          The activity comment ID.
 * @param WP_Comment $post_type_comment    WP Comment object.
 * @param array      $activity_args        Activity comment arguments.
 * @param object     $activity_post_object The post type tracking args object.
 */
function bp_activity_add_notification_for_synced_blog_comment($activity_id, $post_type_comment, $activity_args, $activity_post_object)
{
    // If activity comments are disabled for WP posts, stop now!
    if (bp_disable_blogforum_comments() || empty($activity_id)) {
        return;
    }
    // Send a notification to the blog post author.
    if ((int) $post_type_comment->post->post_author !== (int) $activity_args['user_id']) {
        // Only add a notification if comment author is a registered user.
        // @todo Should we remove this restriction?
        if (!empty($post_type_comment->user_id)) {
            bp_notifications_add_notification(array('user_id' => $post_type_comment->post->post_author, 'item_id' => $activity_id, 'secondary_item_id' => $post_type_comment->user_id, 'component_name' => buddypress()->activity->id, 'component_action' => 'update_reply', 'date_notified' => $post_type_comment->comment_date_gmt, 'is_new' => 1));
        }
    }
    // Send a notification to the parent comment author for follow-up comments.
    if (!empty($post_type_comment->comment_parent)) {
        $parent_comment = get_comment($post_type_comment->comment_parent);
        if (!empty($parent_comment->user_id) && (int) $parent_comment->user_id !== (int) $activity_args['user_id']) {
            bp_notifications_add_notification(array('user_id' => $parent_comment->user_id, 'item_id' => $activity_id, 'secondary_item_id' => $post_type_comment->user_id, 'component_name' => buddypress()->activity->id, 'component_action' => 'comment_reply', 'date_notified' => $post_type_comment->comment_date_gmt, 'is_new' => 1));
        }
    }
}
/**
 * Notify a member when another member accepts their virtual friendship request.
 *
 * @since 1.9.0
 *
 * @param int $friendship_id     The unique ID of the friendship.
 * @param int $initiator_user_id The friendship initiator user ID.
 * @param int $friend_user_id    The friendship request receiver user ID.
 */
function bp_friends_add_friendship_accepted_notification($friendship_id, $initiator_user_id, $friend_user_id)
{
    // Bail if notifications is not active.
    if (!bp_is_active('notifications')) {
        return;
    }
    // Remove the friend request notice.
    bp_notifications_mark_notifications_by_item_id($friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request');
    // Add a friend accepted notice for the initiating user.
    bp_notifications_add_notification(array('user_id' => $initiator_user_id, 'item_id' => $friend_user_id, 'secondary_item_id' => $friendship_id, 'component_name' => buddypress()->friends->id, 'component_action' => 'friendship_accepted', 'date_notified' => bp_core_current_time(), 'is_new' => 1));
}
Exemple #24
0
 public function create_object($args)
 {
     return bp_notifications_add_notification($args);
 }
/**
 * Send notifications to message recipients.
 *
 * @since BuddyPress (1.9.0)
 *
 * @param BP_Messages_Message $message Message object.
 */
function bp_messages_message_sent_add_notification($message)
{
    if (bp_is_active('notifications') && !empty($message->recipients)) {
        foreach ((array) $message->recipients as $recipient) {
            bp_notifications_add_notification(array('user_id' => $recipient->user_id, 'item_id' => $message->id, 'secondary_item_id' => $message->sender_id, 'component_name' => buddypress()->messages->id, 'component_action' => 'new_message', 'date_notified' => bp_core_current_time(), 'is_new' => 1));
        }
    }
}
Exemple #26
0
 public function save($args = array())
 {
     global $wpdb;
     $args = array('title' => $this->title, 'description' => $this->description, 'user' => $this->user_id, 'milestone_id' => $this->milestone_id, 'project_id' => $this->project_id, 'priority' => $this->priority, 'date_created' => date("Y-m-d H:i:s"), 'assign_users' => $this->group_members_assigned);
     $trimmed_title = trim($this->title);
     if (empty($trimmed_title)) {
         return false;
     }
     $trimmed_description = trim($this->description);
     if (empty($trimmed_description)) {
         return false;
     }
     $format = array('%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s');
     if (!empty($this->id)) {
         // Assign members to the task.
         $this->assign_members($this->id, $this->group_members_assigned);
         return $wpdb->update($this->model, $args, array('id' => $this->id), $format, array('%d')) === 0;
     } else {
         if ($wpdb->insert($this->model, $args, $format)) {
             $last_insert_id = $wpdb->insert_id;
             // Assign members to the task.
             $this->assign_members($last_insert_id, $this->group_members_assigned);
             // Add new activity. Check if buddypress is active first
             if (function_exists('bp_activity_add')) {
                 $bp_user_link = '';
                 if (function_exists('bp_core_get_userlink')) {
                     $bp_user_link = bp_core_get_userlink($this->user_id);
                 }
                 $task_breaker_project_post = get_post($this->project_id, OBJECT);
                 $task_breaker_project_name = '';
                 $permalink = get_permalink($this->project_id);
                 if (!empty($task_breaker_project_post)) {
                     $task_breaker_project_name = sprintf('<a href="%s" title="%s">%s<a/>', $permalink, $task_breaker_project_post->post_title, $task_breaker_project_post->post_title);
                 }
                 $action = sprintf(__('%s added new task under %s', 'task_breaker'), $bp_user_link, $task_breaker_project_name);
                 $new_activity_id = bp_activity_add(array('user_id' => $this->user_id, 'action' => apply_filters('task_breaker_new_task_activity_action', $action, $this->user_id), 'component' => 'project', 'content' => apply_filters('task_breaker_new_task_activity_descriptioin', sprintf('<a href="%s" title="%s">#%d - %s</a>', $permalink . '#tasks/view/' . $last_insert_id, $this->title, $last_insert_id, $this->title)), 'type' => 'task_breaker_new_task'));
                 // Send a notification to the assigned member
                 $exploded_members = explode(",", $this->group_members_assigned);
                 foreach ((array) $this->group_members_assigned as $ua_id) {
                     bp_notifications_add_notification(array('user_id' => $ua_id, 'item_id' => $last_insert_id, 'secondary_item_id' => $this->user_id, 'component_name' => 'task_breaker_ua_notifications_name', 'component_action' => 'task_breaker_ua_action', 'date_notified' => bp_core_current_time(), 'is_new' => 1));
                 }
             }
             return $last_insert_id;
         } else {
             return false;
         }
     }
 }