Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/07/2015 02:30:31 PM (9 years ago)
Author:
boonebgorges
Message:

Introduce cache support for xprofile fields.

xprofile_get_field() will now look in the cache before returning a
BP_XProfile_Field object (via the new BP_XProfile_Field::get_instance()),
and will populate the cache if necessary. It's strongly recommended to use
xprofile_get_field() when fetching individual existing fields, instead of
creating new BP_XProfile_Field objects directly.

BP_XProfile_Group::get() now leverages the field cache too. Instead of a
SELECT * query, it fetches a list of matching field IDs SELECT id, and
populates the full field objects from the cache, if available. The fields
property of BP_XProfile_Group objects is now an array of BP_XProfile_Field
objects, not stdClass. See #6358.

Props boonebgorges, r-a-y.
See #6638.

File:
1 edited

Legend:

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

    r10163 r10198  
    276276}
    277277
    278 function xprofile_get_field( $field_id ) {
    279     return new BP_XProfile_Field( $field_id );
     278/**
     279 * Get a profile field object.
     280 *
     281 * @param int|object $field ID of the field or object representing field data.
     282 * @return BP_XProfile_Field|null Field object if found, otherwise null.
     283 */
     284function xprofile_get_field( $field ) {
     285    if ( $field instanceof BP_XProfile_Field ) {
     286        $_field = $field;
     287    } elseif ( is_object( $field ) ) {
     288        $_field = new BP_XProfile_Field();
     289        $_field->fill_data( $field );
     290    } else {
     291        $_field = BP_XProfile_Field::get_instance( $field );
     292    }
     293
     294    if ( ! $_field ) {
     295        return null;
     296    }
     297
     298    return $_field;
    280299}
    281300
Note: See TracChangeset for help on using the changeset viewer.