From 070bc9b5eab6189707f8d6f29da0da4d8057d1c1 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 19 Jul 2022 14:49:08 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@53721 git-svn-id: http://core.svn.wordpress.org/trunk@53280 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-post-types-controller.php | 29 ++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php index 4d27b9dea6..173125a8e1 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php @@ -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 ) ), + ), + ); + } } diff --git a/wp-includes/version.php b/wp-includes/version.php index ac4badf6f6..85d69a68b8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53720'; +$wp_version = '6.1-alpha-53721'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.