wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Constant FILTER_SANITIZE_STRING is deprecated

Open ThomasTr opened this issue 3 years ago • 9 comments

  • [X] I've read and understood the contribution guidelines.
  • [X] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

Constant FILTER_SANITIZE_STRING is deprecated in wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 22

Please describe what you expected to happen and why.

In my DEV environment deprecations are thrown as exceptions due to other software in which Wordpress is integrated.

An exception occurred: [ErrorException] [E_DEPRECATED] Constant FILTER_SANITIZE_STRING is deprecated in /public/wordpress/wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 22

How can we reproduce this behavior?

Use wordpress-seo under php 8.1 and log or throw deprecations.

Technical info

Used versions

  • WordPress version: 5.8.3
  • Yoast SEO version: 18.0

ThomasTr avatar Jan 25 '22 11:01 ThomasTr

Confirmed to be deprecated in PHP 8.1, according to https://www.php.net/manual/en/filter.filters.sanitize.php . Article suggests the use of htmlspecialchars().

Djennez avatar Jan 25 '22 12:01 Djennez

In my DEV environment deprecations are thrown as exceptions due to other software in which Wordpress is integrated.

That sounds like a problem in your dev environment. Deprecations are NOT errors and should NOT be treated as such. Until PHP 9.0, everything which is deprecated will still work as it did before.

jrfnl avatar Jan 25 '22 14:01 jrfnl

That sounds like a problem in your dev environment. Deprecations are NOT errors and should NOT be treated as such. Until PHP 9.0, everything which is deprecated will still work as it did before.

Sometimes you have not the control over all the code you use. Enabling debug mode in wordpress is enough to get all deprecations printed out.

ThomasTr avatar Jan 25 '22 14:01 ThomasTr

Please inform the customer of conversation # 912334 when this conversation has been closed.

amboutwe avatar Jul 08 '22 18:07 amboutwe

FYI here are the logs from Query Monitor showing all the deprecation notices:

Screen Shot 2022-07-11 at 9 22 40 AM
Deprecated Constant FILTER_SANITIZE_STRING is deprecated wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php:22
Deprecated Constant FILTER_SANITIZE_STRING is deprecated wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php:28
Deprecated strtolower(): Passing null to parameter #1 ($string) of type string is deprecated wp-content/plugins/wordpress-seo/src/generators/schema-generator.php:185

tedw avatar Jul 11 '22 13:07 tedw

Please inform the customer of conversation # 914387 when this conversation has been closed.

michaelbriantina avatar Jul 15 '22 02:07 michaelbriantina

None of our sites don't use Elementor and throw this Warning on PHP 8.1

Could this also be optimised to not run at all if Elementor is not detected?

kb6673 avatar Aug 18 '22 10:08 kb6673

@kb6673 the relevant part of the code isn't optimized for PHP v8.1 or higher and as such, the relevant warning appears. It doesn't mean that you have to use Elementor.

mmikhan avatar Aug 24 '22 22:08 mmikhan

Please inform the customer of conversation # 941917 when this conversation has been closed.

michaelbriantina avatar Sep 19 '22 03:09 michaelbriantina

+1 https://wordpress.org/support/topic/deprecated-functions-29/

maybellyne avatar Sep 27 '22 12:09 maybellyne

+1 https://wordpress.org/support/topic/internal-problem/

maybellyne avatar Oct 21 '22 09:10 maybellyne

+1 https://wordpress.org/support/topic/yoast-plugin-breaks-website/

maybellyne avatar Oct 27 '22 13:10 maybellyne

+https://wordpress.org/support/topic/php-8-1-deprecated-2/

maybellyne avatar Oct 27 '22 14:10 maybellyne

+1 https://wordpress.org/support/topic/filter_sanitize_string-is-deprecated-in-php-v-8-1/

maybellyne avatar Nov 02 '22 13:11 maybellyne

I barely can debug, because of how many deprecation messages are being dumped. Had to regex to hide deprecation messages. When are you planning to update theses?

richardevcom avatar Nov 07 '22 03:11 richardevcom

We have prioritized this internally and hoping to start working on it soon! That said, the deprecation messages aren't supposed to appear in the production environment. So, ensure that you have to debug mode turned off on your system!

mmikhan avatar Nov 07 '22 09:11 mmikhan

A PR https://github.com/Yoast/wordpress-seo/pull/19128 has been merged and is planned to be included in v19.12

mmikhan avatar Nov 07 '22 14:11 mmikhan

@monbauza @mmikhan Are you sure that this is fixed? It did fix some of the warnings, but there is 1 left in the backend.

Deprecated | Constant FILTER_SANITIZE_STRING is deprecated | wp-content/plugins/wordpress-seo/src/integrations/admin/helpscout-beacon.php:111

See screenshot:

info

worldsdream avatar Dec 23 '22 10:12 worldsdream

@worldsdream Please make sure you are using YoastSEO 19.12 or higher. I just checked and the fix is most definitely there.

jrfnl avatar Dec 23 '22 20:12 jrfnl

@jrfnl I am on version Yoast version 19.13

I just spin up a fresh WP install (v 6.1.1) and Yoast SEO 19.13.

The back-end shows the deprecation notice.

See screenshot:

info

I can confirm that the other deprecated notices are gone. But this one is available (back-end). The front-end is all good.

worldsdream avatar Dec 24 '22 09:12 worldsdream

Hi @worldsdream, I've been able to reproduce the deprecation notice you reported. Please, note that the deprecation only appears in the Query Monitor plugin, and not in the debug logs or in the WP admin panel. Anyway, deprecations don't break any WordPress functionality and are not actual errors, so you can ignore them. We'll eventually fix the reason that causes that deprecation.

monbauza avatar Dec 27 '22 09:12 monbauza

Hi @monbauza, I am glad that you are able to reproduce the deprecation notice.

We will wait for a fix.

worldsdream avatar Dec 27 '22 15:12 worldsdream

Replace wp-security-audit-log/sensors/class-yoast-seo-sensor.php lines 213 - 229 With:

// Set filter input args. $filter_input_args = array( 'post_ID' => FILTER_VALIDATE_INT, '_wpnonce' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'action' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_title' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_metadesc' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_focuskw' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_is_cornerstone' => FILTER_VALIDATE_BOOLEAN, 'yoast_wpseo_meta-robots-noindex' => FILTER_VALIDATE_INT, 'yoast_wpseo_meta-robots-nofollow' => FILTER_VALIDATE_INT, 'yoast_wpseo_meta-robots-adv' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_canonical' => FILTER_VALIDATE_URL, 'yoast_wpseo_schema_page_type' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_schema_article_type' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], 'yoast_wpseo_bctitle' => [FILTER_FLAG_NO_ENCODE_QUOTES, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_BACKTICK, FILTER_FLAG_ENCODE_LOW, FILTER_FLAG_ENCODE_HIGH, FILTER_FLAG_ENCODE_AMP], );

BrandonWeigand avatar Sep 21 '23 17:09 BrandonWeigand