Skip to content

Fix deprecation warning by checking for null before stripslashes() in Meta_Description_Presenter #22314

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

jilllynndesign
Copy link

Context

This PR fixes a deprecation warning introduced in PHP 8.1+ where stripslashes() throws a warning when passed null. The issue occurs in Meta_Description_Presenter when $meta_description is null before being passed to stripslashes(). This can prevent pages using ACF Flexible Content fields from saving properly, showing a "The response is not a valid JSON response" error.

Summary

Changelog:
changelog: bugfix Fixes a bug where saving posts with ACF flexible content fields could fail with a JSON error due to a deprecation warning in PHP 8.1+ (stripslashes(null) in Meta_Description_Presenter).

Relevant technical choices

Added a null check before calling stripslashes():

$meta_description = $this->helpers->string->strip_all_tags(
	$meta_description === null ? null : \stripslashes( $meta_description )
);

Test instructions

  1. Install ACF and create a field group using Flexible Content fields.
  2. On PHP 8.1 or later, try saving a post using these fields with the current Yoast plugin — confirm that you get the JSON error and see a deprecation warning related to stripslashes()
  3. Apply this PR.
  4. Save the post again — confirm the error and warning are gone.

Impact check

This PR affects how meta descriptions are handled in Yoast SEO, specifically in Meta_Description_Presenter. Any code that relies on filtering or modifying meta descriptions could be impacted. Regression testing is advised around:

  • Meta description outputs
  • Open Graph description tags
  • Meta description previews in the editor

@jilllynndesign jilllynndesign changed the title Fix deprecation warning by checking for null before stripslashes() in Meta_Description_Presenterv Fix deprecation warning by checking for null before stripslashes() in Meta_Description_Presenter May 27, 2025
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.

2 participants