gform_block_form_forms

Description

The gform_block_form_forms filter allows the list of available forms displayed in the Form block to be overridden.

Usage

The filter would be used like so:

add_filter( 'gform_block_form_forms', 'your_function_name' );

Parameters

  • $forms array
    A collection of active forms on site. The array for each form contains the following properties: id, title, and hasConditionalLogic. As of Gravity Forms 2.5, this array is sorted alphabetically by title. It was previously sorted incrementally by id.

Examples

1. Remove

This example removes form id 1 from the list of forms which 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 );

} );

2. Sort list newest to oldest

This example sorts the list of forms with most recent forms listed at the 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;

} );

Placement

This code should be placed in the functions.php file of your active theme or a custom functions plugin.

Since

This filter was added in Gravity Forms v2.4.22.5.

Source Code

This filter is located in GF_Block_Form::get_forms() in includes/blocks/class-gf-block-form.php.