Make WordPress Core

Changeset 48381


Ignore:
Timestamp:
07/07/2020 03:29:22 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php

    r46586 r48381  
    149149        $links = array();
    150150
    151         $item_route = $this->detect_rest_item_route( $post );
     151        $item_route = rest_get_route_for_post( $post );
    152152        if ( ! empty( $item_route ) ) {
    153153            $links['self'] = array(
     
    183183     *
    184184     * @since 5.0.0
     185     * @deprecated 5.5.0 Use rest_get_route_for_post()
     186     * @see rest_get_route_for_post()
    185187     *
    186188     * @param WP_Post $post Post object.
     
    188190     */
    189191    protected function detect_rest_item_route( $post ) {
    190         $post_type = get_post_type_object( $post->post_type );
    191         if ( ! $post_type ) {
    192             return '';
    193         }
     192        _deprecated_function( __METHOD__, '5.5.0', 'rest_get_route_for_post()' );
    194193
    195         // It's currently impossible to detect the REST URL from a custom controller.
    196         if ( ! empty( $post_type->rest_controller_class ) && 'WP_REST_Posts_Controller' !== $post_type->rest_controller_class ) {
    197             return '';
    198         }
    199 
    200         $namespace = 'wp/v2';
    201         $rest_base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
    202 
    203         return sprintf( '%s/%s/%d', $namespace, $rest_base, $post->ID );
     194        return rest_get_route_for_post( $post );
    204195    }
    205196
Note: See TracChangeset for help on using the changeset viewer.