Skip to:
Content

BuddyPress.org

Ticket #7130: 7130.2.diff

File 7130.2.diff, 2.8 KB (added by mauteri, 7 years ago)

Bug in code, ksort in wrong place.

  • src/bp-notifications/bp-notifications-functions.php

     
    132132 *
    133133 * @since 2.1.0
    134134 *
    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.
    136137 * @return array $notifications Array of notifications for user.
    137138 */
    138 function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) {
     139function bp_notifications_get_all_notifications_for_user( $user_id = 0, $args = array() ) {
    139140
    140141        // Default to displayed user if no ID is passed.
    141142        if ( empty( $user_id ) ) {
     
    142143                $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    143144        }
    144145
     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
    145154        // 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' );
    147156        if ( false === $notifications ) {
    148                 $notifications = BP_Notifications_Notification::get( array(
    149                         'user_id' => $user_id
     157                $notifications = BP_Notifications_Notification::get( array_merge(
     158                        $args, array( 'user_id' => $user_id )
    150159                ) );
    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' );
    152161        }
    153162
    154163        /**
     
    170179 * @param int    $user_id ID of the user whose notifications are being fetched.
    171180 * @param string $format  Format of the returned values. 'string' returns HTML,
    172181 *                        while 'object' returns a structured object for parsing.
     182 * @param array  $args    Additional arguments to expand notification query.
    173183 * @return mixed Object or array on success, false on failure.
    174184 */
    175 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) {
     185function bp_notifications_get_notifications_for_user( $user_id, $format = 'string', $args = array() ) {
    176186
    177187        // Setup local variables.
    178188        $bp = buddypress();
    179189
    180190        // 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 );
    182192        $grouped_notifications = array(); // Notification groups.
    183193        $renderable            = array(); // Renderable notifications.
    184194