Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/01/2015 04:18:13 AM (11 years ago)
Author:
tw2113
Message:

First pass of documentation cleanup for the XProfile Component.

See #6406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-cache.php

    r10140 r10163  
    1818 * @since 2.2.0
    1919 *
    20  * @param int   $user_id   User ID to check
     20 * @param int   $user_id   User ID to check.
    2121 * @param array $field_ids XProfile field IDs.
     22 *
    2223 * @return array
    2324 */
    … …  
    5152 *
    5253 * @param array $object_ids Multi-dimensional array of object_ids, keyed by
    53  *        object type ('group', 'field', 'data')
     54 *                          object type ('group', 'field', 'data').
     55 *
     56 * @return bool
    5457 */
    5558function bp_xprofile_update_meta_cache( $object_ids = array() ) {
    5659        global $wpdb;
    5760
    58         // Bail if no objects
     61        // Bail if no objects.
    5962        if ( empty( $object_ids ) ) {
    6063                return false;
    … …  
    6366        $bp = buddypress();
    6467
    65         // Define the array where uncached object IDs will be stored
     68        // Define the array where uncached object IDs will be stored.
    6669        $uncached_object_ids = array(
    6770                'group',
    … …  
    7073        );
    7174
    72         // Define the cache groups for the 3 types of XProfile metadata
     75        // Define the cache groups for the 3 types of XProfile metadata.
    7376        $cache_groups = array(
    7477                'group' => 'xprofile_group_meta',
    … …  
    7780        );
    7881
    79         // No reason to query yet
     82        // No reason to query yet.
    8083        $do_query = false;
    8184
    82         // Loop through object types and look for uncached data
     85        // Loop through object types and look for uncached data.
    8386        foreach ( $uncached_object_ids as $object_type ) {
    8487
    85                 // Skip if empty object type
     88                // Skip if empty object type.
    8689                if ( empty( $object_ids[ $object_type ] ) ) {
    8790                        continue;
    8891                }
    8992
    90                 // Sanitize $object_ids passed to the function
     93                // Sanitize $object_ids passed to the function.
    9194                $object_type_ids = wp_parse_id_list( $object_ids[ $object_type ] );
    9295
    93                 // Get non-cached IDs for each object type
     96                // Get non-cached IDs for each object type.
    9497                $uncached_object_ids[ $object_type ] = bp_get_non_cached_ids( $object_type_ids, $cache_groups[ $object_type ] );
    9598
    96                 // Set the flag to do the meta query
     99                // Set the flag to do the meta query.
    97100                if ( ! empty( $uncached_object_ids[ $object_type ] ) && ( false === $do_query ) ) {
    98101                        $do_query = true;
    … …  
    100103        }
    101104
    102         // Bail if no uncached items
     105        // Bail if no uncached items.
    103106        if ( false === $do_query ) {
    104107                return;
    105108        }
    106109
    107         // Setup where conditions for query
     110        // Setup where conditions for query.
    108111        $where_sql        = '';
    109112        $where_conditions = array();
    110113
    111         // Loop through uncached objects and prepare to query for them
     114        // Loop through uncached objects and prepare to query for them.
    112115        foreach ( $uncached_object_ids as $otype => $oids ) {
    113116
    114                 // Skip empty object IDs
     117                // Skip empty object IDs.
    115118                if ( empty( $oids ) ) {
    116119                        continue;
    117120                }
    118121
    119                 // Compile WHERE query conditions for uncached metadata
     122                // Compile WHERE query conditions for uncached metadata.
    120123                $oids_sql           = implode( ',', wp_parse_id_list( $oids ) );
    121124                $where_conditions[] = $wpdb->prepare( "( object_type = %s AND object_id IN ({$oids_sql}) )", $otype );
    122125        }
    123126
    124         // Bail if no where conditions
     127        // Bail if no where conditions.
    125128        if ( empty( $where_conditions ) ) {
    126129                return;
    127130        }
    128131
    129         // Setup the WHERE query part
     132        // Setup the WHERE query part.
    130133        $where_sql = implode( " OR ", $where_conditions );
    131134
    132         // Attempt to query meta values
     135        // Attempt to query meta values.
    133136        $meta_list = $wpdb->get_results( "SELECT object_id, object_type, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE {$where_sql}" );
    134137
    135         // Bail if no results found
     138        // Bail if no results found.
    136139        if ( empty( $meta_list ) || is_wp_error( $meta_list ) ) {
    137140                return;
    138141        }
    139142
    140         // Setup empty cache array
     143        // Setup empty cache array.
    141144        $cache = array();
    142145
    143         // Loop through metas
     146        // Loop through metas.
    144147        foreach ( $meta_list as $meta ) {
    145148                $oid    = $meta->object_id;
    … …  
    148151                $ovalue = $meta->meta_value;
    149152
    150                 // Force subkeys to be array type
     153                // Force subkeys to be array type.
    151154                if ( ! isset( $cache[ $otype ][ $oid ] ) || ! is_array( $cache[ $otype ][ $oid ] ) ) {
    152155                        $cache[ $otype ][ $oid ] = array();
    … …  
    157160                }
    158161
    159                 // Add to the cache array
     162                // Add to the cache array.
    160163                $cache[ $otype ][ $oid ][ $okey ][] = maybe_unserialize( $ovalue );
    161164        }
    162165
    163         // Loop through data and cache to the appropriate object
     166        // Loop through data and cache to the appropriate object.
    164167        foreach ( $cache as $object_type => $object_caches ) {
    165168
    166                 // Determine the cache group for this data
     169                // Determine the cache group for this data.
    167170                $cache_group = $cache_groups[ $object_type ];
    168171
    169                 // Loop through objects and cache appropriately
     172                // Loop through objects and cache appropriately.
    170173                foreach ( $object_caches as $object_id => $object_cache ) {
    171174                        wp_cache_set( $object_id, $object_cache, $cache_group );
    … …  
    175178
    176179/**
    177  * Clear cached XProfile field group data
     180 * Clear cached XProfile field group data.
    178181 *
    179182 * @since 2.1.0
    180183 *
    181  * @param object $group_obj
     184 * @param object $group_obj Groub object to clear.
    182185 */
    183186function xprofile_clear_profile_groups_object_cache( $group_obj ) {
    … …  
    189192
    190193/**
    191  * Clear cached XProfile fullname data for user
     194 * Clear cached XProfile fullname data for user.
    192195 *
    193196 * @since 2.1.0
    194197 *
    195  * @param int $user_id ID of user whose fullname cache to delete
     198 * @param int $user_id ID of user whose fullname cache to delete.
    196199 */
    197200function xprofile_clear_profile_data_object_cache( $user_id = 0 ) {
    … …  
    203206 * Clear the fullname cache when field 1 is updated.
    204207 *
    205  * xprofile_clear_profile_data_object_cache() will make this redundant in most
    206  * cases, except where the field is updated directly with xprofile_set_field_data()
    207  *
    208  * @since 2.0.0
     208 * The xprofile_clear_profile_data_object_cache() will make this redundant in most
     209 * cases, except where the field is updated directly with xprofile_set_field_data().
     210 *
     211 * @since 2.0.0
     212 *
     213 * @param object $data Data object to clear.
    209214 */
    210215function xprofile_clear_fullname_cache_on_profile_field_edit( $data ) {
    … …  
    220225 * @since 2.0.0
    221226 *
    222  * @param BP_XProfile_Field
     227 * @param BP_XProfile_Field $field_obj Field object cache to delete.
    223228 */
    224229function xprofile_clear_profile_field_object_cache( $field_obj ) {
    225230
    226         // Clear default visibility level cache
     231        // Clear default visibility level cache.
    227232        wp_cache_delete( 'default_visibility_levels', 'bp_xprofile' );
    228233
    229234        // Modified fields can alter parent group status, in particular when
    230235        // the group goes from empty to non-empty. Bust its cache, as well as
    231         // the global 'all' cache
     236        // the global 'all' cache.
    232237        wp_cache_delete( 'all',                'bp_xprofile_groups' );
    233238        wp_cache_delete( $field_obj->group_id, 'bp_xprofile_groups' );
    … …  
    251256 * @since 2.0.0
    252257 *
    253  * @param BP_XProfile_ProfileData $data_obj
     258 * @param BP_XProfile_ProfileData $data_obj Field data object to delete.
    254259 */
    255260function xprofile_clear_profiledata_object_cache( $data_obj ) {
    … …  
    279284add_action( 'update_option_bp-xprofile-fullname-field-name', 'xprofile_clear_fullname_field_id_cache' );
    280285
    281 // List actions to clear super cached pages on, if super cache is installed
     286// List actions to clear super cached pages on, if super cache is installed.
    282287add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' );
Note: See TracChangeset for help on using the changeset viewer.