gform_filters_get_users

gform_filters_get_users

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to control the list of users available in the filters on the entry list, export entries conditional logic and results pages.
Usage
add_filter( 'gform_filters_get_users', 'your_function_name' );

Parameters

$args array
array( 'number' => 200 )
The array of options to use when filtering the users. See the get_users() Function Reference on the WordPress codex for further details: https://developer.wordpress.org/reference/functions/get_users/

Examples
This example lists only the users from the role 「administrator」.
add_filter( 'gform_filters_get_users', 'filters_get_users_args' );
function api_get_users_args( $args ) {
$args['role'] = 'administrator';
return $args;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
apply_filters( 'gform_filters_get_users', array( 'number' => 200 ) )

This action hook is located in GFCommon::get_entry_info_filter_columns() in common.php

gform_field_filters

gform_field_filters

DescriptionUsageParametersExamples1. Add a custom payment status2. Add an operator to a specific fieldPlacementSinceSource Code

Description
The 「gform_field_filters」 filter in Gravity Forms enables the filter settings to be overridden for the form fields, entry properties, and entry meta.
Usage
1add_filter( 'gform_field_filters', 'your_function_name', 10, 2 );

Parameters

$field_filters array
The form field, entry properties, and entry meta filter settings.

$form Form Object
The form object.

Examples
1. Add a custom payment status
123456789101112131415161718192021add_filter( 'gform_field_filters', 'update_filters', 10, 2 );function update_filters( $field_filters, $form ){  foreach ( $field_filters as &$filter ){    if ( $filter['key'] == 'payment_status' ){        //add custom payment status        $values = $filter['values'];        $status_exists = false;        foreach( $values as &$value ){            if ( $value['text'] == 'Test Status' ){                $status_exists = true;            }        }        if ( ! $status_exists ){            //add status            array_push( $values, array( 'text' => 'Test Status', 'value' => 'Test Status' ) );            $filter['values'] = $values;        }    }  }  return $field_filters;}
2. Add an operator to a specific field
12345678910add_filter( 'gform_field_filters', function ( $field_filters, $form ) {   foreach ( $field_filters as $filter ) {      if ( rgar( $filter, 'key' ) == '2' ) {         $filter['operators'][] = 'isnot';         break;      }   }    return $field_filters;}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 2.3.1.16.
Source Code
This filter is located in GFCommon::get_field_filter_settings() in common.php

gform_form_notification_page

gform_form_notification_page

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Filters the form to be used in the notification page.
Usage
The following would apply to all forms:
add_filter( 'gform_form_notification_page', 'your_function_name', 10, 2 );

To target a specific form, append the form id to the hook name. (format: gform_form_notification_page_FORMID)
add_filter( 'gform_form_notification_page_1', 'your_function_name', 10, 2 );

Parameters

$form Form Object
The current form.

$notification_id int
The notification id.

Example
The example below assumes a master form has been created (id 79) with all the notifications needed. When going to a different form and editing a notification, all the ones from the master form will be saved to your new form. Any changes made to notifications on your new form would be overwritten by the master form』s notifications once a notification is saved. This can be used to control the notifications on forms.
add_filter( 'gform_form_notification_page', 'use_master_form', 10, 2 );
function use_master_form( $form, $notification_id ){
if ($form['id'] == '45'){
//use master form with notifications to be used for all forms.
$form = GFFormsModel::get_form_meta(79);
}

return $form;

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 1.8.6.
Source Code
This filter is located in GFNotification::notification_edit_page() in notification.php.

gform_file_permission

gform_file_permission

DescriptionUsageParametersExamplesSource Code

Description
This filter is executed when uploading a file. It can be used to change the default permissions of uploaded files.
Usage
Applies to all forms.
1add_filter( 'gform_file_permission', 'set_file_permission', 10, 2 );
Parameters

$permission string
The file permission to be filtered (i.e. 0755).

$path string
The full file path.

Examples
This example changes the permissions of uploaded files to 0755.
12345add_filter( 'gform_file_permission', 'set_file_permission', 10, 2 );function set_file_permission( $permission, $path ) {    // Note the octal value with the leading zero. Don't return a string.    return 0755;}
Source Code
This filter is located in GFFormsModel::set_permissions() in forms_model.php.

gform_form_editor_can_field_be_added

gform_form_editor_can_field_be_added

DescriptionUsageParametersExampleSource Code

Description
This filter fires on the Form Editor page when a field button is clicked or dragged on to the form, it can be used to prevent a field being added to the form if the conditions you define are not met.
Usage
1234gform.addFilter('gform_form_editor_can_field_be_added', function (canFieldBeAdded, type) {    // return false to prevent a field being added.    return canFieldBeAdded;});

Parameters

canFieldBeAdded boolean
Defaults to true.

type string
The current field type.

Example
This example uses the gform_admin_pre_render filter to load the hook on the form editor page.
1234567891011121314151617181920add_filter( 'gform_admin_pre_render', function ( $form ) {    echo GFCommon::is_form_editor() ? "        " : '';     //return the form object from the php hook    return $form;} );
Source Code
This filter is located in js.php

gform_field_standard_settings

gform_field_standard_settings

DescriptionUsageParametersExamplesPlacementSource Code

Description

Use this action to create new field settings under the Standard tab. Useful when implementing a new custom field type that requires custom settings.

Usage

add_action( 'gform_field_standard_settings', 'my_standard_settings', 10, 2 );

Parameters

$index integerSpecify the position that the settings should be displayed. For a list of all available positions, search form_detail.php for 「gform_field_standard_settings」 or review the Common Field Settings article.$form_id integerThe ID of the form from which the entry value was submitted.

Examples

This example creates a new standard setting for Single Line Text fields on the field』s General tab at position 25 (right after the Field Label setting), that specifies if the field data should be encrypted.

add_action( 'gform_field_standard_settings', 'my_standard_settings', 10, 2 );
function my_standard_settings( $position, $form_id ) {

//create settings on position 25 (right after Field Label)
if ( $position == 25 ) {
?>




  • Encryption

    Check this box to encrypt this field's data";
    return $tooltips;
    }

    Placement

    This code should be placed in the functions.php file of your active theme.

    Source Code

    This filter is located in form_detail.php.

    gform_form_settings_menu

    gform_form_settings_menu

    DescriptionUsageParametersExamplesSource Code

    Description

    Add new or modify default menu items which will appear in the Form Settings section menu.

    Usage

    add_filter( 'gform_form_settings_menu', 'my_custom_function' );

    Parameters

    $menu_items arrayAn array of menu items to be displayed on the Form Settings page menu.

    Examples

    This example demonstrates how you can add a custom menu item to the Form Settings page menu. It also demonstrates (with the use of the gform_form_settings_page_view) how to display content for this page when selected.

    // add a custom menu item to the Form Settings page menu
    add_filter( 'gform_form_settings_menu', 'my_custom_form_settings_menu_item' );
    function my_custom_form_settings_menu_item( $menu_items ) {

    $menu_items[] = array(
    'name' => 'my_custom_form_settings_page',
    'label' => __( 'My Custom Form Settings Page' ),
    'icon' => 'dashicons-flag dashicons'
    );

    return $menu_items;
    }

    // handle displaying content for our custom menu when selected
    add_action( 'gform_form_settings_page_my_custom_form_settings_page', 'my_custom_form_settings_page' );
    function my_custom_form_settings_page() {

    GFFormSettings::page_header();

    echo 'My Custom Form Settings!';

    GFFormSettings::page_footer();

    }

    Source Code

    This filter is located in GFFormSettings::get_tabs() in form_settings.php.

    gform_filters_pre_results

    gform_filters_pre_results

    DescriptionUsageParametersExamplesPlacementSource Code

    Description
    Use this filter to modify the filters used in the drop down list of fields in the admin results page. The results page is currently only used by add-ons that implement the Add-On Framework.
    Usage
    1add_filter( 'gform_filters_pre_results', 'your_function_name', 10, 2 );

    Parameters

    $filter_settings array
    The array of filters.

    $form Form Object
    The form object.

    Examples
    This example removes payment related info fields from the filters.
    123456789add_filter( 'gform_filters_pre_results', 'remove_payment_filters', 10, 2 );function remove_payment_filters( $filter_settings, $form ) {    foreach ( $filters as $i => $filter ) {        if ( in_array( $filter_settings['key'], array( 'payment_amount', 'payment_date', 'payment_status', 'transaction_id' ) ) ) {            unset( $filter_settings[ $i ] );        }    }    return $filter_settings;}
    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    1apply_filters( 'gform_filters_pre_results', $filter_settings, $form );
    This filter is located in GFResults::results_page() in includes/addon/class-gf-results.php.

    gform_field_groups_form_editor

    gform_field_groups_form_editor

    DescriptionUsageParametersExamplePlacementSource Code

    Description
    The 「gform_field_groups_form_editor」 filter in Gravity Forms is used to modify the field groups in the Form Editor before fields are added, allowing control over what displays.
    Usage
    add_filter( 'gform_field_groups_form_editor', 'your_function_name', 10, 1 );

    Parameters

    $field_groups array
    The field groups, including group name, label and fields.

    Example
    This example changes the label for Standard Fields to Testing.
    add_filter( 'gform_field_groups_form_editor', 'change_title', 10, 1 );
    function change_title( $field_groups ){
    foreach ( $field_groups as &$group ){
    if ( $group['name'] == 'standard_fields' ){
    $group['label'] = 'Testing';
    }
    }
    return $field_groups;
    }

    Placement
    Your code snippet should be placed in the functions.php file of your active theme.
    Source Code
    This filter is located in GFFormDetail::get_field_groups() in gravityforms/form_detail.php.

    gform_form_post_get_meta

    gform_form_post_get_meta

    DescriptionUsageParametersExamples1. Populate checkbox field2. Return admin labels in REST API requestPlacementSource CodeSince

    Description
    This filter can be used to manipulate the Form Object; it is executed when the form meta is retrieved. Any changes made to the form object via this filter would affect form render, validation, submission, and the form in the admin.
    When using this filter you wouldn』t need to make the same change using the gform_pre_render, gform_pre_validation, gform_pre_submission_filter, or gform_admin_pre_render filters.
    Usage
    The following would apply to all forms.
    1add_filter( 'gform_form_post_get_meta', 'your_function_name' );
    To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_form_post_get_meta_FORMID)
    1add_filter( 'gform_form_post_get_meta_6', 'your_function_name' );

    Parameters

    $form Form Object
    The current form to be filtered.

    Examples
    1. Populate checkbox field
    The following example dynamically populates a checkbox field with a list of published posts
    12345678910111213141516171819202122232425262728293031323334353637//NOTE: update the '221' to the ID of your formadd_filter( 'gform_form_post_get_meta_221', 'populate_checkbox' );function populate_checkbox( $form ) {     foreach( $form['fields'] as &$field )  {         //NOTE: replace 3 with your checkbox field id        $field_id = 3;        if ( $field->id != $field_id ) {            continue;        }         // you can add additional parameters here to alter the posts that are retreieved        // more info: [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)        $posts = get_posts( 'numberposts=-1&post_status=publish' );         $input_id = 1;        foreach( $posts as $post ) {             //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)            if ( $input_id % 10 == 0 ) {                $input_id++;            }             $choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );            $inputs[] = array( 'label' => $post->post_title, 'id' => "{$field_id}.{$input_id}" );             $input_id++;        }         $field->choices = $choices;        $field->inputs = $inputs;     }     return $form;}
    2. Return admin labels in REST API request
    The following example shows how a form, in this case id #93, can be configured to return the admin labels when getting entries via the REST API with the _labels argument.
    1234567891011121314add_filter( 'gform_form_post_get_meta_93', function ( $form ) {    if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST  || ! rgget( '_labels' ) ) {        return $form;    }     foreach ( $form['fields'] as $field ) {        if ( $field->displayOnly ) {            continue;        }        $field->set_context_property( 'use_admin_label', true );    }     return $form;} );
    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    1$form = gf_apply_filters( 'gform_form_post_get_meta', $form_id, $form );
    This filter is located in GFFormDisplay::get_form_meta() in form_display.php.
    Since
    The form specific version of this filter was added in Gravity Forms 1.9.6.