Skip to content

Conversation

@Crabcyborg
Copy link
Contributor

@Crabcyborg Crabcyborg commented Oct 21, 2025

Related ticket https://secure.helpscout.net/conversation/3115553783/240278

This fixes a conflict with All in One Security, where more than one Turnstile element would get rendered.

To avoid this I'm avoid the cf-turnstile class name and using frm-cf-turnstile instead now.

Pre-release
formidable-6.25.1b.zip

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

This PR refactors CAPTCHA class prefix handling by introducing a get_class_prefix() method across CAPTCHA settings classes (base and subclasses), delegating prefix determination from inline logic in FrmFieldCaptcha to settings objects. Concurrently, JavaScript Turnstile selectors are updated from .cf-turnstile to .frm-cf-turnstile.

Changes

Cohort / File(s) Change Summary
CAPTCHA Settings Base Class
classes/models/FrmFieldCaptchaSettings.php
Added get_class_prefix($allow_multiple) method returning empty string by default, establishing extension point for subclasses.
CAPTCHA Settings Implementations
classes/models/FrmRecaptchaSettings.php, classes/models/FrmTurnstileSettings.php
Added get_class_prefix($allow_multiple) method; FrmRecaptchaSettings returns 'frm-' conditionally, FrmTurnstileSettings returns 'frm-' unconditionally.
CAPTCHA Field Logic
classes/models/fields/FrmFieldCaptcha.php
Refactored class prefix determination to delegate to FrmCaptchaFactory::get_settings_object()->get_class_prefix(...); replaced direct property check with $this->allow_multiple() method call.
JavaScript Turnstile Selectors
js/formidable.js
Updated Turnstile DOM selector from .cf-turnstile to .frm-cf-turnstile across initialization, direct invocation, and captcha detection logic.

Sequence Diagram

sequenceDiagram
    participant FC as FrmFieldCaptcha
    participant FCF as FrmCaptchaFactory
    participant SO as Settings Object<br/>(Recaptcha/Turnstile)
    
    Note over FC,SO: Old: Inline class prefix logic
    
    rect rgb(240, 248, 255)
    Note over FC,SO: New: Delegated approach
    FC->>FCF: get_settings_object()
    FCF-->>FC: Returns Settings Object instance
    FC->>SO: get_class_prefix($allow_multiple)
    SO-->>FC: Returns 'frm-' or ''
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes introduce a consistent delegation pattern across multiple settings classes and refactor existing logic in FrmFieldCaptcha, with additional selector updates in JavaScript. While the individual changes are straightforward, the spread across multiple files and need to verify the delegation logic integration warrants moderate review effort.

Possibly related PRs

Suggested reviewers

  • engahmeds3ed

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "Add a prefix to turnstile elements" directly and clearly summarizes the main change in the changeset. The modifications across multiple files implement a prefixing mechanism where Turnstile elements transition from using the .cf-turnstile class to .frm-cf-turnstile, which is exactly what the title describes. The title is specific enough that a teammate reviewing the commit history would immediately understand the primary objective without requiring additional context.
Description Check ✅ Passed The pull request description is directly related to the changeset. The author explains that the changes address a conflict with "All in One Security" plugin where multiple Turnstile elements were being rendered, and the solution involves prefixing the class name from cf-turnstile to frm-cf-turnstile. The changeset confirms this intent by implementing a prefix infrastructure through new get_class_prefix() methods in multiple settings classes, with FrmTurnstileSettings specifically returning the 'frm-' prefix, and updating JavaScript selectors from .cf-turnstile to .frm-cf-turnstile. The description provides meaningful context about the problem being solved and links to a relevant ticket.
✨ 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 add_a_prefix_to_turnstile_elements

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.

Copy link
Contributor

@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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4fe33 and e2c1eb3.

📒 Files selected for processing (5)
  • classes/models/FrmFieldCaptchaSettings.php (1 hunks)
  • classes/models/FrmRecaptchaSettings.php (1 hunks)
  • classes/models/FrmTurnstileSettings.php (1 hunks)
  • classes/models/fields/FrmFieldCaptcha.php (2 hunks)
  • js/formidable.js (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
classes/models/FrmFieldCaptchaSettings.php (3)
classes/models/FrmRecaptchaSettings.php (1)
  • get_class_prefix (126-128)
classes/models/FrmTurnstileSettings.php (1)
  • get_class_prefix (86-88)
classes/models/fields/FrmFieldCaptcha.php (1)
  • allow_multiple (271-273)
classes/models/FrmTurnstileSettings.php (3)
classes/models/FrmFieldCaptchaSettings.php (1)
  • get_class_prefix (265-267)
classes/models/FrmRecaptchaSettings.php (1)
  • get_class_prefix (126-128)
classes/models/fields/FrmFieldCaptcha.php (1)
  • allow_multiple (271-273)
classes/models/FrmRecaptchaSettings.php (3)
classes/models/FrmFieldCaptchaSettings.php (1)
  • get_class_prefix (265-267)
classes/models/FrmTurnstileSettings.php (1)
  • get_class_prefix (86-88)
classes/models/fields/FrmFieldCaptcha.php (1)
  • allow_multiple (271-273)
classes/models/fields/FrmFieldCaptcha.php (3)
classes/models/FrmFieldCaptchaSettings.php (1)
  • get_class_prefix (265-267)
classes/models/FrmRecaptchaSettings.php (1)
  • get_class_prefix (126-128)
classes/models/FrmTurnstileSettings.php (1)
  • get_class_prefix (86-88)
🪛 PHPMD (2.15.0)
classes/models/FrmFieldCaptchaSettings.php

265-265: Avoid unused parameters such as '$allow_multiple'. (undefined)

(UnusedFormalParameter)

classes/models/FrmTurnstileSettings.php

86-86: Avoid unused parameters such as '$allow_multiple'. (undefined)

(UnusedFormalParameter)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Cypress
🔇 Additional comments (5)
classes/models/fields/FrmFieldCaptcha.php (2)

174-174: LGTM: Improved encapsulation.

Refactoring to use the allow_multiple() method instead of direct property access improves encapsulation and consistency.


255-257: LGTM: Clean delegation to settings object.

The refactor properly delegates prefix determination to the settings object, removing inline conditional logic and improving maintainability.

js/formidable.js (3)

968-970: LGTM: Selector update is consistent with PHP changes.

The Turnstile selector correctly updated to .frm-cf-turnstile to match the prefixed class name generated by the PHP changes.


2068-2068: LGTM: Consistent selector in frmTurnstile function.

The selector update aligns with the new prefixed class name.


2117-2119: LGTM: Consistent detection logic.

The Turnstile detection properly uses the updated .frm-cf-turnstile selector.

@Crabcyborg Crabcyborg merged commit 08f5767 into master Oct 21, 2025
35 of 37 checks passed
@Crabcyborg Crabcyborg deleted the add_a_prefix_to_turnstile_elements branch October 21, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants