Skip to content

Commit

Permalink
REST API: Add prepare_links method to `WP_REST_Taxonomies_Controlle…
Browse files Browse the repository at this point in the history
…r` 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
  • Loading branch information
spacedmonkey committed Jul 19, 2022
1 parent 847d407 commit eaad35d
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,7 @@ public function prepare_item_for_response( $item, $request ) {
// 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.
Expand Down Expand Up @@ -437,4 +428,23 @@ public function get_collection_params() {
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 ) ),
),
);
}

}

0 comments on commit eaad35d

Please sign in to comment.