[wp-trac] [WordPress Trac] #44152: Comments "up" link does not cover custom post types and/or REST controllers
WordPress Trac
noreply at wordpress.org
Fri May 18 21:54:38 UTC 2018
#44152: Comments "up" link does not cover custom post types and/or REST controllers
--------------------------+------------------------------
Reporter: dsifford | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses: rest-api
--------------------------+------------------------------
Comment (by dsifford):
@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 static getter method for the namespace of
`WP_REST_Controller`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44152#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list