Description
Filters through and allows modification of the forms displayed in the Form Switcher dropdown.
Parameters
- $forms array
An array containing the last ten forms sorted by most recently edited by the logged-in user.
Examples
Exclude a single form from search results
This example shows how to prevent form ID 10 from appearing in the Form Switcher search results.
add_filter( 'gform_form_switcher_forms', 'exclude_ten' );
function exclude_ten( $forms ) {
$forms = array_filter( $forms, static function ( $element ) {
return $element->id !== "10";
});
return $forms;
}
Include all active forms on page load
This example shows how you can include all active forms in the Form Switcher on page load.
Note: this can impact admin performance for sites with lots of forms and even result in critical/fatal PHP memory errors.
add_filter( 'gform_form_switcher_forms', function ( $forms ) {
if ( wp_doing_ajax() ) {
return $forms;
}
$is_active = true;
$sort_column = 'title'; // or 'id', 'date_created', or 'date_updated'.
$sort_direction = 'ASC'; // or 'DESC'.
$is_trash = false;
return GFFormsModel::get_forms( $is_active, $sort_column, $sort_direction, $is_trash );
} );
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?
Since
This filter was added in Gravity Forms version 2.4.16 and updated in Gravity Forms version 2.9.6.
Source Code
This filter is located in GFForms::form_switcher in gravityforms.php and includes/form-switcher/endpoints/class-gf-form-switcher-endpoint-get-forms.php