Skip to content
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 deprecated messages on PHP 8.2 from using FILTER_SANITIZE_STRING #3144

Merged
merged 3 commits into from
May 27, 2024

Conversation

mattallan
Copy link
Contributor

@mattallan mattallan commented May 22, 2024

Changes proposed in this Pull Request:

While testing another PR (#2837) I noticed a bunch of deprecated warnings in my error logs while trying to purchase a product using Google Pay and Apple Pay:

[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1175
[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1176
[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1177
[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1178
[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1179
[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1180
[22-May-2024 05:10:49 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /Users/matt/local/woo/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-payment-request.php on line 1183

Looks like the FILTER_SANITIZE_STRING constant has been deprecated since PHP 8.1 and so this PR updates our code to use FILTER_SANITIZE_SPECIAL_CHARS instead which is essentially the same thing.

Testing instructions

  1. Switch your dev site over to PHP 8.2+
  2. Enable Apple Pay/Google Pay
  3. While on develop add a product to your cart and attempt to purchase it using Google Pay
  4. When the Google Pay window appears, check you debug log and confirm the deprecated messages
  5. Checkout this branch and confirm no deprecation messages
  6. These changes impact fetching shipping options so confirm the shipping based on your address are correct

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

Fixes #3056

Copy link
Contributor

@a-danae a-danae left a comment

Choose a reason for hiding this comment

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

Thanks for updating these, @mattallan! Things look good to me 👍

✅ No entries related to the deprecation of FILTER_SANITIZE_STRING are added to the debug log in this branch.
✅ The shipping options displayed in Google Pay match the ones defined in the WC settings for the selected shipping address.
✅ The customer details are correct in the Stripe payment details.
✅ The code changes make sense to me.
✅ I didn't find any other occurrences of FILTER_SANITIZE_STRING in the code.

Having the logs filled up by deprecated messages isn't nice. Glad to see this fixed!

@mattallan mattallan merged commit a261a00 into develop May 27, 2024
33 checks passed
@mattallan mattallan deleted the fix/deprecated_filter_sanitize_string branch May 27, 2024 00:27
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.

Consider replacing FILTER_SANITIZE_STRING, since it is deprecated as of PHP 8.1.0
2 participants