gform_search_critera_entry_limit_validation

Description

The gform_search_criteria_entry_limit_validation filter can be used to modify the search criteria used to get the current entry count for the entry limit validation.

Usage

The following would apply to all forms.

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

To limit the scope of your function to a specific form, append the form ID to the end of the hook name. (format: gform_search_criteria_entry_limit_validation_FORMID)

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

Parameters

  • $search_criteria array
    An array containing the search criteria. See Search Arguments for accepted arguments.
$search_criteria = array(
	'status'     => 'active',
	'start_date' => '2023-02-01',
	'end_date'   => '2023-02-01 23:59:59',
);

Examples

Limit count by field value

The following example shows how you can filter the entries used for the limit count by the valued saved to a field that has id 5. The filter name limits its scope to form id 3.

add_filter( 'gform_search_criteria_entry_limit_validation_3', function( $search_criteria, $form ) {
	$search_criteria['field_filters'][] = array( 'key' => '5', 'value' => 'First Choice' );

	return $search_criteria;
}, 10, 2 );

Limit count by user ID

The following example shows how you can filter the entries used for the limit count by the ID of the current logged in user. The filter name doesn’t include a form id, therefore the snippet will be applicable to all forms.

add_filter( 'gform_search_criteria_entry_limit_validation', function( $search_criteria, $form ) {
	$search_criteria['field_filters'][] = array( 'key' => 'created_by', 'value' => get_current_user_id() );

	return $search_criteria;
}, 10, 2 );

Limit count to Paid entries only

The following example shows how you can filter the entries used for the limit count by the Payment Status. It will search for Paid entries, the filter name limits its scope to form id 8.

add_filter( 'gform_search_criteria_entry_limit_validation_8', function( $search_criteria, $form ) {
	$search_criteria['field_filters'][] = array( 'key' => 'payment_status', 'value' => 'Active' );

	return $search_criteria;
}, 10, 2 );

Since

This filter was added in Gravity Forms 2.7.1

Source Code

This filter is located in GFFormDisplay::validate_entry_limit() in form_display.php

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?