BP_XProfile_Field_Type_WordPress::set_field_value( boolean $retval = false, array $field_args = array() )

Sets the WordPress field value.


Parameters Parameters

$retval

(boolean) (Optional) Whether to shortcircuit the $bp->profile->table_name_data table. Default false.

Default value: false

$field_args

(array) (Optional) An array of arguments.

  • 'field_type_obj'
    (object) Field type object.
  • 'field'
    (BP_XProfile_Field) Field object.
  • 'user_id'
    (integer) The user ID.
  • 'value'
    (mixed) Value passed to xprofile_set_field_data().
  • 'is_required'
    (boolean) Whether or not the field is required.

Default value: array()


Top ↑

Return Return

(boolean) Whether to shortcircuit the $bp->profile->table_name_data table.


Source Source

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

	public function set_field_value( $retval = false, $field_args = array() ) {
		// Check the wp_user_key is valid and supported.
		if ( ! isset( $field_args['field']->type_obj->wp_user_key ) || $this->wp_user_key !== $field_args['field']->type_obj->wp_user_key || ! in_array( $field_args['field']->type_obj->wp_user_key, $this->supported_keys, true ) ) {
			return false;
		}

		$wp_user_field_value = $this->sanitize_for_db( $field_args['value'] );
		$bp_displayed_user   = bp_get_displayed_user();

		if ( isset( $bp_displayed_user->updated_keys ) ) {
			$bp_displayed_user->updated_keys[ $this->wp_user_key ] = $wp_user_field_value;
			$retval = true;
		} else {
			$retval = wp_update_user(
				array(
					'ID'               => (int) $field_args['user_id'],
					$this->wp_user_key => $wp_user_field_value,
				)
			);
		}

		if ( ! is_wp_error( $retval ) ) {
			$retval = true;
		}

		return $retval;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
8.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.