Guidelines: Fix fatal when rest_api_init fires before init (cherry-pick #78350)#78477
Merged
Conversation
* Guidelines: Add test for rest_api_init firing before init Hosts can call rest_get_server() during plugins_loaded, which fires rest_api_init before init priority 10 has had a chance to register the wp_guideline post type. The rest_api_init callbacks in lib/experimental/guidelines/index.php dereference the post type object, so without a defensive guard they fatal (controllers) or trip _doing_it_wrong (register_post_meta). This test simulates that ordering by unregistering the post type and firing rest_api_init directly. * Guidelines: Ensure post type is registered before rest_api_init callbacks init normally fires before rest_api_init, but anything that calls rest_get_server() early (e.g. from plugins_loaded) fires rest_api_init before init priority 10 has had a chance to register the wp_guideline post type. When that happens, the rest_api_init callbacks dereference a null post type object: - Gutenberg_Content_Guidelines_REST_Controller and Gutenberg_Content_Guidelines_Revisions_Controller fatal in their parent constructors (WP_REST_Posts_Controller::__construct and WP_REST_Revisions_Controller::__construct). - Gutenberg_Guidelines_Post_Type::register_post_meta trips a _doing_it_wrong notice about meta keys enabling revisions support on a subtype that does not support revisions. Add a single priority-1 rest_api_init guard that registers the post type if it does not yet exist, so all subsequent rest_api_init callbacks see a fully-registered post type regardless of how the REST server was booted. --------- Co-authored-by: Xavier Lozano Carreras <xavier.lozano.carreras@a8c.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mikachan
approved these changes
May 20, 2026
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
Slack-thread
Cherry-picks #78350 into
release/23.2.Original PR: #78350
Hosts can call
rest_get_server()duringplugins_loaded, which firesrest_api_initbeforeinitpriority 10 has had a chance to register thewp_guidelinepost type. Therest_api_initcallbacks inlib/experimental/guidelines/index.phpdereference the post type object, so without a defensive guard they fatal (controllers) or trip_doing_it_wrong(register_post_meta).This adds a single priority-1
rest_api_initguard that registers the post type if it doesn't yet exist, plus a regression test.Test plan
phpunit/experimental/guidelines/rest_get_server()is called duringplugins_loaded🤖 Generated with Claude Code