Make WordPress Core


Ignore:
Timestamp:
09/11/2022 06:53:28 PM (2 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Use helper functions for building routes in more places.

Props get_dave, spacedmonkey.
Fixes #56472.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r53760 r54121  
    304304        $response->header( 'X-WP-TotalPages', (int) $max_pages );
    305305
    306         $base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( $this->namespace . '/' . $this->rest_base ) );
     306        $request_params = $request->get_query_params();
     307        $collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) );
     308        $base           = add_query_arg( urlencode_deep( $request_params ), $collection_url );
     309
    307310        if ( $page > 1 ) {
    308311            $prev_page = $page - 1;
     
    894897     */
    895898    protected function prepare_links( $term ) {
    896         $base  = $this->namespace . '/' . $this->rest_base;
    897899        $links = array(
    898900            'self'       => array(
    899                 'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
     901                'href' => rest_url( rest_get_route_for_term( $term ) ),
    900902            ),
    901903            'collection' => array(
    902                 'href' => rest_url( $base ),
     904                'href' => rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ),
    903905            ),
    904906            'about'      => array(
     
    912914            if ( $parent_term ) {
    913915                $links['up'] = array(
    914                     'href'       => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
     916                    'href'       => rest_url( rest_get_route_for_term( $parent_term ) ),
    915917                    'embeddable' => true,
    916918                );
Note: See TracChangeset for help on using the changeset viewer.