fix(recaptcha): skip script registration on TEC Community Events pages#4666
fix(recaptcha): skip script registration on TEC Community Events pages#4666wil-gerken wants to merge 4 commits intotrunkfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Prevents a reCAPTCHA breakage caused by double-loading Google’s api.js (with different site keys) when The Events Calendar Community Events submission page is used alongside Newspack reCAPTCHA.
Changes:
- Add an early return in
Recaptcha::register_scripts()on TEC Community Events submission/edit pages to avoid registering/enqueueing Newspack’s reCAPTCHA scripts there. - Add unit tests covering script registration behavior on normal pages, TEC community pages, and when reCAPTCHA is disabled.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
includes/class-recaptcha.php |
Adds TEC Community Events page detection and bails early to avoid conflicting api.js loads. |
tests/unit-tests/recaptcha.php |
Adds unit tests validating script registration/enqueue behavior across page contexts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
All Submissions:
Changes proposed in this Pull Request:
Newspack's reCAPTCHA loads Google's
api.json every front-end page. When The Events Calendar Community Events is active and the publisher has configured TEC's own reCAPTCHA key, the TEC Community Events submission page also loadsapi.jswith a different site key. Twoapi.jsloading on the same page with different keys break reCAPTCHA resulting in errors when trying to submit a community event.Newspack's reCAPTCHA client only protects
form[data-newspack-recaptcha],form#add_payment_method, andform.checkout, so it was never protecting TEC forms to begin with. This change adds an early return inRecaptcha::register_scripts()when we're on a TEC Community Events submission page, preventing the conflict while leaving TEC's own reCAPTCHA spam protection intact.Closes NPPM-2743.
How to test the changes in this Pull Request:
Setup:
Reproduce the problem (on
trunk, before this PR):/events/community/add/.api.js. Confirm two separatehttps://www.google.com/recaptcha/api.jsrequests load.Verify the fix (with this PR):
/events/community/add/. Confirm only TEC'sapi.jsloads, Newspack's is no longer present.api.js?render=<site_key>still loads (no regression).repos/newspack-plugin/, runn test-php --filter Test_Recaptchaand confirm all 3 new tests pass.Other information: