-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix: remove reCAPTCHA for Woo from modal checkout #1984
Conversation
includes/class-modal-checkout.php
Outdated
/** | ||
* Remove hooks related to reCAPTCHA for WooCommerce | ||
*/ | ||
public static function remove_recaptcha_hooks() { |
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.
Question: How common is this extension? It feels strange to have to account for specific 3rd party plugin hooks like this within our own plugin. It also doesn't seem very sustainable for other cases that might be impacting checkout down the line.
Is it possible to do this more dynamically using an approach similar to how we handle allowed scripts?
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.
How common is this extension?
It's active on 28 sites now (and installed but inactive on others) -- definitely more than I would have expected!
Is it possible to do this more dynamically using an approach similar to how we handle allowed scripts?
Like pass a filterable array of hooks to remove? I can dig into it!
Ok I think I have everything sorted, @chickenn00dle! As an extra precaution, I did some error logging for the scripts/styles getting removed before and after this change, and re-added a couple -- one (the woocommerce styles one) was causing issues. I didn't see any issues caused by selectWoo, but better safe than sorry! (It's Woo's accessible fork of select2, which was also being enqueued [I think] as a fallback). For the remove_action part, I added an array with the hook and callback that can be filtered using Just let me know if anything needs changing -- thanks! |
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.
Hmm, I tested with the changes but am still seeing the recaptcha error on my end:
Not sure if its the same extension but I am testing with this one: https://woocommerce.com/products/recaptcha-for-woocommerce/
I also left two small comments that are non-blocking (sort of). Let me know what you think!
includes/class-modal-checkout.php
Outdated
], | ||
[ | ||
'hook' => 'woocommerce_review_order_before_submit', | ||
'callback' => 'rcfwc_field_checkout', |
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.
Another (non-blocking question) I had a look through the code and am seeing we have this array of fields to filter out during validation in the modal checkout js:
newspack-blocks/src/modal-checkout/index.js
Lines 618 to 620 in f398d8c
const removeFromValidation = [ | |
'save_user_in_woopay', | |
]; |
For this hook, which I'm assuming is adding a checkout field, is this something that can be removed using the same strategy?
We'd still need to remove hooks associated with any backend logic of course, but if we can stick to the same strategy for bypassing field validation that'd be great!
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.
For this hook, which I'm assuming is adding a checkout field, is this something that can be removed using the same strategy?
I'm not sure of the ins and outs of how this works, but it's adding a div
, like:
<div class="g-recaptcha" data-sitekey="6LfrhJEqAAAAAPuv8JoMdAqEM6G-TKQxc2Es_37A"></div>
I double-checked, and it doesn't look like anything related to reCAPTCHA is included in $form.serializeArray()
, which is what we're checking removeFromValidation
for.
* | ||
* @param string[] $remove_list Array of hooks to remove. | ||
*/ | ||
$remove_list = apply_filters( 'newspack_blocks_modal_checkout_remove_hooks', $remove_list ); |
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.
Another non-blocking comment. This is definitely better. But in the end we are still needing to specify the rcfwc_
callbacks here. This is fine if this is the only one, but I can't imagine we don't run into similar issues in the future with other extensions.
I haven't dug too deep into it, but it's possible to view all hooks associated with a specific action via the $wp_filter
global. Is it possible to do something like create an allow list of plugins, and check the added filters for the checkout processing hook(s), then remove if not in the allow list?
I'm happy to go with this quick fix specific to recaptcha for woocommerce, but really feel this should be improved so we don't have to keep accounting for one-off plugins like this.
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.
I think for now (and in the interest of getting this fixed and rolled out during alphas), my vote would be to keep it simple and revisit when we need to add more plugins 😅 I know something more abstracted would be ideal but I'm worried about cutting this too close to the wire.
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.
I'm going to spin up a separate issue to capture this and see what I can do with it! 🙂
I've updated the code to actually work with the correct ReCaptcha for WooCommerce plugin 😆 Anything related to the plugin should be dequeued/removed in the modal checkout, but still be present in the regular checkout. The plugin uses the prefix |
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.
Looks good. Thanks @laurelfulford
includes/class-modal-checkout.php
Outdated
$remove_list = []; | ||
|
||
// reCaptcha for WooCommerce. | ||
if ( method_exists( 'I13_Woo_Recpatcha', '__construct' ) ) { |
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.
non-blocking nit: we can just do a check for the class with class_exists
.
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.
Thanks Raz! Fixed in ad577d6.
Hey @laurelfulford, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
# [4.5.0-alpha.2](v4.5.0-alpha.1...v4.5.0-alpha.2) (2024-12-04) ### Bug Fixes * remove reCaptcha for WooCommere code from modal checkout ([#1984](#1984)) ([8e250eb](8e250eb))
🎉 This PR is included in version 4.5.0-alpha.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [4.5.0](v4.4.0...v4.5.0) (2024-12-09) ### Bug Fixes * also search for coauthor posts by term slug ([#1954](#1954)) ([49357ff](49357ff)) * **modal-checkout:** allow all gateway assets ([#1988](#1988)) ([e371e30](e371e30)) * **modal-checkout:** handle paypal ([#1985](#1985)) ([9bb2b8c](9bb2b8c)) * **ras-acc:** correct spacing issue around saved credit cards ([#1980](#1980)) ([52a5c57](52a5c57)) * **ras-acc:** fix display issues with Additional Fields ([#1979](#1979)) ([b9390ef](b9390ef)) * **ras-acc:** remove space caused by empty divs ([#1978](#1978)) ([8cb6ead](8cb6ead)) * remove reCaptcha for WooCommere code from modal checkout ([#1984](#1984)) ([8e250eb](8e250eb)) ### Features * add Bluesky support to the Author Profile, List blocks ([#1969](#1969)) ([d26a7e4](d26a7e4)) * add CSS class to variation buttons for tracking ([#1989](#1989)) ([910e6b1](910e6b1)) * add support for Newspack Guest Contributor in HPP blocks ([#1934](#1934)) ([c16849e](c16849e)) * merge RAS-ACC work into trunk ([#1977](#1977)) ([2eeaa89](2eeaa89))
🎉 This PR is included in version 4.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
This PR removes and dequeues code from the reCAPTCHA for WooCommerce plugin from our modal checkout.
See 1207817176293825-as-1208873550136264
Note: the way I went about removing the scripts might be terrible; it seemed kind of duplicative, but I couldn't think of a better way that didn't require spelling out each allowed script.
How to test the changes in this Pull Request:
recaptcha
from the plugin (ag-recaptcha
div, plus the script, rcfwc.js).Other information: