The gform_block_form_forms Gravity Forms PHP filter allows you to modify the list of available forms displayed in the Form block in the WordPress block editor.
On this pageJump to a section
Usage
To use the filter, add the following code to your theme’s functions.php file or a custom functions plugin:
add_filter('gform_block_form_forms', 'your_function_name');
Parameters
$forms(array) – A collection of active forms on the site, sorted alphabetically by title. Each form in the array contains the following properties:id,title, andhasConditionalLogic.
More information
See Gravity Forms Docs: gform_block_form_forms
Examples
Remove specific form
This example removes form with ID 1 from the list of forms that can be embedded using the Form block in the WordPress block editor.
add_filter('gform_block_form_forms', function ($forms) {
foreach ($forms as $key => $form) {
if ($form['id'] == 1) {
unset($forms[$key]);
break;
}
}
return array_values($forms);
});
Sort list by newest to oldest
This example sorts the list of forms with the most recent forms listed at the top (requires PHP 7 or greater).
add_filter('gform_block_form_forms', function ($forms) {
usort($forms, function($a, $b) {
return $b['id'] <=> $a['id'];
});
return $forms;
});
Filter forms by title
This example filters the forms list to only include forms with titles containing the word “survey”.
add_filter('gform_block_form_forms', function ($forms) {
return array_filter($forms, function ($form) {
return strpos(strtolower($form['title']), 'survey') !== false;
});
});
Add custom form data
This example adds custom form data to the array of forms, such as a form’s creation date.
add_filter('gform_block_form_forms', function ($forms) {
foreach ($forms as &$form) {
$form_object = GFAPI::get_form($form['id']);
$form['date_created'] = $form_object['date_created'];
}
return $forms;
});
Exclude forms with conditional logic
This example filters the forms list to exclude forms that have conditional logic.
add_filter('gform_block_form_forms', function ($forms) {
return array_filter($forms, function ($form) {
return !$form['hasConditionalLogic'];
});
});