wordpress-seo
wordpress-seo copied to clipboard
Constant FILTER_SANITIZE_STRING is deprecated
- [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
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()
.
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.
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.
Please inform the customer of conversation # 912334 when this conversation has been closed.
FYI here are the logs from Query Monitor showing all the deprecation notices:

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 |
Please inform the customer of conversation # 914387 when this conversation has been closed.
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 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.
Please inform the customer of conversation # 941917 when this conversation has been closed.
+1 https://wordpress.org/support/topic/deprecated-functions-29/
+1 https://wordpress.org/support/topic/internal-problem/
+1 https://wordpress.org/support/topic/yoast-plugin-breaks-website/
+https://wordpress.org/support/topic/php-8-1-deprecated-2/
+1 https://wordpress.org/support/topic/filter_sanitize_string-is-deprecated-in-php-v-8-1/
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?
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!
A PR https://github.com/Yoast/wordpress-seo/pull/19128 has been merged and is planned to be included in v19.12
@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:
@worldsdream Please make sure you are using YoastSEO 19.12 or higher. I just checked and the fix is most definitely there.
@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:
I can confirm that the other deprecated notices are gone. But this one is available (back-end). The front-end is all good.
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.
Hi @monbauza, I am glad that you are able to reproduce the deprecation notice.
We will wait for a fix.
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], );