Ticket #7130: 7130.1.diff
File 7130.1.diff, 2.7 KB (added by , 7 years ago) |
---|
-
bp-notifications-functions.php
132 132 * 133 133 * @since 2.1.0 134 134 * 135 * @param int $user_id ID of the user whose notifications are being fetched. 135 * @param int $user_id ID of the user whose notifications are being fetched. 136 * @param array $args Additional arguments to expand notification query. 136 137 * @return array $notifications Array of notifications for user. 137 138 */ 138 function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) {139 function bp_notifications_get_all_notifications_for_user( $user_id = 0, $args = array() ) { 139 140 140 141 // Default to displayed user if no ID is passed. 141 142 if ( empty( $user_id ) ) { … … 142 143 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 143 144 } 144 145 146 $args_cache_key = ''; 147 if ( ! empty( $args ) ) { 148 $args_cache_key = '_' . md5( json_encode( $args ) ); 149 } 150 145 151 // Get notifications out of the cache, or query if necessary. 146 $notifications = wp_cache_get( 'all_for_user_' . $user_id , 'bp_notifications' );152 $notifications = wp_cache_get( 'all_for_user_' . $user_id . $args_cache_key, 'bp_notifications' ); 147 153 if ( false === $notifications ) { 148 $notifications = BP_Notifications_Notification::get( array( 149 'user_id' => $user_id 154 // For caching below. 155 ksort( $args ); 156 $notifications = BP_Notifications_Notification::get( array_merge( 157 $args, array( 'user_id' => $user_id ) 150 158 ) ); 151 wp_cache_set( 'all_for_user_' . $user_id , $notifications, 'bp_notifications' );159 wp_cache_set( 'all_for_user_' . $user_id . $args_cache_key, $notifications, 'bp_notifications' ); 152 160 } 153 161 154 162 /** … … 170 178 * @param int $user_id ID of the user whose notifications are being fetched. 171 179 * @param string $format Format of the returned values. 'string' returns HTML, 172 180 * while 'object' returns a structured object for parsing. 181 * @param array $args Additional arguments to expand notification query. 173 182 * @return mixed Object or array on success, false on failure. 174 183 */ 175 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) {184 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string', $args = array() ) { 176 185 177 186 // Setup local variables. 178 187 $bp = buddypress(); 179 188 180 189 // Get notifications (out of the cache, or query if necessary). 181 $notifications = bp_notifications_get_all_notifications_for_user( $user_id );190 $notifications = bp_notifications_get_all_notifications_for_user( $user_id, $args ); 182 191 $grouped_notifications = array(); // Notification groups. 183 192 $renderable = array(); // Renderable notifications. 184 193