gpls_rule_groups

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Apply Limit Collectively to Group of Forms
    2. Disable Limit Feeds when Editing via Gravity View
    3. Disable Limit Rule for Specific User Role
  5. Since

Description

Filter the rule groups that will be enforced for this form.

Usage

Apply to all forms.

add_filter( 'gpls_rule_groups', 'my_custom_function' );

Apply to a specific form.

add_filter( 'gpls_rule_groups_FORMID', 'my_custom_function' );

Parameters

  • $rule_groups array

    An array of GPLS_RuleGroup objects.

  • $form_id int

    The current form ID for which rules are being enforced.

Examples

Apply Limit Collectively to Group of Forms

This allows you to apply limits collectively to a group of forms such that other forms will share limits with a Primary Form.

<?php
/**
 * Gravity Perks // GP Limit Submissions // Apply Limit Collectively to Group of Forms
 * https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
 *
 * Instruction Video: https://www.loom.com/share/790781a22ff14d2f8023b7dd1adeb3eb
 */
add_filter( 'gpls_rule_groups', function( $rule_groups, $form_id ) {

	// Update "123" to the ID of the form that will share its feeds with the other forms.
	$primary_form_id = 123;

	// Update the following to the form IDs of each form that should share the limits of the primary form.
	$group_form_ids = array( 124, 125, 126 );

	// STOP! No need to edit below this line.
	$applicable_forms = array_merge( array( $primary_form_id ), $group_form_ids );
	if ( ! in_array( $form_id, $applicable_forms ) ) {
		return $rule_groups;
	}

	$rule_groups = array_merge( $rule_groups, GPLS_RuleGroup::load_by_form( $primary_form_id ) );
	foreach ( $rule_groups as $rule_group ) {
		$rule_group->applicable_forms = $applicable_forms;
	}

	return $rule_groups;
}, 10, 2 );

Disable Limit Feeds when Editing via Gravity View

This allows you to disable limit feeds when editing form entries via Gravity View.

<?php
/**
 * Gravity Perks // GP Limit Submissions // Disable Limit Feeds when Editing via Gravity View
 * https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
 */
add_filter( 'gpls_rule_groups', function( $rule_groups, $form_id ) {

	if ( is_callable( 'gravityview_get_context' ) && gravityview_get_context() == 'edit' ) {
		$rule_groups = array();
	}

	return $rule_groups;
}, 10, 2 );

Disable Limit Rule for Specific User Role

This allows you to disable the limit submissions feed for users of a specific role.

<?php
/**
 * Gravity Perks // GP Limit Submissions // Disable Limits for a Specific User Role
 * https://gravitywiz.com/documentaiton/gravity-forms-limit-submissions/
 */
// Update '123' to the ID of the Form.
add_filter( 'gpls_rule_groups_123', function( $rule_groups, $form_id ) {
	// Update to the slug of the role, i.e. administrator, editor, author, contributor, subscriber.
	$role_to_check = 'administrator';
	$user          = wp_get_current_user();
	if ( in_array( $role_to_check, (array) $user->roles ) ) {
		$rule_groups = array();
	}
	return $rule_groups;
}, 10, 2 );

Since

This filter is available since GP Limit Submission 1.0-beta-1.