[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Caching functions specific to BuddyPress Members. 4 * 5 * @package BuddyPress 6 * @subpackage MembersCache 7 * @since 2.2.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Pre-fetch member type data when initializing a Members loop. 15 * 16 * @since 2.2.0 17 * 18 * @param BP_User_Query $bp_user_query BP_User_Query object. 19 */ 20 function bp_members_prefetch_member_type( $bp_user_query ) { 21 $uncached_member_ids = bp_get_non_cached_ids( $bp_user_query->user_ids, 'bp_member_member_type' ); 22 23 $member_types = bp_get_object_terms( $uncached_member_ids, bp_get_member_type_tax_name(), array( 24 'fields' => 'all_with_object_id', 25 ) ); 26 27 // Rekey by user ID. 28 $keyed_member_types = array(); 29 foreach ( $member_types as $member_type ) { 30 if ( ! isset( $keyed_member_types[ $member_type->object_id ] ) ) { 31 $keyed_member_types[ $member_type->object_id ] = array(); 32 } 33 34 $keyed_member_types[ $member_type->object_id ][] = $member_type->name; 35 } 36 37 $cached_member_ids = array(); 38 foreach ( $keyed_member_types as $user_id => $user_member_types ) { 39 wp_cache_set( $user_id, $user_member_types, 'bp_member_member_type' ); 40 $cached_member_ids[] = $user_id; 41 } 42 43 // Cache an empty value for users with no type. 44 foreach ( array_diff( $uncached_member_ids, $cached_member_ids ) as $no_type_id ) { 45 wp_cache_set( $no_type_id, '', 'bp_member_member_type' ); 46 } 47 } 48 add_action( 'bp_user_query_populate_extras', 'bp_members_prefetch_member_type' ); 49 50 /** 51 * Clear the member_type cache for a user. 52 * 53 * Called when the user is deleted or marked as spam. 54 * 55 * @since 2.2.0 56 * 57 * @param int $user_id ID of the deleted user. 58 */ 59 function bp_members_clear_member_type_cache( $user_id ) { 60 wp_cache_delete( $user_id, 'bp_member_member_type' ); 61 } 62 add_action( 'wpmu_delete_user', 'bp_members_clear_member_type_cache' ); 63 add_action( 'delete_user', 'bp_members_clear_member_type_cache' ); 64 65 /** 66 * Invalidate activity caches when a user's last_activity value is changed. 67 * 68 * @since 2.7.0 69 * 70 * @return bool True on success, false on failure. 71 */ 72 function bp_members_reset_activity_cache_incrementor() { 73 return bp_core_reset_incrementor( 'bp_activity_with_last_activity' ); 74 } 75 add_action( 'bp_core_user_updated_last_activity', 'bp_members_reset_activity_cache_incrementor' ); 76 77 /** 78 * Bust signup caches when editing or deleting. 79 * 80 * @since 10.0.0 81 * 82 * @param int $signup_id The ID of the signup affected. 83 */ 84 function bp_members_delete_signup_cache( $signup_id = 0 ) { 85 wp_cache_delete( $signup_id, 'bp_signups' ); 86 } 87 add_action( 'bp_core_signups_after_add', 'bp_members_delete_signup_cache' ); 88 add_action( 'bp_core_signups_after_update_meta', 'bp_members_delete_signup_cache' ); 89 90 /** 91 * Bust signup caches for arrays of signup IDs. 92 * 93 * @since 10.0.0 94 * 95 * @param array $signup_ids The IDs of the signups affected. 96 */ 97 function bp_members_delete_signup_cache_multiples( $signup_ids = array() ) { 98 // Ensure that the incoming item is an array. 99 $signup_ids = wp_parse_id_list( $signup_ids ); 100 foreach ( $signup_ids as $signup_id ) { 101 bp_members_delete_signup_cache( $signup_id ); 102 } 103 } 104 add_action( 'bp_core_signup_after_resend', 'bp_members_delete_signup_cache_multiples' ); 105 add_action( 'bp_core_signup_after_activate', 'bp_members_delete_signup_cache_multiples' ); 106 add_action( 'bp_core_signup_after_delete', 'bp_members_delete_signup_cache_multiples' ); 107 108 /** 109 * Reset cache incrementor for BP_Signups. 110 * 111 * This function invalidates all cached results of BP_Signup queries, 112 * whenever one of the following events takes place: 113 * - A record is created or updated. 114 * - A record is deleted. 115 * 116 * @since 10.0.0 117 * 118 * @return bool True on success, false on failure. 119 */ 120 function bp_members_reset_signup_cache_incrementor() { 121 return bp_core_reset_incrementor( 'bp_signups' ); 122 } 123 add_filter( 'bp_core_signups_after_add', 'bp_members_reset_signup_cache_incrementor' ); 124 add_action( 'bp_core_activated_user', 'bp_members_reset_signup_cache_incrementor' ); 125 add_action( 'bp_core_signup_after_activate', 'bp_members_reset_signup_cache_incrementor' ); 126 add_action( 'bp_core_signups_after_update_meta', 'bp_members_reset_signup_cache_incrementor' ); 127 add_action( 'bp_core_signup_after_delete', 'bp_members_reset_signup_cache_incrementor' ); 128
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 |