Using Gravity Forms ‘gform_export_max_execution_time’ PHP filter

The gform_export_max_execution_time Gravity Forms PHP filter allows you to change the maximum execution time for exporting entries.

Usage

To use this filter, you need to add the following code snippet to your WordPress website’s functions.php file or custom plugin:

add_filter( 'gform_export_max_execution_time', 'your_function_name', 10, 2 );

In the above code, replace 'your_function_name' with the name of your custom function that will modify the maximum execution time for exporting entries. You can also change the priority of the filter by modifying the 10 parameter.

Parameters

The gform_export_max_execution_time filter accepts two parameters:

  • $max_execution_time (integer): The number of seconds for which each request should run. Defaults to 20.
  • $form (Form Object): The current form being exported.

More information

For more information about the gform_export_max_execution_time filter, you can refer to the official Gravity Forms documentation at https://docs.gravityforms.com/gform_export_max_execution_time/.

Note that changing the maximum execution time for exporting entries can have performance implications on your website. It is important to carefully test and evaluate the impact of any changes you make to this filter.

Examples

Here are five practical examples of how to use the gform_export_max_execution_time filter:

Change the maximum execution time to 60 seconds

add_filter( 'gform_export_max_execution_time', 'change_export_time', 10, 2 );

function change_export_time( $max_execution_time, $form ) {
    // Change the execution time to 60 seconds
    return 60;
}

In this example, the change_export_time function sets the maximum execution time to 60 seconds for all form exports.

Change the maximum execution time for a specific form

add_filter( 'gform_export_max_execution_time', 'change_export_time', 10, 2 );

function change_export_time( $max_execution_time, $form ) {
    // Check if the form ID is 5
    if ( $form['id'] == 5 ) {
        // Set the execution time to 30 seconds
        return 30;
    }
    // Use the default execution time for all other forms
    return $max_execution_time;
}

In this example, the change_export_time function checks if the current form being exported has an ID of 5. If it does, it sets the maximum execution time to 30 seconds. Otherwise, it uses the default execution time for all other forms.

Increase the maximum execution time for a large form

add_filter( 'gform_export_max_execution_time', 'increase_export_time', 10, 2 );

function increase_export_time( $max_execution_time, $form ) {
    // Check if the form has more than 500 entries
    if ( $form['total_entries'] > 500 ) {
        // Increase the execution time to 60 seconds
        return 60;
    }
    // Use the default execution time for smaller forms
    return $max_execution_time;
}

In this example, the increase_export_time function checks if the current form being exported has more than 500 entries. If it does, it increases the maximum execution time to 60 seconds. Otherwise, it uses the default execution time for smaller forms.