recipients as $recipient ) { wp_cache_delete( $recipient->user_id, 'bp_messages_unread_count' ); } } add_action( 'messages_message_after_save', 'bp_messages_clear_unread_count_cache_on_message_save' ); /** * Clears unread count cache for the logged-in user after a message is deleted. * * @since BuddyPress (2.0.0) * * @param int|array $thread_ids If single thread, the thread ID. Otherwise, an * array of thread IDs */ function bp_messages_clear_unread_count_cache_on_message_delete( $thread_ids ) { wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' ); } add_action( 'messages_before_delete_thread', 'bp_messages_clear_unread_count_cache_on_message_delete' ); /** * Invalidates cache for notices. * * Currently, invalidates active notice cache. * * @since BuddyPress (2.0.0) */ function bp_notices_clear_cache( $notice ) { wp_cache_delete( 'active_notice', 'bp_messages' ); } add_action( 'messages_notice_after_save', 'bp_notices_clear_cache' ); add_action( 'messages_notice_before_delete', 'bp_notices_clear_cache' );