Open
Description
Description:
When saving posts using the block editor (with Advanced Custom Fields Flexible Content), I receive a fatal JSON error in the editor, caused by a deprecation warning from Yoast SEO:
Deprecated: stripslashes(): Passing null to parameter #1 ($string) of type string is deprecated
in wp-content/plugins/wordpress-seo/src/presenters/meta-description-presenter.php on line 60
This breaks the WordPress REST API save process due to unexpected output.
How to Reproduce:
- PHP version: 8.1.32
- WordPress version: [your WP version]
- Plugins: Yoast SEO (latest), Advanced Custom Fields Pro (with Flexible Content)
- Create or edit a post with no meta description set (or one dynamically returning null)
- Attempt to save the post
- Observe the JSON error and deprecated warning
Temporary Fix:
I resolved this temporarily by intercepting the deprecation warning with set_error_handler():
set_error_handler(function($errno, $errstr, $errfile, $errline) {
if (
str_contains($errstr, 'stripslashes()') &&
str_contains($errfile, 'meta-description-presenter.php')
) {
return true;
}
return false;
}, E_DEPRECATED);
Proposed Solution:
Update Meta_Description_Presenter to type-check the meta description before passing to stripslashes():
$description = $this->get();
if ( ! is_string( $description ) ) {
$description = '';
}
return sprintf( '<meta name="description" content="%s" />', esc_attr( stripslashes( $description ) ) );