BP_XProfile_Field::populate( int $id, int|null $user_id = null, bool $get_data = true )

Populate a profile field object.

Description

Parameters

$id

(Required) Field ID.

$user_id

(Optional) User ID.

Default value: null

$get_data

(Optional) Get data.

Default value: true

Source

File: bp-xprofile/classes/class-bp-xprofile-field.php

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
public function populate( $id, $user_id = null, $get_data = true ) {
    global $wpdb, $userdata;
 
    if ( empty( $user_id ) ) {
        $user_id = isset( $userdata->ID ) ? $userdata->ID : 0;
    }
 
    $field = wp_cache_get( $id, 'bp_xprofile_fields' );
    if ( false === $field ) {
        $bp = buddypress();
 
        $field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id ) );
 
        if ( ! $field ) {
            return false;
        }
 
        wp_cache_add( $id, $field, 'bp_xprofile_fields' );
    }
 
    $this->fill_data( $field );
 
    if ( ! empty( $get_data ) && ! empty( $user_id ) ) {
        $this->data = $this->get_field_data( $user_id );
    }
}

Changelog

Changelog
Version Description
BuddyPress 1.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.