Changeset 8744
- Timestamp:
- 07/31/2014 05:31:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-functions.php
r8577 r8744 129 129 130 130 /** 131 * Get notifications for a specific user.132 * 133 * @since BuddyPress ( 1.9.0)134 * 135 * @param int $user_id ID of the user whose notification are being fetched.136 * @ param string $format Format of the returned values. 'string' returns HTML,137 * while 'object' returns a structured object for parsing.138 * @return mixed Object or array on success, false on failure. 139 */ 140 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) { 141 142 // Setup local variables143 $bp = buddypress();131 * Get all notifications for a user and cache them 132 * 133 * @since BuddyPress (2.1.0) 134 * 135 * @param int $user_id 136 * @return array 137 */ 138 function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) { 139 140 // Default to displayed user if no ID is passed 141 if ( empty( $user_id ) ) { 142 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 143 } 144 144 145 145 // Get notifications out of the cache, or query if necessary … … 152 152 } 153 153 154 // Filter and return 155 return apply_filters( 'bp_notifications_get_all_notifications_for_user', $notifications, $user_id ); 156 } 157 158 /** 159 * Get notifications for a specific user. 160 * 161 * @since BuddyPress (1.9.0) 162 * 163 * @param int $user_id ID of the user whose notification are being fetched. 164 * @param string $format Format of the returned values. 'string' returns HTML, 165 * while 'object' returns a structured object for parsing. 166 * @return mixed Object or array on success, false on failure. 167 */ 168 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) { 169 170 // Setup local variables 171 $bp = buddypress(); 172 173 // Get notifications (out of the cache, or query if necessary) 174 $notifications = bp_notifications_get_all_notifications_for_user( $user_id ); 154 175 $grouped_notifications = array(); // Notification groups 155 176 $renderable = array(); // Renderable notifications … … 519 540 */ 520 541 function bp_notifications_get_unread_notification_count( $user_id = 0 ) { 521 522 // Default to displayed user if no ID is passed 523 if ( empty( $user_id ) ) { 524 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 525 } 526 527 // Get the notifications, and count them 528 $notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' ); 529 if ( false === $notifications ) { 530 $notifications = BP_Notifications_Notification::get( array( 531 'user_id' => $user_id, 532 ) ); 533 wp_cache_set( 'all_for_user_' . $user_id, $notifications, 'bp_notifications' ); 534 } 535 536 $count = ! empty( $notifications ) ? count( $notifications ) : 0; 537 538 return apply_filters( 'bp_notifications_get_total_notification_count', $count ); 542 $notifications = bp_notifications_get_all_notifications_for_user( $user_id ); 543 $count = ! empty( $notifications ) ? count( $notifications ) : 0; 544 545 return apply_filters( 'bp_notifications_get_total_notification_count', (int) $count ); 539 546 } 540 547
Note: See TracChangeset
for help on using the changeset viewer.