WP_REST_Post_Search_Handler::detect_rest_item_route( WP_Post $post )
Attempts to detect the route to access a single item.
Description Description
Parameters Parameters
- $post
-
(WP_Post) (Required) Post object.
Return Return
(string) REST route relative to the REST base URI, or empty string if unknown.
Source Source
File: wp-includes/rest-api/search/class-wp-rest-post-search-handler.php
protected function detect_rest_item_route( $post ) {
$post_type = get_post_type_object( $post->post_type );
if ( ! $post_type ) {
return '';
}
// It's currently impossible to detect the REST URL from a custom controller.
if ( ! empty( $post_type->rest_controller_class ) && 'WP_REST_Posts_Controller' !== $post_type->rest_controller_class ) {
return '';
}
$namespace = 'wp/v2';
$rest_base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
return sprintf( '%s/%s/%d', $namespace, $rest_base, $post->ID );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |