XProfile_Field::create( $args,  $assoc_args )

Create an XProfile field.


Description Description

Top ↑

OPTIONS OPTIONS

Top ↑

[–type=] : Field type. [–type=] : Field type.

Top ↑

default: textbox default: textbox

–field-group-id= : ID of the field group where the new field will be created.

–name= : Name of the new field.

[–porcelain] : Output just the new field id.

Top ↑

EXAMPLES EXAMPLES

$ wp bp xprofile field create --type=checkbox --field-group-id=508 --name="Field Name"
Success: Created XProfile field "Field Name" (ID 24564).

$ wp bp xprofile field add --field-group-id=165 --name="Another Field"
Success: Created XProfile field "Another Field" (ID 5465).

Source Source

File: cli/src/xprofile-field.php

	public function create( $args, $assoc_args ) {
		// Check this is a non-empty, valid field type.
		if ( ! in_array( $assoc_args['type'], (array) buddypress()->profile->field_types, true ) ) {
			WP_CLI::error( 'Not a valid field type.' );
		}

		$create_args = array(
			'type'           => $assoc_args['type'],
			'name'           => $assoc_args['name'],
			'field_group_id' => $assoc_args['field-group-id'],
		);

		$field_id = xprofile_insert_field( $create_args );
		if ( ! $field_id ) {
			WP_CLI::error( 'Could not create XProfile field.' );
		}

		if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
			WP_CLI::log( $field_id );
		} else {
			$field = new \BP_XProfile_Field( $field_id );

			WP_CLI::success(
				sprintf(
					'Created XProfile field "%s" (ID %d).',
					$field->name,
					$field->id
				)
			);
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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