#56472 closed defect (bug) (fixed)
rest_get_route_for_post missing usages in Posts Controller prepare_links method
Reported by: | get_dave | Owned by: | TimothyBlynJacobs |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | minor | Version: | 5.5 |
Component: | REST API | Keywords: | has-patch |
Focuses: | Cc: |
Description
Whilst working on https://github.com/WordPress/gutenberg/pull/42809#issuecomment-1231875463 we discovered that the function [rest_get_route_for_post
](https://developer.wordpress.org/reference/functions/rest_get_route_for_post/) isn't fully implemented within the WP_REST_Posts_Controller
.
As this function is filterable this can lead to inconsistencies.
https://developer.wordpress.org/reference/hooks/rest_route_for_post/
To quote:
The rest_get_route_for_post function is filterable. So it can be modified to use the slug instead of the id. But it looks like we missed some spots when implementing rest_get_route_for_post, like in prepare_links, so that will need to be addressed in a Core ticket.
Examples include:
- https://github.com/WordPress/wordpress-develop/blob/97218bbfd336035edc9293274fea0f7bd3da85d7/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1991
- https://github.com/WordPress/wordpress-develop/blob/97218bbfd336035edc9293274fea0f7bd3da85d7/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2024
- https://github.com/WordPress/wordpress-develop/blob/97218bbfd336035edc9293274fea0f7bd3da85d7/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2032
Change History (11)
#1
@
2 years ago
- Milestone changed from Awaiting Review to 6.1
- Owner set to TimothyBlynJacobs
- Status changed from new to assigned
- Version set to 5.5
This ticket was mentioned in PR #3179 on WordPress/wordpress-develop by spacedmonkey.
2 years ago
#2
- Keywords has-patch added
spacedmonkey commented on PR #3179:
2 years ago
#3
@getdave Can you take a look
#4
@
2 years ago
- Resolution set to worksforme
- Status changed from assigned to closed
I tested this by checking out https://github.com/WordPress/gutenberg/pull/42809/ which modifies the route for wp_navigation
. I then made a REST for a single Navigation post by slug
.
I received the following which indicates that these changes are 👍
spacedmonkey commented on PR #3179:
2 years ago
#5
@getdave Do you want this in 6.0.x?
spacedmonkey commented on PR #3179:
2 years ago
#7
@TimothyBJacobs Can you take a look a this please. Happy to commit.
TimothyBJacobs commented on PR #3179:
2 years ago
#8
I'm also seing usages in WP_REST_Posts_Controller::create_item
for the Location
header. We can also use rest_get_route_for_post_type_items
in WP_REST_Posts_Controller::get_items
when preparing the pagination links.
#9
@
2 years ago
- Resolution worksforme deleted
- Status changed from closed to reopened
Hi there, thanks for the ticket!
Reopening, as it looks like the PR has not been committed yet, so the closing in comment:4 appears to be unintentional.
See The Bug Tracker (Trac) for ticket resolution descriptions:
worksforme: The bug reported in the ticket cannot be reproduced. Sometimes, an existing plugin, hook, or feature may render the ticket moot, so the ticket can be closed without further action.
TimothyBJacobs commented on PR #3179:
2 years ago
#11
Merged in da03cf1c6b3ab71ea7e56f4a050d87c41150726e.
Trac ticket: https://core.trac.wordpress.org/ticket/56472