Description
The gravityflow_get_users_args filter allows changing the default number of users returned in the user query. It
return an array of arguments to be used by WordPress get_users function.
Parameters
Parameter | Type | Details |
---|---|---|
$args | Array | An associative array of arguments. |
$form_id | Integer | The current form ID |
$field | Field or Null | The field which the user choices relate to. If null, it is for the assignees list in step settings. |
Usage
There are 3 variations of this filter with the same parameters that you could hook to depending on which field/scenario you require.
1 2 3 | add_filter( 'gravityflow_get_users_args' , 'sh_get_users_args_example' , 10, 2); add_filter( 'gravityflow_get_user_args_assignee_field' , 'sh_get_users_args_example_assignee' , 10, 2); add_filter( 'gravityflow_get_users_args_user_field' , 'sh_get_users_args_example_users' , 10, 2); |
Examples
Modify the user query for all Gravity Flow related requests
1 2 3 4 5 6 | add_filter( 'gravityflow_get_users_args' , 'sh_gravityflow_get_users_args' ); function sh_gravityflow_get_users_args( $args ) { // default is array( 'number' => 1000, 'orderby' => 'display_name' ) return array ( 'number' => 1500, 'orderby' => 'display_name' ); } |
Modify the user query for assignee field related requests
1 2 3 4 5 6 | add_filter( 'gravityflow_get_users_args_assignee_field' , 'sh_gravityflow_get_users_args_assignee_field' , 10, 3 ); function sh_gravityflow_get_users_args_assignee_field( $args , $form_id , $field ) { // default is array( 'number' => 1000, 'orderby' => 'display_name' ) return array ( 'number' => 1500, ); } |
Limit assignee field results by role
1 2 3 4 5 6 | add_filter( 'gravityflow_get_users_args_assignee_field' , 'sh_gravityflow_get_users_args_assignee_field' , 10 , 3 ); function sh_gravityflow_get_users_args_assignee_field( $args , $form_id , $field ) { // default is array( 'number' => 1000, 'orderby' => 'display_name' ) return array ( 'number' => 1500, 'orderby' => 'display_name' , 'role' => 'administrator' ); } |
Modify the user query for user field related requests by multiple roles.
1 2 3 | add_filter( 'gravityflow_get_users_args_user_field' , 'sh_gravityflow_get_users_args_user_field' , 10, 3 ); function sh_gravityflow_get_users_args_user_field( $args , $form_id , $field ) { return array ( 'number' => 5, 'orderby' => 'display_name' , 'role__in' => array ( 'subscriber' , 'administrator' )); } |
Modify the user query for user field related requests limited to 5,000
1 2 3 4 5 | add_filter( 'gravityflow_get_users_args_user_field' , 'sh_gravityflow_get_users_args_user_field' , 10, 3 ); function sh_gravityflow_get_users_args_user_field( $args , $form_id , $field ) { return array ( 'number' => 5000, 'orderby' => 'display_name' , 'role' => 'subscriber' ); } |
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?