bp_notifications_get_all_notifications_for_user( int $user_id )
Get all notifications for a user and cache them.
Description
Parameters
- $user_id
-
(Required) ID of the user whose notifications are being fetched.
Return
(array) $notifications Array of notifications for user.
Source
File: bp-notifications/bp-notifications-functions.php
function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) {
// Default to displayed user if no ID is passed.
if ( empty( $user_id ) ) {
$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
}
// Get notifications out of the cache, or query if necessary.
$notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' );
if ( false === $notifications ) {
$notifications = BP_Notifications_Notification::get( array(
'user_id' => $user_id
) );
wp_cache_set( 'all_for_user_' . $user_id, $notifications, 'bp_notifications' );
}
/**
* Filters all notifications for a user.
*
* @since BuddyPress 2.1.0
*
* @param array $notifications Array of notifications for user.
* @param int $user_id ID of the user being fetched.
*/
return apply_filters( 'bp_notifications_get_all_notifications_for_user', $notifications, $user_id );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.