BP_XProfile_ProfileData::populate( int $field_id, int $user_id )

Populates the XProfile profile data.

Description

Parameters

$field_id

(int) (Required) Field ID to populate.

$user_id

(int) (Required) User ID to populate for.

Source

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

	public function populate( $field_id, $user_id ) {
		global $wpdb;

		$cache_key   = "{$user_id}:{$field_id}";
		$profiledata = wp_cache_get( $cache_key, 'bp_xprofile_data' );

		if ( false === $profiledata ) {
			$bp = buddypress();

			$sql         = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
			$profiledata = $wpdb->get_row( $sql );

			if ( $profiledata ) {
				wp_cache_set( $cache_key, $profiledata, 'bp_xprofile_data' );
			}
		}

		if ( $profiledata ) {
			$this->id           = (int) $profiledata->id;
			$this->user_id      = (int) $profiledata->user_id;
			$this->field_id     = (int) $profiledata->field_id;
			$this->value        = stripslashes( $profiledata->value );
			$this->last_updated = $profiledata->last_updated;

		} else {
			// When no row is found, we'll need to set these properties manually.
			$this->field_id	    = (int) $field_id;
			$this->user_id	    = (int) $user_id;
		}
	}

Changelog

Changelog
Version Description
BuddyPress 1.0.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.