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/classes/class-bp-xprofile-profiledata.php

    r10142 r10163  
    11<?php
    22/**
    3  * BuddyPress XProfile Classes
     3 * BuddyPress XProfile Classes.
    44 *
    55 * @package BuddyPress
    … …  
    2323        }
    2424
    25         public function populate( $field_id, $user_id )  {
     25        public function populate( $field_id, $user_id ) {
    2626                global $wpdb;
    2727
    … …  
    4848
    4949                } else {
    50                         // When no row is found, we'll need to set these properties manually
     50                        // When no row is found, we'll need to set these properties manually.
    5151                        $this->field_id     = $field_id;
    5252                        $this->user_id      = $user_id;
    … …  
    6464                global $wpdb;
    6565
    66                 // Check cache first
     66                // Check cache first.
    6767                $cache_key = "{$this->user_id}:{$this->field_id}";
    6868                $cached    = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    … …  
    100100
    101101                /**
    102                  * Filters whether or not data is for a valid field
     102                 * Filters whether or not data is for a valid field.
    103103                 *
    104104                 * @since 1.2.7
    … …  
    164164
    165165        /**
    166          * Delete specific XProfile field data
     166         * Delete specific XProfile field data.
    167167         *
    168168         * @global object $wpdb
    … …  
    205205         * Get a user's profile data for a set of fields.
    206206         *
    207          * @param int $user_id
    208          * @param array $field_ids
     207         * @param int   $user_id   ID of user whose data is being queried.
     208         * @param array $field_ids Array of field IDs to query for.
     209         *
    209210         * @return array
    210211         */
    … …  
    216217                $uncached_field_ids = bp_xprofile_get_non_cached_field_ids( $user_id, $field_ids );
    217218
    218                 // Prime the cache
     219                // Prime the cache.
    219220                if ( ! empty( $uncached_field_ids ) ) {
    220221                        $bp = buddypress();
    … …  
    222223                        $uncached_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, field_id, value, last_updated FROM {$bp->profile->table_name_data} WHERE field_id IN ({$uncached_field_ids_sql}) AND user_id = %d", $user_id ) );
    223224
    224                         // Rekey
     225                        // Rekey.
    225226                        $queried_data = array();
    226227                        foreach ( $uncached_data as $ud ) {
    … …  
    235236                        }
    236237
    237                         // Set caches
     238                        // Set caches.
    238239                        foreach ( $uncached_field_ids as $field_id ) {
    239240
    240241                                $cache_key = "{$user_id}:{$field_id}";
    241242
    242                                 // If a value was found, cache it
     243                                // If a value was found, cache it.
    243244                                if ( isset( $queried_data[ $field_id ] ) ) {
    244245                                        wp_cache_set( $cache_key, $queried_data[ $field_id ], 'bp_xprofile_data' );
    245246
    246247                                // If no value was found, cache an empty item
    247                                 // to avoid future cache misses
     248                                // to avoid future cache misses.
    248249                                } else {
    249250                                        $d               = new stdClass;
    … …  
    259260                }
    260261
    261                 // Now that all items are cached, fetch them
     262                // Now that all items are cached, fetch them.
    262263                foreach ( $field_ids as $field_id ) {
    263264                        $cache_key = "{$user_id}:{$field_id}";
    … …  
    272273         *
    273274         * @param int $user_id ID of the user.
     275         *
    274276         * @return array
    275277         */
    … …  
    316318         * Get the user's field data id by the id of the xprofile field.
    317319         *
    318          * @param int $field_id
    319          * @param int $user_id
     320         * @param int $field_id Field ID being queried for.
     321         * @param int $user_id  User ID associated with field.
     322         *
    320323         * @return int $fielddata_id
    321324         */
    … …  
    328331                        $bp = buddypress();
    329332
    330                         // Check cache first
     333                        // Check cache first.
    331334                        $cache_key = "{$user_id}:{$field_id}";
    332335                        $fielddata = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    … …  
    346349         * Supports multiple user IDs.
    347350         *
    348          * @param int $field_id ID of the field.
    349          * @param int|array $user_ids ID or IDs of user(s).
     351         * @param int            $field_id ID of the field.
     352         * @param int|array|null $user_ids ID or IDs of user(s).
     353         *
    350354         * @return string|array Single value if a single user is queried,
    351          *         otherwise an array of results.
     355         *                      otherwise an array of results.
    352356         */
    353357        public static function get_value_byid( $field_id, $user_ids = null ) {
    … …  
    364368                }
    365369
    366                 // Assemble uncached IDs
     370                // Assemble uncached IDs.
    367371                $uncached_ids = array();
    368372                foreach ( $user_ids as $user_id ) {
    … …  
    373377                }
    374378
    375                 // Prime caches
     379                // Prime caches.
    376380                if ( ! empty( $uncached_ids ) ) {
    377381                        $bp = buddypress();
    … …  
    379383                        $queried_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, field_id, value, last_updated FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$uncached_ids_sql})", $field_id ) );
    380384
    381                         // Rekey
     385                        // Rekey.
    382386                        $qd = array();
    383387                        foreach ( $queried_data as $data ) {
    … …  
    386390
    387391                        foreach ( $uncached_ids as $id ) {
    388                                 // The value was successfully fetched
     392                                // The value was successfully fetched.
    389393                                if ( isset( $qd[ $id ] ) ) {
    390394                                        $d = $qd[ $id ];
    391395
    392396                                // No data found for the user, so we fake it to
    393                                 // avoid cache misses and PHP notices
     397                                // avoid cache misses and PHP notices.
    394398                                } else {
    395399                                        $d = new stdClass;
    … …  
    406410                }
    407411
    408                 // Now that the cache is primed with all data, fetch it
     412                // Now that the cache is primed with all data, fetch it.
    409413                $data = array();
    410414                foreach ( $user_ids as $user_id ) {
    … …  
    413417                }
    414418
    415                 // If a single ID was passed, just return the value
     419                // If a single ID was passed, just return the value.
    416420                if ( $is_single ) {
    417421                        return $data[0]->value;
    418422
    419                 // Otherwise return the whole array
     423                // Otherwise return the whole array.
    420424                } else {
    421425                        return $data;
Note: See TracChangeset for help on using the changeset viewer.