Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/22/2022 07:23:34 PM (3 years ago)
Author:
imath
Message:

Clear the notifications user cache when bulk updating/deleting items

This commit also groups PHP Unit tests about notifications cache functions into a specific file.

Props niftythree, oztaser.

Fixes #8637 (branch 10.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/10.0/src/bp-notifications/bp-notifications-cache.php

    r13091 r13244  
    102102        $n = bp_notifications_get_notification( $where_args['id'] );
    103103        bp_notifications_clear_all_for_user_cache( $n->user_id );
     104
     105        // Get the list of user IDs from notification IDs.
     106    } elseif ( isset( $where_args['ids'] ) && $where_args['ids'] ) {
     107        $ids = (array) $where_args['ids'];
     108
     109        $ns = BP_Notifications_Notification::get(
     110            array(
     111                'id' => $ids,
     112            )
     113        );
     114
     115        $user_ids = wp_list_pluck( $ns, 'user_id' );
     116        $user_ids = array_unique( $user_ids );
     117
     118        foreach ( $user_ids as $user_id ) {
     119            bp_notifications_clear_all_for_user_cache( $user_id );
     120        }
    104121    }
    105122}
Note: See TracChangeset for help on using the changeset viewer.