gravityflow_user_field

Description

The User Field, by default, will display all users. If you need to filter the items you can use the following filter gravityflow_user_field

Parameters

ParameterTypeDetails
$usersArrayThe users array
$form_id IntegerId of the current form
$fieldFieldThe current field

Examples

Display only two users.

add_filter( 'gravityflow_user_field', 'sh_gravityflow_user_field', 10, 3 );
function sh_gravityflow_user_field( $users, $form_id, $field ) {
	$users = array(
		// value = WordPress user account ID.
		array( 'value' => '1', 'text' => 'Joe' ), 
		array( 'value' => '2', 'text' => 'Jane' ),
	);
	return $users;
}

Modify the user list for only one form

add_filter( 'gravityflow_user_field', 'sh_gravityflow_user_field', 10, 3 );
function sh_gravityflow_user_field( $choices, $form_id, $field ) {
	if ( $form_id == 142 && $field->id == 3 ) {
		$choices = array(
			array( 'value' => '1', 'text' => 'Joe' ), // The text element can be anything you like.
			array( 'value' => '2', 'text' => 'Jane' ),
		);
	}
	return $choices;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?