gravityflow_get_users_args

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

ParameterTypeDetails
$argsArrayAn associative array of arguments.
$form_idIntegerThe current form ID
$fieldField or NullThe 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

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' );
}
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'  );
}
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')); }
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?