Rest API: add class to handle wp_navigation post type schema #4949
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.
Background
This PR is an attempt to resolve the concerns in https://core.trac.wordpress.org/ticket/58910: a hook (
wp_add_fields_to_navigation_fallback_embedded_links
) was inserted viarest_{$this->post_type}_item_schema
to manipulate thewp_navigation
post object rest response. It was added to a new file in Core and also referred to "navigation fallback", when in fact it was being applied to all wp_navigation post types.The PR that backported these changes originally for 6.3: #4713
What this PR does
The strategy in this PR is to create a new rest API class -
WP_REST_Navigation_Controller
- to overwrite theget_item_schema
method ofWP_REST_Posts_Controller
.The controller class for the
wp_navigation
custom post type has been changed fromWP_REST_Posts_Controller
toWP_REST_Navigation_Controller
.wp_add_fields_to_navigation_fallback_embedded_links
and the file it lives in has been deleted. The unit test is now covered inWP_REST_Navigation_Fallback_Controller_Test
.Tests have been added for this class.
If this PR is merged, it will require a backport to Gutenberg.
cc @scruffian @getdave @SergeyBiryukov
Trac ticket: https://core.trac.wordpress.org/ticket/58910
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.