Fix TypeError in json_decode when template content is an array - #4341
Open
muhitasraf wants to merge 1 commit into
Open
Fix TypeError in json_decode when template content is an array#4341muhitasraf wants to merge 1 commit into
muhitasraf wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR prevents a fatal PHP
TypeErrorinElementorUtils::get_all_widgets_in_all_templates()when the post meta_elementor_datais retrieved as an array rather than a JSON-encoded string.The Problem
Under certain environments, database setups, or migrations,
_elementor_datapost meta may be stored as a serialized PHP array in the database instead of a JSON string. When retrieved viaget_post_meta($id, '_elementor_data', true), WordPress automatically unserializes it and returns a PHParray.In PHP 8.0+, passing an array directly to
json_decode()throws a fatal type error:TypeError: json_decode(): Argument #1 ($json) must be of type string, array givenAdditionally, if the metadata is corrupt or missing, passing the resulting non-array to
recursively_get_inner_widgets()(which expects anarrayparameter) causes another fatalTypeError.The Solution
is_string( $template_content )before callingjson_decode( $template_content, true ).is_array( $template_content )before merging widgets to ensure we do not pass invalid types torecursively_get_inner_widgets().continue.