gravityflow_assignee_field_{type}

Description

The Assignee Field displays all roles, users, and fields by default. The Form Editor settings allow each type to be turned off, but if you need to filter the items further, you can use the following filters.

Usage

1
2
3
add_filter( 'gravityflow_assignee_field_users', 'flow_assignee_field_type_users_example', 10, 3);
add_filter( 'gravityflow_assignee_field_fields', 'flow_assignee_field_type_fields_example', 10, 3);
add_filter( 'gravityflow_assignee_field_roles', 'flow_assignee_field_type_roles_example', 10, 3);

Parameters

ParameterTypeDetails
$choicesArrayAn array of choices based on the assignee/filter type (users, roles, fields).
$form_idIntegerThe current form ID.
$fieldFieldThe current assignee field.

Examples

Assignee by role – Modify the list of roles

Use the gravityflow_assignee_field_roles filter to modify the list of roles. The following example ensures that only two roles are displayed:

1
2
3
4
5
6
7
8
add_filter( 'gravityflow_assignee_field_roles', 'sh_gravityflow_assignee_field_roles', 10, 3 );
function sh_gravityflow_assignee_field_roles( $roles, $form_id, $field ) {
    $roles = array(
        array( 'value' => 'role|administrator', 'text' => 'Administrators' ),
        array( 'value' => 'role|editor', 'text' => 'Editors' ),
    );
    return $roles;
}

Assignee by user – Modify the list of users for all fields

Use the gravityflow_assignee_field_users filter to modify the list of users.

1
2
3
4
5
6
7
8
add_filter( 'gravityflow_assignee_field_users', 'sh_gravityflow_assignee_field_users', 10, 3 );
function sh_gravityflow_assignee_field_users( $users, $form_id, $field ) {
    $users = array(
        array( 'value' => 'user_id|1', 'text' => 'Joe' ),
        array( 'value' => 'user_id|2', 'text' => 'Jane' ),
    );
    return $users;
}

Assignee by user – Modify the list of users limited to a specific field

Use the gravityflow_assignee_field_users filter to modify the list of fields for only one field on one form.

1
2
3
4
5
6
7
8
9
10
    add_filter( 'gravityflow_assignee_field_users', 'sh_gravityflow_assignee_field_users', 10, 3 );
function sh_gravityflow_assignee_field_users( $choices, $form_id, $field ) {
    if ( $form_id == 142 && $field->id == 3 ) {
        $choices = array(
            array( 'value' => 'user_id|1', 'text' => 'Joe' ), // The text element can be anything you like.
            array( 'value' => 'user_id|2', 'text' => 'Jane' ),
        );
    }
    return $choices;
}

Assignee by user – Modify the list to display email addresses

Use the gravityflow_assignee_field_users filter to display a list of email assignees instead of users.

1
2
3
4
5
6
7
8
9
10
    add_filter( 'gravityflow_assignee_field_users', 'sh_gravityflow_assignee_field_users', 10, 3 );
function sh_gravityflow_assignee_field_users( $choices, $form_id, $field ) {
    if ( $form_id == 142 && $field->id == 3 ) {
        $choices = array(
            array( 'value' => 'email|someone@domain.com', 'text' => 'Joe' ), // The text element can be anything you like.
            array( 'value' => 'email|another@company.com, '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?