From eaad35de6b4b12bf3c8581df5fc1aa9aba501531 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 19 Jul 2022 14:52:12 +0000 Subject: [PATCH] REST API: Add `prepare_links` method to `WP_REST_Taxonomies_Controller` class. Move logic to from `prepare_item_for_response` to `prepare_links` method to bring `WP_REST_Taxonomies_Controller` class inline with other REST API controllers. Props Spacedmonkey, timothyblynjacobs, dlh. Fixes #56020. git-svn-id: https://develop.svn.wordpress.org/trunk@53722 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-rest-taxonomies-controller.php | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php index ede47585b1..bc987b42f8 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php @@ -272,16 +272,7 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { // Wrap the data in a response object. $response = rest_ensure_response( $data ); - $response->add_links( - array( - 'collection' => array( - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), - ), - 'https://api.w.org/items' => array( - 'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ), - ), - ) - ); + $response->add_links( $this->prepare_links( $taxonomy ) ); /** * Filters a taxonomy returned from the REST API. @@ -437,4 +428,23 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { return $new_params; } + /** + * Prepares links for the request. + * + * @since 6.1.0 + * + * @param @param WP_Taxonomy $taxonomy The taxonomy. + * @return array Links for the given taxonomy. + */ + protected function prepare_links( $taxonomy ) { + return array( + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + 'https://api.w.org/items' => array( + 'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ), + ), + ); + } + }