gform_state_lifespan

Description

The gform_state_lifespan filter allows developers to customize the lifespan of the state. By default, this lifespan is set to 2 days (172800 seconds).

Note: it is not recommend increasing the lifespan significantly. A better solution is to exclude the page containing the form from caching or reduce the cache lifetime (TTL) for that page.

Usage

add_filter( 'gform_state_lifespan', 'my_function_name' );

Parameters

ParameterTypeDescription
$lifespanintThe state lifespan in seconds. Default is 172800 (2 days).
$form_idintThe ID of the form the state is for.

Examples

Change the state lifespan to 1 week.

add_filter( 'gform_state_lifespan', function () {
	return WEEK_IN_SECONDS;
} );

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?

Source Code

This filter is located in Gravity_Forms\Gravity_Forms\Form_Display\State\State_Handler::is_stale() in includes/form-display/state/class-state-handler.php

Since

This filter was added in Gravity Forms 3.1.1