Skip to content

stripslashes(): Passing null to parameter #1 ($string) is deprecated in meta-description-presenter.php #22300

Open
@jilllynndesign

Description

@jilllynndesign

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:

  1. PHP version: 8.1.32
  2. WordPress version: [your WP version]
  3. Plugins: Yoast SEO (latest), Advanced Custom Fields Pro (with Flexible Content)
  4. Create or edit a post with no meta description set (or one dynamically returning null)
  5. Attempt to save the post
  6. 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 ) ) );

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions