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

Populate a profile field object.

Description

Parameters

$id

(int) (Required) Field ID.

$user_id

(int|null) (Optional) User ID.

Default value: null

$get_data

(bool) (Optional) Get data.

Default value: true

Source

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

	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.