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

Props get_dave, spacedmonkey.
Fixes #56472.


git-svn-id: https://develop.svn.wordpress.org/trunk@54121 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2022-09-11 18:53:28 +00:00
parent 8f533d77d2
commit da03cf1c6b
4 changed files with 20 additions and 19 deletions
@@ -303,7 +303,10 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
$response->header( 'X-WP-TotalPages', (int) $max_pages );
$base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( $this->namespace . '/' . $this->rest_base ) );
$request_params = $request->get_query_params();
$collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) );
$base = add_query_arg( urlencode_deep( $request_params ), $collection_url );
if ( $page > 1 ) {
$prev_page = $page - 1;
@@ -893,13 +896,12 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
* @return array Links for the given term.
*/
protected function prepare_links( $term ) {
$base = $this->namespace . '/' . $this->rest_base;
$links = array(
'self' => array(
'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
'href' => rest_url( rest_get_route_for_term( $term ) ),
),
'collection' => array(
'href' => rest_url( $base ),
'href' => rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ),
),
'about' => array(
'href' => rest_url( sprintf( 'wp/v2/taxonomies/%s', $this->taxonomy ) ),
@@ -911,7 +913,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
if ( $parent_term ) {
$links['up'] = array(
'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
'href' => rest_url( rest_get_route_for_term( $parent_term ) ),
'embeddable' => true,
);
}