Changeset 9887
- Timestamp:
- 05/21/2015 07:56:59 PM (11 years ago)
- Location:
- trunk/src/bp-notifications
- Files:
-
- 2 edited
-
bp-notifications-cache.php (modified) (4 diffs)
-
classes/class-bp-notifications-notification.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-cache.php
r9819 r9887 32 32 33 33 /** 34 * Clear all notifications cache for a given user ID 35 * 36 * @since BuddyPress (2.3.0) 37 * 38 * @param int $user_id The user ID's cache to clear 39 */ 40 function bp_notifications_clear_all_for_user_cache( $user_id = 0 ) { 41 wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' ); 42 } 43 44 /** 34 45 * Invalidate 'all_for_user_' cache when saving. 35 46 * … … 39 50 */ 40 51 function bp_notifications_clear_all_for_user_cache_after_save( BP_Notifications_Notification $n ) { 41 wp_cache_delete( 'all_for_user_' . $n->user_id, 'bp_notifications');52 bp_notifications_clear_all_for_user_cache( $n->user_id ); 42 53 } 43 54 add_action( 'bp_notification_after_save', 'bp_notifications_clear_all_for_user_cache_after_save' ); … … 51 62 */ 52 63 function bp_notifications_clear_all_for_user_cache_before_delete( $args ) { 64 53 65 // Pull up a list of items matching the args (those about te be deleted) 54 66 $ns = BP_Notifications_Notification::get( $args ); … … 59 71 } 60 72 61 foreach ( array_unique( $user_ids ) as $user_id ) { 62 wp_cache_delete( 'all_for_user_' . $user_id, 'bp_notifications' ); 73 $user_ids = array_unique( $user_ids ); 74 foreach ( $user_ids as $user_id ) { 75 bp_notifications_clear_all_for_user_cache( $user_id ); 63 76 } 64 77 } 65 78 add_action( 'bp_notification_before_delete', 'bp_notifications_clear_all_for_user_cache_before_delete' ); 79 80 /** 81 * Invalidates 'all_for_user_' cache when updating. 82 * 83 * @since BuddyPress (2.3.0) 84 * 85 * @param array $update_args See BP_Notifications_Notification::update() for description. 86 * @param array $where_args See BP_Notifications_Notification::update() for description. 87 */ 88 function bp_notifications_clear_all_for_user_cache_before_update( $update_args, $where_args ) { 89 90 // User ID is passed in where arugments 91 if ( ! empty( $where_args['user_id'] ) ) { 92 bp_notifications_clear_all_for_user_cache( $where_args['user_id'] ); 93 94 // Get user ID from Notification ID 95 } elseif ( ! empty( $where_args['id'] ) ) { 96 $n = bp_notifications_get_notification( $where_args['id'] ); 97 bp_notifications_clear_all_for_user_cache( $n->user_id ); 98 } 99 } 100 add_action( 'bp_notification_before_update', 'bp_notifications_clear_all_for_user_cache_before_update', 10, 2 ); -
trunk/src/bp-notifications/classes/class-bp-notifications-notification.php
r9819 r9887 831 831 $where = self::get_query_clauses( $where_args ); 832 832 833 // make sure we delete the notification cache for the user on update 834 if ( ! empty( $where_args['user_id'] ) ) { 835 wp_cache_delete( 'all_for_user_' . $where_args['user_id'], 'bp_notifications' ); 836 } 837 838 return self::_update( $update['data'], $where['data'], $update['format'], $where['format'] ); 833 /** 834 * Fires before the update of a notification item. 835 * 836 * @since BuddyPress (2.3.0) 837 * 838 * @param array $update_args See BP_Notifications_Notification::update(). 839 * @param array $where_args See BP_Notifications_Notification::update(). 840 */ 841 do_action( 'bp_notification_before_update', $update_args, $where_args ); 842 843 return self::_update( 844 $update['data'], 845 $where['data'], 846 $update['format'], 847 $where['format'] 848 ); 839 849 } 840 850
Note: See TracChangeset
for help on using the changeset viewer.