[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Messages Caching. 4 * 5 * Caching functions handle the clearing of cached objects and pages on specific 6 * actions throughout BuddyPress. 7 * 8 * @package BuddyPress 9 * @subpackage MessagesCache 10 * @since 1.5.0 11 */ 12 13 // Exit if accessed directly. 14 defined( 'ABSPATH' ) || exit; 15 16 /** 17 * Slurp up metadata for a set of messages. 18 * 19 * It grabs all message meta associated with all of the messages passed in 20 * $message_ids and adds it to WP cache. This improves efficiency when using 21 * message meta within a loop context. 22 * 23 * @since 2.2.0 24 * 25 * @param int|string|array|bool $message_ids Accepts a single message_id, or a 26 * comma-separated list or array of message ids. 27 */ 28 function bp_messages_update_meta_cache( $message_ids = false ) { 29 bp_update_meta_cache( array( 30 'object_ids' => $message_ids, 31 'object_type' => buddypress()->messages->id, 32 'cache_group' => 'message_meta', 33 'object_column' => 'message_id', 34 'meta_table' => buddypress()->messages->table_name_meta, 35 'cache_key_prefix' => 'bp_messages_meta' 36 ) ); 37 } 38 39 // List actions to clear super cached pages on, if super cache is installed. 40 add_action( 'messages_delete_thread', 'bp_core_clear_cache' ); 41 add_action( 'messages_send_notice', 'bp_core_clear_cache' ); 42 add_action( 'messages_message_sent', 'bp_core_clear_cache' ); 43 44 // Don't cache message inbox/sentbox/compose as it's too problematic. 45 add_action( 'messages_screen_compose', 'bp_core_clear_cache' ); 46 add_action( 'messages_screen_sentbox', 'bp_core_clear_cache' ); 47 add_action( 'messages_screen_inbox', 'bp_core_clear_cache' ); 48 49 /** 50 * Clear message cache after a message is saved. 51 * 52 * @since 2.0.0 53 * 54 * @param BP_Messages_Message $message Message being saved. 55 */ 56 function bp_messages_clear_cache_on_message_save( $message ) { 57 // Delete thread cache. 58 wp_cache_delete( $message->thread_id, 'bp_messages_threads' ); 59 60 // Delete unread count for each recipient. 61 foreach ( (array) $message->recipients as $recipient ) { 62 wp_cache_delete( $recipient->user_id, 'bp_messages_unread_count' ); 63 } 64 65 // Delete thread recipient cache. 66 wp_cache_delete( 'thread_recipients_' . $message->thread_id, 'bp_messages' ); 67 } 68 add_action( 'messages_message_after_save', 'bp_messages_clear_cache_on_message_save' ); 69 70 /** 71 * Clear message cache after a message thread is deleted. 72 * 73 * @since 2.0.0 74 * 75 * @param int|array $thread_ids If single thread, the thread ID. 76 * Otherwise, an array of thread IDs. 77 * @param int $user_id ID of the user that the threads were deleted for. 78 */ 79 function bp_messages_clear_cache_on_message_delete( $thread_ids, $user_id ) { 80 // Delete thread and thread recipient cache. 81 foreach ( (array) $thread_ids as $thread_id ) { 82 wp_cache_delete( $thread_id, 'bp_messages_threads' ); 83 wp_cache_delete( "thread_recipients_{$thread_id}", 'bp_messages' ); 84 } 85 86 // Delete unread count for logged-in user. 87 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); 88 } 89 add_action( 'messages_delete_thread', 'bp_messages_clear_cache_on_message_delete', 10, 2 ); 90 add_action( 'bp_messages_exit_thread', 'bp_messages_clear_cache_on_message_delete', 10, 2 ); 91 92 /** 93 * Invalidate cache for notices. 94 * 95 * Currently, invalidates active notice cache. 96 * 97 * @since 2.0.0 98 */ 99 function bp_notices_clear_cache() { 100 wp_cache_delete( 'active_notice', 'bp_messages' ); 101 } 102 add_action( 'messages_notice_after_save', 'bp_notices_clear_cache' ); 103 add_action( 'messages_notice_before_delete', 'bp_notices_clear_cache' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |