/** * Output full-text description for a specific notification. * * @since BuddyPress (1.9.0) */ function bp_the_notification_description() { echo bp_get_the_notification_description(); }
/** * Get the notifications from BuddyPress */ function get_notifications() { // Setup notification array $nots = array(); // Count each type $nots['counts'] = array('activity' => 0, 'messages' => 0, 'friends' => 0, 'groups' => 0); // Configure query parameters $args = array('user_id' => $this->user_id, 'is_new' => true, 'page' => '', 'per_page' => '', 'max' => '', 'search_terms' => ''); // Loop through notifications, sorting them by type if (bp_has_notifications($args)) { while (bp_the_notifications()) { bp_the_notification(); // Get the notification global $bp; $not = $bp->notifications->query_loop->notification; // Consolidate action components if ($not->component_name == "forums") { $not->component_name = "activity"; } if ($not->component_name == "events") { $not->component_name = "groups"; } $comp = $not->component_name; // Add a count for each notification type $not->count = 1; // Get the default description $not->desc = 'activity' != $not->component_name ? bp_get_the_notification_description() : ""; // Add notifications to the array $nots[$comp][] = $not; // Increment the count $nots['counts'][$comp]++; } } // Group activity notifications if ($nots['counts']['activity'] > 0) { // Get the activities and setup a combined array $acts = $nots['activity']; $activities = array(); // Loop over activities and group them by item_id for ($i = 0; $i < count($acts); $i++) { // Mentions get grouped, other activities use their item_id $item_id = $acts[$i]->component_action == 'new_at_mention' ? 0 : $acts[$i]->item_id; $acts[$i]->id = $item_id; // Add the activity, or increment the count if (!isset($activities[$item_id])) { $activities[$item_id] = $acts[$i]; } else { $activities[$item_id]->count++; } } // Loop over grouped notifications, apply custom formatting for activities foreach ($nots['activity'] as $id => $not) { // Get the formatted description $nots['activity'][$id]->desc = $this->format_notification($not); } // Replace activities with the grouped ones $nots['activity'] = $activities; } // Return the notifications return $nots; }