From 31c061e89df792b59a89694e8684737b4cbba24e Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 19 Jul 2022 14:54:08 +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. Built from https://develop.svn.wordpress.org/trunk@53722 git-svn-id: http://core.svn.wordpress.org/trunk@53281 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-taxonomies-controller.php | 30 ++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php index ede47585b1..bc987b42f8 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php +++ b/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 ) ), + ), + ); + } + } diff --git a/wp-includes/version.php b/wp-includes/version.php index 85d69a68b8..aabe5f1fd1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53721'; +$wp_version = '6.1-alpha-53722'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.