Skip to content

Conversation

@SebastianWiz
Copy link
Contributor

@SebastianWiz SebastianWiz commented Oct 21, 2025

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/3089383028/89888

Summary

This snippet adds the option to skip a Limit Submissions feed whenever any field-based rule in the targeted form resolves to a blank value.

Example scenario
User has the following feed configured with the goal to prevent visitors from being able to submit the same email address and coupon code more than once.

  • Limit submissions: 1
  • Rules:
    • Field value: Email field
    • Field value: Coupon field

While the limit submission feed does prevent a second submission using the same email and coupon code, it will also prevent any submission where the same email address is used but the coupon field is left blank. With this snippet installed, the limit submission feed is skipped unless both email and coupon fields contains values.

@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2025

Walkthrough

Adds a new PHP file registering a gpls_should_apply_rules filter that skips evaluating a Limit Submissions feed for specific form(s) when any field-based rule resolves to a blank value, caching skip decisions per feed.

Changes

Cohort / File(s) Summary
Gravity Perks Limit Submissions Filter
gp-limit-submissions/gpls-skip-limit-if-blank.php
New file registering a gpls_should_apply_rules filter (priority 20, 3 args) that: targets specific form IDs (includes form 123), iterates GPLS_Rule_Field rules, obtains limit field values, trims arrays deeply and strings, treats blank results as "skip feed", caches skip decisions on the rule_test/feed_id, and returns false to skip when blank detected.

Sequence Diagram

sequenceDiagram
    participant Feed as Feed Processor
    participant Hook as gpls_should_apply_rules
    participant Cache as Feed Skip Cache
    participant Rules as Rule Iterator
    participant Logic as Value Evaluation

    Feed->>Hook: apply_filters('gpls_should_apply_rules', should_apply, form_id, rule_test)
    Hook->>Cache: check cached skip for feed_id (if present)
    alt cached skip exists
        Cache-->>Hook: return cached false
    else no cache
        Hook->>Rules: get rule_group / rules
        loop each GPLS_Rule_Field
            Rules->>Logic: get_limit_field_value(get_field())
            alt value is array
                Logic->>Logic: GFCommon::trim_deep -> check empty
                alt array empty
                    Logic->>Cache: cache skip for feed_id
                    Logic-->>Hook: return false
                end
            else value is string
                Logic->>Logic: trim whitespace -> check blank
                alt blank
                    Logic->>Cache: cache skip for feed_id
                    Logic-->>Hook: return false
                end
            end
        end
    end
    Hook-->>Feed: return should_apply (possibly false)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • saifsultanc

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title accurately and specifically describes the main change in the changeset. It clearly identifies the new file being added (gpls-skip-limit-if-blank.php) and concisely summarizes its purpose: adding a snippet for skipping limit submissions when field values are blank. The title directly aligns with the raw summary and PR objectives, which confirm this is the primary change. The phrasing is clear, specific, and avoids vague or generic terminology, making it easy for reviewers scanning history to understand the core contribution.
Description Check ✅ Passed The pull request description follows the required template structure and includes all necessary sections. The Context section is present with a relevant ticket reference linking to the customer conversation. The Summary section provides a clear explanation of what the snippet does, including both a straightforward description and a detailed example scenario that illustrates the motivation and expected behavior. The description effectively conveys the purpose of the change and the problem it solves, enabling reviewers to understand the functionality and use case without ambiguity.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SebastianWiz-patch-2

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71f6965 and 4262f44.

📒 Files selected for processing (1)
  • gp-limit-submissions/gpls-skip-limit-if-blank.php (1 hunks)
🔇 Additional comments (7)
gp-limit-submissions/gpls-skip-limit-if-blank.php (7)

9-13: LGTM! Early exit conditions are well-structured.

The guard clauses efficiently prevent unnecessary processing when the feed shouldn't apply or when required data structures are missing.


15-20: LGTM! Form targeting logic is correctly implemented.

The strict type comparison with explicit integer casting ensures reliable form ID matching.


28-31: LGTM! Instance type check correctly filters field-based rules.

The instanceof guard ensures only field-based rules are evaluated, which aligns with the snippet's stated purpose.


35-57: LGTM! Blank value detection logic is comprehensive.

The implementation correctly handles different value types:

  • Arrays are trimmed deeply and checked for emptiness
  • Strings are trimmed of whitespace
  • The rgblank() function appropriately catches blank values after processing

60-60: LGTM! Correct fallback behavior.

Returns the original $should_apply value when no blank values are detected, allowing normal feed evaluation to proceed.


43-43: <!-- [scratchpad_update]
[task review_file_1/1 verify_dynamic_property_1/3]
Confirmed PHP 8.2+ behavior via web search; now need to find $rule_test class definition.
[observations]

  • Web search confirms: Dynamic properties on classes without #[AllowDynamicProperties] are deprecated in PHP 8.2 and become Error in PHP 9.0
  • Three exceptions: __get/__set, extends stdClass, or #[AllowDynamicProperties] attribute
  • Shell script found usages at lines 24, 43, 55 in gpls-skip-limit-if-blank.php but did NOT locate class definition with AllowDynamicProperties
    [pending]
  • Need to find what class $rule_test is (look for instantiation)
  • Verify if that class has the attribute or magic methods
    [actions]
    Search for $rule_test instantiation and class definition in the codebase.
    [scratchpad_end] --><!-- [scratchpad_update]
    [task review_file_1/1 verify_dynamic_property_2/3]
    Web search confirmed GPLS_RuleTest class exists in Gravity Forms Limit Submissions plugin, but need class definition details.
    [observations]
  • Search results show GPLS_RuleTest/RuleTest class is used in Gravity Forms Limit Submissions
  • Documentation references "$ruletest" object with properties like form_id, join[], where[]
  • Found Gravity Forms PHP 8.2 compatibility doc showing dynamic property deprecation issues in GF
  • No direct evidence of #[AllowDynamicProperties] on GPLS_RuleTest class from search results
    [pending]
  • Need to locate GPLS_RuleTest class definition in the repository to check for AllowDynamicProperties attribute
  • Check if class has __get/__set magic methods or extends stdClass
    [actions]
    Search for GPLS_RuleTest class definition in codebase using rg.
    [scratchpad_end] --><!-- [scratchpad_final_update]
    [task review_file_1/1 verify_dynamic_property_final]
    Verification complete: Unable to locate GPLS_RuleTest class definition via web search to confirm AllowDynamicProperties or __get/__set methods.
    [observations]
  • Multiple sources confirm GPLS_RuleTest class exists and is documented
  • Shown in documentation examples dynamically setting properties (join[], where[], skip_limit_feed_on_blank)
  • No web search results showed #[AllowDynamicProperties] on GPLS_RuleTest class
  • No evidence of __get/__set magic methods in search results
  • PHP 8.2 documentation confirms dynamic properties deprecated and will error in PHP 9.0
    [analysis]
    The code dynamically assigns $rule_test->skip_limit_feed_on_blank (lines 43, 55 in snippet).
    Without confirmation that GPLS_RuleTest has:
    1. #[AllowDynamicProperties] attribute, OR
    2. __get/__set magic methods, OR
    3. Extends stdClass
      The dynamic property assignment will trigger deprecation notices in PHP 8.2+ and errors in PHP 9.0.

The original review comment is VALID: dynamic properties should be verified against the class definition.
[actions]
Issue remains valid. Output rewritten comment flagged for manual verification since class definition not located via web search. Repository should be searched directly.
[scratchpad_end] -->

Add explicit property declaration to GPLS_RuleTest or verify class allows dynamic properties.

In PHP 8.2 and later, setting a value to an undeclared class property is deprecated, and emits a deprecation notice, and the creation of dynamic properties on classes that aren't marked with the #[AllowDynamicProperties] attribute is deprecated in PHP 8.2 and becomes an Error exception in PHP 9.0. The code assigns $rule_test->skip_limit_feed_on_blank on lines 43 and 55 without verifying the class supports dynamic properties. Confirm that the GPLS_RuleTest class either:

  • Declares skip_limit_feed_on_blank as a property, or
  • Has #[AllowDynamicProperties] attribute, or
  • Implements __get()/__set() magic methods, or extends stdClass

22-26: Verification inconclusive—manual review of external plugin required.

The code in this repository is a snippet for the external "Gravity Forms Limit Submissions" plugin. The $rule_test object is instantiated and passed to the filter by that plugin, not by code in this repository.

The concern about object property persistence is theoretically valid: if the same $rule_test instance is reused across multiple submissions within a single request (batch processing, AJAX, etc.), the skip_limit_feed_on_blank flag would remain set from the first submission and incorrectly affect subsequent evaluations.

To verify the concern:

  1. Check the Gravity Forms Limit Submissions plugin source code for where apply_filters( 'gpls_should_apply_rules', ... ) is called
  2. Determine whether a new $rule_test object is instantiated for each submission evaluation or if it's reused across multiple submissions in a single request

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Oct 21, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 4262f44

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
gp-limit-submissions/gpls-skip-limit-if-blank.php (1)

37-63: Logic correctly handles different value types.

The handling of false values, arrays, and strings is appropriate. The use of GFCommon::trim_deep() and rgblank() aligns with Gravity Forms conventions.

Optional: The cache update logic at lines 45-47 and 59-61 is duplicated. If the static cache is retained (see separate comment), you could consolidate this:

// Helper to mark feed for skipping
$mark_skip = function() use ( $feed_id, &$skip_feed_ids ) {
	if ( $feed_id ) {
		$skip_feed_ids[ $feed_id ] = true;
	}
	return false;
};

// Then use: return $mark_skip();

However, given the critical issue with the static cache itself, this refactoring may not be necessary.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb06fa4 and 71f6965.

📒 Files selected for processing (1)
  • gp-limit-submissions/gpls-skip-limit-if-blank.php (1 hunks)
🔇 Additional comments (4)
gp-limit-submissions/gpls-skip-limit-if-blank.php (4)

1-8: Clear documentation.

The header clearly explains the snippet's purpose and links to relevant documentation.


13-22: Good defensive programming.

The early return guards and form ID targeting logic are appropriate. The strict type checking in in_array() is a good practice.


24-24: Good use of defensive method checking.

The method_exists() check before calling get_feed_id() is appropriate defensive programming.


9-9: Filter hook registration looks appropriate.

The filter parameters and priority (20) appear correct, and the final return properly preserves the original $should_apply value when no blank values are detected.

Also applies to: 66-67

continue;
}

$value = $rule->get_limit_field_value( $rule->get_field() );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Consider adding null check for get_field() result.

If get_field() can return null, passing it directly to get_limit_field_value() might cause issues. Consider adding a defensive check.

+	$field = $rule->get_field();
+	if ( ! $field ) {
+		continue;
+	}
-	$value = $rule->get_limit_field_value( $rule->get_field() );
+	$value = $rule->get_limit_field_value( $field );

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In gpl-limit-submissions/gpls-skip-limit-if-blank.php around line 35, the call
passes $rule->get_field() directly into get_limit_field_value() without checking
for null; add a defensive null check: first get the field into a variable,
verify it is not null (and optionally that it is of the expected type/string),
and only then call get_limit_field_value($field); if null, handle appropriately
(return early, skip processing, or use a safe default) to avoid errors.

Copy link
Contributor

@saifsultanc saifsultanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants