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_Post_Types_Controller class.
Move logic to from `prepare_item_for_response` to `prepare_links` method to bring `WP_REST_Post_Types_Controller` class inline with other REST API controllers. Props Spacedmonkey, timothyblynjacobs, dlh. Fixes #56019. git-svn-id: https://develop.svn.wordpress.org/trunk@53721 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
92ba1bb88e
commit
847d40743a
@ -244,16 +244,7 @@ class WP_REST_Post_Types_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_post_type_items( $post_type->name ) ),
|
||||
),
|
||||
)
|
||||
);
|
||||
$response->add_links( $this->prepare_links( $post_type ) );
|
||||
|
||||
/**
|
||||
* Filters a post type returned from the REST API.
|
||||
@ -394,4 +385,22 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares links for the request.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param WP_Post_Type $post_type The post type.
|
||||
* @return array Links for the given post type.
|
||||
*/
|
||||
protected function prepare_links( $post_type ) {
|
||||
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_post_type_items( $post_type->name ) ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user