XProfile_Data::set( $args,  $assoc_args )

Set profile data for a user.


Description Description

Top ↑

OPTIONS OPTIONS

–user-id= : Identifier for the user. Accepts either a user_login or a numeric ID.

–field-id= : Identifier for the field. Accepts either the name of the field or a numeric ID.

–value= : Value to set.

Top ↑

EXAMPLE EXAMPLE

$ wp bp xprofile data set --user-id=45 --field-id=120 --value=teste
Success: Updated XProfile field "Field Name" (ID 120) with value  "teste" for user user_login (ID 45).

Source Source

File: cli/src/xprofile-data.php

	public function set( $args, $assoc_args ) {
		$user     = $this->get_user_id_from_identifier( $assoc_args['user-id'] );
		$field_id = $this->get_field_id( $assoc_args['field-id'] );
		$field    = new \BP_XProfile_Field( $field_id );

		if ( empty( $field->name ) ) {
			WP_CLI::error( 'XProfile field not found.' );
		}

		$value = $assoc_args['value'];

		if ( 'checkbox' === $field->type ) {
			$value = explode( ',', $assoc_args['value'] );
		}

		$updated = xprofile_set_field_data( $field->id, $user->ID, $value );

		if ( ! $updated ) {
			WP_CLI::error( 'Could not set profile data.' );
		}

		WP_CLI::success(
			sprintf(
				'Updated XProfile field "%s" (ID %d) with value "%s" for user %s (ID %d).',
				$field->name,
				$field->id,
				$assoc_args['value'],
				$user->user_nicename,
				$user->ID
			)
		);
	}


Top ↑

User Contributed Notes User Contributed Notes

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