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
This commit is contained in:
spacedmonkey 2022-07-19 14:54:08 +00:00
parent 070bc9b5ea
commit 31c061e89d
2 changed files with 21 additions and 11 deletions

View File

@ -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 ) ),
),
);
}
}

View File

@ -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.