/** * Sends emails and BP notifications for users @-mentioned in an activity item. * * @since 1.7.0 * * @uses bp_activity_at_message_notification() * @uses bp_activity_update_mention_count_for_user() * * @param BP_Activity_Activity $activity The BP_Activity_Activity object. */ function bp_activity_at_name_send_emails($activity) { // Are mentions disabled? if (!bp_activity_do_mentions()) { return; } // If our temporary variable doesn't exist, stop now. if (empty(buddypress()->activity->mentioned_users)) { return; } // Grab our temporary variable from bp_activity_at_name_filter_updates(). $usernames = buddypress()->activity->mentioned_users; // Get rid of temporary variable. unset(buddypress()->activity->mentioned_users); // Send @mentions and setup BP notifications. foreach ((array) $usernames as $user_id => $username) { /** * Filters BuddyPress' ability to send email notifications for @mentions. * * @since 1.6.0 * * @param bool $value Whether or not BuddyPress should send a notification to the mentioned users. * @param array $usernames Array of users potentially notified. */ if (apply_filters('bp_activity_at_name_do_notifications', true, $usernames)) { bp_activity_at_message_notification($activity->id, $user_id); } // Updates mention count for the user. bp_activity_update_mention_count_for_user($user_id, $activity->id); } }
/** * Adjusts mention count for mentioned users in activity items. * * This function is useful if you only have the activity ID handy and you * haven't parsed an activity item for @mentions yet. * * Currently, only used in {@link bp_activity_delete()}. * * @since BuddyPress (1.5.0) * * @uses bp_activity_find_mentions() * @uses bp_activity_update_mention_count_for_user() * * @param int $activity_id The unique id for the activity item. * @param string $action Can be 'delete' or 'add'. Defaults to 'add'. */ function bp_activity_adjust_mention_count($activity_id = 0, $action = 'add') { // Bail if no activity ID passed if (empty($activity_id)) { return false; } // Get activity object $activity = new BP_Activity_Activity((int) $activity_id); // Try to find mentions $usernames = bp_activity_find_mentions(strip_tags($activity->content)); // Still empty? Stop now if (empty($usernames)) { return false; } // Increment mention count foreach mentioned user foreach ((array) array_keys($usernames) as $user_id) { bp_activity_update_mention_count_for_user($user_id, $activity_id, $action); } }
/** * Sends emails and BP notifications for users @-mentioned in an activity item. * * @since BuddyPress (1.7) * * @uses bp_activity_at_message_notification() * @uses bp_activity_update_mention_count_for_user() * * @param BP_Activity_Activity $activity The BP_Activity_Activity object */ function bp_activity_at_name_send_emails($activity) { // Are mentions disabled? if (!bp_activity_do_mentions()) { return; } // If our temporary variable doesn't exist, stop now. if (empty(buddypress()->activity->mentioned_users)) { return; } // Grab our temporary variable from bp_activity_at_name_filter_updates() $usernames = buddypress()->activity->mentioned_users; // Get rid of temporary variable unset(buddypress()->activity->mentioned_users); // Send @mentions and setup BP notifications foreach ((array) $usernames as $user_id => $username) { // If you want to disable notifications, you can use this filter to stop email sending if (apply_filters('bp_activity_at_name_do_notifications', true, $usernames)) { bp_activity_at_message_notification($activity->id, $user_id); } // Updates mention count for the user bp_activity_update_mention_count_for_user($user_id, $activity->id); } }