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
Parameter | Type | Details |
---|---|---|
$users | Array | The users array |
$form_id | Integer | Id of the current form |
$field | Field | The current field |
Examples
Display only two users.
1 2 3 4 5 6 7 8 9 | 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
1 2 3 4 5 6 7 8 9 10 | 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?