-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix route conflicts for the auto-save and revisions endpoints of the wp_template and wp_template_part post types #5194
Conversation
6e20189
to
0d6ab54
Compare
Why register late? Why not register all post type controller like this? |
I've replied in the ticket: https://core.trac.wordpress.org/ticket/56922#comment:13 |
@@ -5074,6 +5074,338 @@ mockedApiResponse.Schema = { | |||
} | |||
] | |||
}, | |||
"/wp/v2/templates/(?P<parent>[\\d]+)/revisions": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in the wp-api-generated.js
file are auto-generated, so probably it makes no sense to review them.
343426f
to
e31904c
Compare
e31904c
to
9f8d174
Compare
Closed in favor of #3533. |
What and why?
Fixes https://core.trac.wordpress.org/ticket/56922.
This PR addresses route conflicts between
WP_REST_Templates_Controller
and bothWP_REST_Revisions_Controller
andWP_REST_Autosaves_Controller
.When making REST requests to the following endpoints:
wp/v2/templates/<parent_post_id>/revisions
wp/v2/templates/<parent_post_id>/autosaves
wp/v2/template-parts/<parent_post_id>/revisions
wp/v2/template-parts/<parent_post_id>/autosaves
the
WP_REST_Templates_Controller::get_item()
method is incorrectly matched as the callback method to process these requests. This misidentification arises from the regular expression that defines the problematic route in theWP_REST_Templates_Controller
class, specifically:/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)
.In actuality, the aforementioned requests should be handled by the
WP_REST_Revisions_Controller::get_items()
andWP_REST_Autosaves_Controller::get_items()
callbacks, depending on whether it's arevisions
orautosaves
request.How
This PR modifies the order in which the routes for endpoints in
WP_REST_Templates_Controller
,WP_REST_Revisions_Controller
, andWP_REST_Autosaves_Controller
are registered.Routes in
WP_REST_Revisions_Controller
andWP_REST_Autosaves_Controller
are now registered prior to those inWP_REST_Templates_Controller
.This ensures the correct callback is matched, preventing
WP_REST_Templates_Controller::get_item()
from being mistakenly matched for the endpoints listed above.However, this change is limited to the
wp_template
andwp_template_parts
post types to mitigate the risk of introducing new bugs.