Using Gravity Forms ‘gform_visibility_options’ PHP filter

The gform_visibility_options filter in Gravity Forms allows you to modify or remove default visibility options and add custom visibility options.

Usage

add_filter('gform_visibility_options', 'my_function', 10);

Parameters

  • $options (array): An array of visibility options.
  • $label (string): The label of the visibility option; displayed in the field’s Visibility setting.
  • $value (string): The value of the visibility option; will be saved to the form meta.
  • $description (string): The description of the visibility option; used in the Visibility setting tooltip.

More information

See Gravity Forms Docs: gform_visibility_options

Examples

Add a custom visibility option

This example adds a custom visibility option to the form.

add_filter('gform_visibility_options', 'my_custom_visibility_options');
function my_custom_visibility_options($options) {
    $options[] = array(
        'label' => __('Custom Option'),
        'value' => 'custom',
        'description' => __('This is a description of my custom visibility option. It will show up in the Visibility setting tooltip.')
    );
    return $options;
}

Remove a visibility option

This example removes the “Hidden” visibility option from the form.

add_filter('gform_visibility_options', 'remove_hidden_visibility_option');
function remove_hidden_visibility_option($options) {
    foreach ($options as $key => $option) {
        if ($option['value'] == 'hidden') {
            unset($options[$key]);
        }
    }
    return $options;
}

Modify an existing visibility option

This example modifies the “Administrative” visibility option’s label and description.

add_filter('gform_visibility_options', 'modify_administrative_visibility_option');
function modify_administrative_visibility_option($options) {
    foreach ($options as &$option) {
        if ($option['value'] == 'administrative') {
            $option['label'] = __('New Administrative Label');
            $option['description'] = __('This is a new description for the Administrative visibility option.');
        }
    }
    return $options;
}

Add multiple custom visibility options

This example adds two custom visibility options to the form.

add_filter('gform_visibility_options', 'add_multiple_custom_visibility_options');
function add_multiple_custom_visibility_options($options) {
    $custom_options = array(
        array(
            'label' => __('Custom Option 1'),
            'value' => 'custom_option_1',
            'description' => __('This is a description of Custom Option 1.')
        ),
        array(
            'label' => __('Custom Option 2'),
            'value' => 'custom_option_2',
            'description' => __('This is a description of Custom Option 2.')
        )
    );
    return array_merge($options, $custom_options);
}