#44152 closed defect (bug) (fixed)
Comments "up" link does not cover custom post types and/or REST controllers
Reported by: | dsifford | Owned by: | TimothyBlynJacobs |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | rest-api | Cc: |
Description
Currently, WP_REST_Comments_Controller
only covers built-in post types under the /wp/v2/
namespace when making "up" links.
Note that wp/v2
is hard-coded on the line above.
This causes issues if a comment falls under a custom post type with it's own REST controller falling under a different namespace.
Change History (7)
#2
@
7 years ago
@danielbachhuber Not totally sure. I'm only very loosely familiar with the internals of the API.
I went in and fixed my singular issue by hooking into rest_prepare_comment
and adjusting for the specific post type by doing a similar hard-coding of the endpoint.
One specific thing that tripped me up in the process of doing this is that it doesn't look like it's currently possible to obtain the namespace of a given object type easily (if at all).
The only thing that it appears you have access to is the rest_base
and the rest_controller_class
which, although still very useful and helpful, only allows someone to build the REST url after the namespace itself.
Digging into WP_REST_Server
, I saw that there is a get_namespaces
method and an associated get_namespace_index
method, but it ostensibly only allows you to obtain an endpoint's namespace if you have a WP_REST_Request
instance that is actively hitting that endpoint available. We don't have that in this case.
So yeah, I'm a bit stumped here. Happy to work with you and others on this though if needed.
Best case scenario I'd say would be to add a rest_namespace
field to the custom post type. That way, a full REST url could be built from the object itself, rather than just the part after the namespace.
That, or implement a public getter method for the namespace of WP_REST_Controller
.
This ticket was mentioned in PR #652 on WordPress/wordpress-develop by TimothyBJacobs.
4 years ago
#4
- Keywords has-patch has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/44152
#5
@
4 years ago
- Milestone changed from Awaiting Review to 5.6
Now that we have rest_get_route_for_post
we can support this in a fairly straightforward way. https://make.wordpress.org/core/2020/07/22/rest-api-changes-in-wordpress-5-5/
#6
@
4 years ago
- Owner set to TimothyBlynJacobs
- Resolution set to fixed
- Status changed from new to closed
In 49299:
TimothyBJacobs commented on PR #652:
4 years ago
#7
Fixed in b8cdf1be50ab8d6cfb7b3e594bc8558f64376acf.
@dsifford How would you suggest solving this issue?