Ticket #7130: 7130.2.diff
File 7130.2.diff, 2.8 KB (added by , 7 years ago) |
---|
-
src/bp-notifications/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 // For caching below. 147 ksort( $args ); 148 149 $args_cache_key = ''; 150 if ( ! empty( $args ) ) { 151 $args_cache_key = '_' . md5( json_encode( $args ) ); 152 } 153 145 154 // Get notifications out of the cache, or query if necessary. 146 $notifications = wp_cache_get( 'all_for_user_' . $user_id , 'bp_notifications' );155 $notifications = wp_cache_get( 'all_for_user_' . $user_id . $args_cache_key, 'bp_notifications' ); 147 156 if ( false === $notifications ) { 148 $notifications = BP_Notifications_Notification::get( array (149 'user_id' => $user_id157 $notifications = BP_Notifications_Notification::get( array_merge( 158 $args, array( 'user_id' => $user_id ) 150 159 ) ); 151 wp_cache_set( 'all_for_user_' . $user_id , $notifications, 'bp_notifications' );160 wp_cache_set( 'all_for_user_' . $user_id . $args_cache_key, $notifications, 'bp_notifications' ); 152 161 } 153 162 154 163 /** … … 170 179 * @param int $user_id ID of the user whose notifications are being fetched. 171 180 * @param string $format Format of the returned values. 'string' returns HTML, 172 181 * while 'object' returns a structured object for parsing. 182 * @param array $args Additional arguments to expand notification query. 173 183 * @return mixed Object or array on success, false on failure. 174 184 */ 175 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) {185 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string', $args = array() ) { 176 186 177 187 // Setup local variables. 178 188 $bp = buddypress(); 179 189 180 190 // Get notifications (out of the cache, or query if necessary). 181 $notifications = bp_notifications_get_all_notifications_for_user( $user_id );191 $notifications = bp_notifications_get_all_notifications_for_user( $user_id, $args ); 182 192 $grouped_notifications = array(); // Notification groups. 183 193 $renderable = array(); // Renderable notifications. 184 194