Prevent blank page caused by invalid graphql_general_settings in public/User.php#78
Open
bicodrex wants to merge 1 commit intorockiger:developfrom
Open
Prevent blank page caused by invalid graphql_general_settings in public/User.php#78bicodrex wants to merge 1 commit intorockiger:developfrom
bicodrex wants to merge 1 commit intorockiger:developfrom
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.
Today, after installing the WPGraphQL plugin on my WordPress server running ReactPress v3.4.0, I noticed that pages using ReactPress were rendering blank. Checking the PHP error log, I found the following stack trace:
Oddly enough, the crash occurred even after disabling and uninstalling WPGraphQL.
Why this crashes
After some debugging, I discovered the following behavior of
get_option('graphql_general_settings'):get_option(). In this case['graphql_endpoint' => 'graphql']is used, so the code works as expected.'') if WPGraphQL has been installed but its settings page has never been saved. In this case, WordPress does not use the default value. As a result, the code tries to access['graphql_endpoint']on a string, which causes a fatal error:Uncaught TypeError: Cannot access offset of type string on stringThe fix
The proposed solution adds a safety check to ensure the option value is an array before accessing
['graphql_endpoint']. If it's not, the fallback value'graphql'is used.This prevents the crash when the option is missing or improperly initialized and ensures a more robust and fault-tolerant behavior.