-
Notifications
You must be signed in to change notification settings - Fork 2
Include reason in the GF 2.7+ entry note #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe spam detection function is refactored to add early exit for pre-flagged submissions, replace direct Changes
Sequence DiagramsequenceDiagram
participant Caller
participant Function
participant GFCommon
participant Fallback
Caller->>Function: Call spam check
alt Already spam
Function->>Function: Early exit (return true)
else Not spam
Function->>Function: Extract key via rgpost()
alt Key is empty
Function->>Function: Mark as spam + set reason
else Key provided
Function->>Function: Validate key vs stored key
alt Keys match
Function->>Caller: Return false (not spam)
else Keys don't match
Function->>Function: Mark as spam + set reason
alt GF 2.7+ available
Function->>GFCommon: Call set_spam_filter(reason)
else Older GF version
Function->>Fallback: Queue entry note via gform_entry_created
end
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
gravityforms-zero-spam.php (1)
234-238: GF 2.7+ integration looks solid; backward compatibility maintained.The feature detection and use of
set_spam_filter()with the reason is exactly what's needed for GF 2.7+. For older versions, the fallback preserves the existing behavior with a generic entry note.Optional enhancement for older GF versions:
To include the specific reason in entry notes for GF < 2.7, you could pass
$reasonvia a closure:} else { - add_action( 'gform_entry_created', array( $this, 'add_entry_note' ) ); + add_action( 'gform_entry_created', function( $entry ) use ( $reason ) { + $this->add_entry_note_with_reason( $entry, $reason ); + } ); }Then add a new method to handle the reason:
public function add_entry_note_with_reason( $entry, $reason ) { if ( 'spam' !== rgar( $entry, 'status' ) || ! method_exists( 'GFAPI', 'add_note' ) ) { return; } GFAPI::add_note( $entry['id'], 0, 'Zero Spam', $reason, 'gf-zero-spam', 'success' ); }This keeps the existing
add_entry_note()method for other uses while providing the specific reason for spam detection in older GF versions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gravityforms-zero-spam.php(3 hunks)
🔇 Additional comments (2)
gravityforms-zero-spam.php (2)
185-187: Good addition: early exit prevents redundant processing.This correctly skips key validation when a prior spam filter has already flagged the submission, improving efficiency and avoiding potential issues with missing keys in edge cases.
221-232: Excellent refactor: clearer validation with actionable spam reasons.The switch to
rgpost()follows GF best practices, and separating the missing-key and invalid-key cases provides reviewers with specific context. The early return at line 230 keeps the logic clean.
This uses
GFCommon::set_spam_filter(), which was added in GF 2.7, to add the note when the entry is spam, including a reason, so the user reviewing the entry knows why it was marked as spam. It also adds an early return for when another check (e.g. honeypot) has already determined the entry is spam.Summary by CodeRabbit
Bug Fixes
Refactor