Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/06/2014 07:38:35 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce bp_xprofile_fullname_field_id() and use in query building throughout BP

There are many places throughout BuddyPress where it's necessary to query for
user fullnames. When XProfile is active, part of this process involves
determining the ID of the fullname field. Historically, this has been done by
querying for the ID of a field corresponding to the 'name' bp_xprofile_fullname_field_name().
Creating a standalone function for this allows us to centralize persistent
caching for the field ID.

As a side note, the fact that we do this query at all is a little farcical.
The fullname field is essentially necessarily tied to field #1 (due to some
hardcoding in the xprofile schema definition as well as bp-xprofile-admin.php).
We rely on the Name setting only for historical reasons, which probably didn't
even make all that much sense at the time. At some point, a serious review
should be done, and references to the fullname field id standardized (either
all hardcoded, or all not hardcoded).

See #5362

File:
1 edited

Legend:

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

    r7730 r7812  
    438438        return false;
    439439
    440     $fullname = xprofile_get_field_data( bp_xprofile_fullname_field_name(), $user_id );
     440    $fullname = xprofile_get_field_data( bp_xprofile_fullname_field_id(), $user_id );
    441441    $space    = strpos( $fullname, ' ' );
    442442
     
    474474        return;
    475475
    476     xprofile_set_field_data( bp_xprofile_fullname_field_name(), $user->ID, $user->display_name );
     476    xprofile_set_field_data( bp_xprofile_fullname_field_id(), $user->ID, $user->display_name );
    477477}
    478478add_action( 'user_profile_update_errors', 'xprofile_sync_bp_profile', 10, 3 );
     
    626626
    627627/**
     628 * Return the field ID for the Full Name xprofile field.
     629 *
     630 * @since BuddyPress (2.0.0)
     631 *
     632 * @return int Field ID.
     633 */
     634function bp_xprofile_fullname_field_id() {
     635    $id = wp_cache_get( 'fullname_field_id', 'bp_xprofile' );
     636
     637    if ( false === $id ) {
     638        global $wpdb;
     639
     640        $bp = buddypress();
     641        $id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", bp_xprofile_fullname_field_name() ) );
     642
     643        wp_cache_set( 'fullname_field_id', $id, 'bp_xprofile' );
     644    }
     645
     646    return absint( $id );
     647}
     648
     649/**
    628650 * Return the field name for the Full Name xprofile field
    629651 *
Note: See TracChangeset for help on using the changeset viewer.