fix: Prevent fatal error when updating options via /wp-admin/options.php #3440
+211
−6
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.
What bug does this fix? Explain your changes.
This PR fixes a fatal error that occurs when updating WPGraphQL options via
/wp-admin/options.phpwith empty string values.What the bug was:
When a user navigates to
/wp-admin/options.phpand updates a WPGraphQL option (such asgraphql_experiments_settingsorgraphql_general_settings) with an empty string value, WordPress triggers a fatalTypeError.How it was manifesting:
The error message was:
This occurred in the WordPress admin when submitting the options form, causing the entire admin dashboard to crash.
What the root cause was:
The
sanitize_options()method inSettingsRegistryhad a strictarraytype hint for its parameter. However, when WordPress calls the sanitization callback via thesanitize_option_{$option_name}filter (which happens when updating options through/wp-admin/options.php), it can pass the raw value directly - which may be a string (like an empty string'') rather than an array. This type mismatch caused the fatal error.How your fix addresses it:
The fix modifies
sanitize_options()to:mixedtype instead of strictarraytypeThis ensures compatibility with WordPress's sanitization filter behavior while maintaining the existing functionality for array-based settings.
Does this close any currently open issues?
Closes #3439
Testing Strategy
This PR follows the preferred commit structure for bugfixes:
SettingsRegistryOptionsPageCept.php) that reproduces the bug by submitting the options form with empty string valuesSettingsRegistry::sanitize_options()to handle non-array values gracefullyThis approach demonstrates that:
Test Results
Before/After Examples
Before (Buggy Behavior):
/wp-admin/options.phpin WordPress admingraphql_experiments_settingsorgraphql_general_settingswith an empty string valueAfter (No error):
/wp-admin/options.phpin WordPress admingraphql_experiments_settingsorgraphql_general_settingswith an empty string value