mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
This commit is contained in:
parent
847d40743a
commit
eaad35de6b
@ -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 ) ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user