REST API: Use new `rest_get_route_for_post()` in the post search handler.
In [48273] the rest_get_route_for_post function was introduced. This simplifies determining the REST API route for any given post object and adds a filter for custom controllers. Props ravatparmar. Fixes #50529. Built from https://develop.svn.wordpress.org/trunk@48381 git-svn-id: http://core.svn.wordpress.org/trunk@48150 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3c41801c5c
commit
0615a9ab37
|
@ -148,7 +148,7 @@ class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
|
|||
|
||||
$links = array();
|
||||
|
||||
$item_route = $this->detect_rest_item_route( $post );
|
||||
$item_route = rest_get_route_for_post( $post );
|
||||
if ( ! empty( $item_route ) ) {
|
||||
$links['self'] = array(
|
||||
'href' => rest_url( $item_route ),
|
||||
|
@ -182,25 +182,16 @@ class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
|
|||
* Attempts to detect the route to access a single item.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @deprecated 5.5.0 Use rest_get_route_for_post()
|
||||
* @see rest_get_route_for_post()
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
* @return string REST route relative to the REST base URI, or empty string if unknown.
|
||||
*/
|
||||
protected function detect_rest_item_route( $post ) {
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
if ( ! $post_type ) {
|
||||
return '';
|
||||
}
|
||||
_deprecated_function( __METHOD__, '5.5.0', 'rest_get_route_for_post()' );
|
||||
|
||||
// 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 );
|
||||
return rest_get_route_for_post( $post );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-48380';
|
||||
$wp_version = '5.5-alpha-48381';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue