diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php index 5547e7e002f02..e013f58972ea8 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php @@ -230,7 +230,15 @@ public function prepare_item_for_response( $ability, $request ) { ), ); - $links['wp:action-run'] = array( + $category = $ability->get_category(); + if ( '' !== $category ) { + $links['up'] = array( + 'href' => rest_url( sprintf( '%s/categories/%s', $this->namespace, $category ) ), + 'embeddable' => true, + ); + } + + $links['https://api.w.org/action-run'] = array( 'href' => rest_url( sprintf( '%s/%s/%s/run', $this->namespace, $this->rest_base, $ability->get_name() ) ), ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php index 767917d6f6fd0..09fc7a96ce4e3 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php @@ -650,22 +650,25 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the request. * * @since 5.6.0 + * @since 7.2.0 Added the `collection` and `up` links. * * @param WP_User $user The requested user. * @param array $item The application password. * @return array The list of links. */ protected function prepare_links( WP_User $user, $item ) { + $collection = sprintf( '%s/users/%d/application-passwords', $this->namespace, $user->ID ); + return array( - 'self' => array( - 'href' => rest_url( - sprintf( - '%s/users/%d/application-passwords/%s', - $this->namespace, - $user->ID, - $item['uuid'] - ) - ), + 'self' => array( + 'href' => rest_url( $collection . '/' . $item['uuid'] ), + ), + 'collection' => array( + 'href' => rest_url( $collection ), + ), + 'up' => array( + 'href' => rest_url( sprintf( '%s/users/%d', $this->namespace, $user->ID ) ), + 'embeddable' => true, ), ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php index c0d58160467b2..1ed24b49515a4 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php @@ -45,9 +45,10 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { * The base of the parent controller's route. * * @since 5.0.0 + * @since 7.2.0 Changed from private to protected. * @var string */ - private $parent_base; + protected $parent_base; /** * Constructor. @@ -472,6 +473,17 @@ public function prepare_item_for_response( $item, $request ) { $response = $this->revisions_controller->prepare_item_for_response( $post, $request ); $fields = $this->get_fields_for_response( $request ); + if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { + // The revisions controller links to the revisions routes; point them at the autosaves routes instead. + $links = $this->prepare_links( $post ); + + foreach ( array_keys( $links ) as $rel ) { + $response->remove_link( $rel ); + } + + $response->add_links( $links ); + } + if ( in_array( 'preview_link', $fields, true ) ) { $parent_id = wp_is_post_autosave( $post ); $preview_post_id = false === $parent_id ? $post->ID : $parent_id; diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php index 2aaf63cd1058f..0d15f603ea881 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php @@ -796,6 +796,7 @@ protected function get_parent_font_family_post( $font_family_id ) { * Prepares links for the request. * * @since 6.5.0 + * @since 7.2.0 Added the `about` link. * * @param WP_Post $post Post object. * @return array Links for the given post. @@ -809,6 +810,9 @@ protected function prepare_links( $post ) { 'collection' => array( 'href' => rest_url( $this->namespace . '/font-families/' . $post->post_parent . '/font-faces' ), ), + 'about' => array( + 'href' => rest_url( 'wp/v2/types/' . $this->post_type ), + ), 'parent' => array( 'href' => rest_url( $this->namespace . '/font-families/' . $post->post_parent ), ), diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php index a126055b4c807..e91ae68a319e9 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php @@ -479,6 +479,7 @@ protected function get_font_face_ids( $font_family_id ) { * Prepares font family links for the request. * * @since 6.5.0 + * @since 7.2.0 Added the `about` link. * * @param WP_Post $post Post object. * @return array Links for the given post. @@ -490,6 +491,7 @@ protected function prepare_links( $post ) { return array( 'self' => $links['self'], 'collection' => $links['collection'], + 'about' => $links['about'], 'font_faces' => $this->prepare_font_face_links( $post->ID ), ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php index e9f3b281ed773..8c8416208f4d7 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php @@ -387,6 +387,7 @@ public function prepare_item_for_response( $post, $request ) { * * @since 5.9.0 * @since 6.3.0 Adds revisions count and rest URL href to version-history. + * @since 7.2.0 Added the `predecessor-version` and `https://api.w.org/theme` links. * * @param int $id ID. * @return array Links for the given post. @@ -411,6 +412,22 @@ protected function prepare_links( $id ) { 'href' => rest_url( $revisions_base ), 'count' => $revisions_count, ); + + if ( $revisions_count > 0 ) { + $links['predecessor-version'] = array( + 'href' => rest_url( $revisions_base . '/' . $revisions['latest_id'] ), + 'id' => $revisions['latest_id'], + ); + } + } + + // The `wp_theme` term name is the stylesheet of the theme the styles belong to. + $theme_terms = get_the_terms( $id, 'wp_theme' ); + + if ( is_array( $theme_terms ) && ! empty( $theme_terms ) ) { + $links['https://api.w.org/theme'] = array( + 'href' => rest_url( sprintf( 'wp/v2/themes/%s', $theme_terms[0]->name ) ), + ); } return $links; @@ -593,9 +610,15 @@ public function get_theme_item( $request ) { if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $links = array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ), ), + 'https://api.w.org/theme' => array( + 'href' => rest_url( 'wp/v2/themes/' . $request['stylesheet'] ), + ), + 'https://api.w.org/theme-style-variations' => array( + 'href' => rest_url( sprintf( '%s/%s/themes/%s/variations', $this->namespace, $this->rest_base, $request['stylesheet'] ) ), + ), ); $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme ); if ( ! empty( $resolved_theme_uris ) ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php index c5d4e89e5e1d3..d3b16f33b5ed8 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php @@ -289,6 +289,7 @@ public function get_items( $request ) { * * @since 6.3.0 * @since 6.6.0 Added resolved URI links to the response. + * @since 7.2.0 Added the `self`, `collection`, `parent`, and `author` links. * * @param WP_Post $post Post revision object. * @param WP_REST_Request $request Request object. @@ -365,6 +366,10 @@ public function prepare_item_for_response( $post, $request ) { $response = rest_ensure_response( $data ); $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme_json ); + if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { + $response->add_links( $this->prepare_links( $post ) ); + } + if ( ! empty( $resolved_theme_uris ) ) { $response->add_links( array( diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php index ab6c83f2ea6c5..d71007119aae6 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php @@ -207,10 +207,38 @@ public function prepare_item_for_response( $item, $request ) { } } - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); - return rest_ensure_response( $data ); + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); + $response = rest_ensure_response( $data ); + + if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { + $response->add_links( $this->prepare_links( $item ) ); + } + + return $response; + } + + /** + * Prepares links for the request. + * + * @since 7.2.0 + * + * @param array $item Raw icon collection as registered. + * @return array Links for the given icon collection. + */ + protected function prepare_links( $item ) { + return array( + 'self' => array( + 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $item['slug'] ) ), + ), + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + 'https://api.w.org/items' => array( + 'href' => rest_url( sprintf( '%s/icons/%s', $this->namespace, $item['slug'] ) ), + ), + ); } /** diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php index afcf80f4b25e9..0821fa8240f01 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php @@ -270,10 +270,44 @@ public function prepare_item_for_response( $item, $request ) { $data['keywords'] = isset( $item['keywords'] ) ? array_values( $item['keywords'] ) : array(); } - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); - return rest_ensure_response( $data ); + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); + $response = rest_ensure_response( $data ); + + if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { + $response->add_links( $this->prepare_links( $item ) ); + } + + return $response; + } + + /** + * Prepares links for the request. + * + * @since 7.2.0 + * + * @param array $item Raw icon as registered. + * @return array Links for the given icon. + */ + protected function prepare_links( $item ) { + $links = array( + 'self' => array( + 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $item['name'] ) ), + ), + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + ); + + if ( ! empty( $item['collection'] ) ) { + $links['up'] = array( + 'href' => rest_url( sprintf( '%s/icon-collections/%s', $this->namespace, $item['collection'] ) ), + 'embeddable' => true, + ); + } + + return $links; } /** diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php index 919714c5a96ef..a1ba0d473fdd7 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php @@ -657,6 +657,7 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the request. * * @since 5.9.0 + * @since 7.2.0 Added the `up` link to the parent menu item. * * @param WP_Post $post Post object. * @return array Links for the given post. @@ -665,6 +666,18 @@ protected function prepare_links( $post ) { $links = parent::prepare_links( $post ); $menu_item = $this->get_nav_menu_item( $post->ID ); + // Menu items store their parent in meta rather than `post_parent`, so the posts controller cannot link it. + if ( ! empty( $menu_item->menu_item_parent ) ) { + $parent_route = rest_get_route_for_post( (int) $menu_item->menu_item_parent ); + + if ( $parent_route ) { + $links['up'] = array( + 'href' => rest_url( $parent_route ), + 'embeddable' => true, + ); + } + } + if ( empty( $menu_item->object_id ) ) { return $links; } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php index d0dd5fce4cd9c..3f8fe8b7e41fd 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php @@ -623,13 +623,14 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the request. * * @since 5.5.0 + * @since 7.2.0 Added the `collection` link. * * @param array $item The plugin item. * @return array[] */ protected function prepare_links( $item ) { return array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%s', @@ -639,6 +640,9 @@ protected function prepare_links( $item ) { ) ), ), + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php index fab2307a2ea7d..8142e162919c9 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php @@ -264,6 +264,9 @@ public function prepare_item_for_response( $item, $request ) { $response = rest_ensure_response( $data ); + $response->add_link( 'self', rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $status->name ) ) ); + $response->add_link( 'collection', rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); + $rest_url = rest_url( rest_get_route_for_post_type_items( 'post' ) ); if ( 'publish' === $status->name ) { $response->add_link( 'archives', $rest_url ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php index 0a6638934693a..ae6754f54f6d1 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php @@ -294,12 +294,16 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the request. * * @since 6.1.0 + * @since 7.2.0 Added the `self` and `https://api.w.org/taxonomy` links. * * @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( + $links = array( + 'self' => array( + 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $post_type->name ) ), + ), 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), @@ -307,6 +311,17 @@ protected function prepare_links( $post_type ) { 'href' => rest_url( rest_get_route_for_post_type_items( $post_type->name ) ), ), ); + + foreach ( get_object_taxonomies( $post_type->name, 'objects' ) as $taxonomy ) { + if ( $taxonomy->show_in_rest ) { + $links['https://api.w.org/taxonomy'][] = array( + 'href' => rest_url( 'wp/v2/taxonomies/' . $taxonomy->name ), + 'taxonomy' => $taxonomy->name, + ); + } + } + + return $links; } /** diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 443f839dba6f1..1caa294cdf31c 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -2218,6 +2218,7 @@ public function protected_title_format() { * Prepares links for the request. * * @since 4.7.0 + * @since 7.2.0 Added the `children` and `https://api.w.org/autosaves` links. * * @param WP_Post $post Post object. * @return array Links for the given post. @@ -2274,6 +2275,12 @@ protected function prepare_links( $post ) { $post_type_obj = get_post_type_object( $post->post_type ); + if ( $post_type_obj->get_autosave_rest_controller() instanceof WP_REST_Autosaves_Controller && current_user_can( 'edit_post', $post->ID ) ) { + $links['https://api.w.org/autosaves'] = array( + 'href' => rest_url( sprintf( '/%s/%s/%d/autosaves', $this->namespace, $this->rest_base, $post->ID ) ), + ); + } + if ( $post_type_obj->hierarchical && ! empty( $post->post_parent ) ) { $links['up'] = array( 'href' => rest_url( rest_get_route_for_post( $post->post_parent ) ), @@ -2281,6 +2288,13 @@ protected function prepare_links( $post ) { ); } + if ( $post_type_obj->hierarchical ) { + $links['children'] = array( + 'href' => add_query_arg( 'parent', $post->ID, $links['collection']['href'] ), + 'embeddable' => true, + ); + } + // If we have a featured media, add that. $featured_media = get_post_thumbnail_id( $post->ID ); if ( $featured_media && ( 'publish' === get_post_status( $featured_media ) || current_user_can( 'read_post', $featured_media ) ) ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index 2dbba2b6d5e1d..16433b442d40c 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -44,9 +44,10 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { * The base of the parent controller's route. * * @since 4.7.0 + * @since 7.2.0 Changed from private to protected. * @var string */ - private $parent_base; + protected $parent_base; /** * Constructor. @@ -596,6 +597,7 @@ protected function prepare_items_query( $prepared_args = array(), $request = nul * @since 4.7.0 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. * @since 7.1.0 The global post is now restored to its previous value before returning. + * @since 7.2.0 Added the `self`, `collection`, and `author` links. * * @global WP_Post|null $post Global post object. * @@ -721,8 +723,8 @@ public function prepare_item_for_response( $item, $request ) { $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); - if ( ! empty( $data['parent'] ) ) { - $response->add_link( 'parent', rest_url( rest_get_route_for_post( $data['parent'] ) ) ); + if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { + $response->add_links( $this->prepare_links( $post ) ); } /** @@ -743,6 +745,42 @@ public function prepare_item_for_response( $item, $request ) { return $response; } + /** + * Prepares links for the request. + * + * @since 7.2.0 + * + * @param WP_Post $post Post revision object. + * @return array Links for the given revision. + */ + protected function prepare_links( $post ) { + $collection = sprintf( '/%s/%s/%d/%s', $this->namespace, $this->parent_base, $post->post_parent, $this->rest_base ); + + $links = array( + 'self' => array( + 'href' => rest_url( $collection . '/' . $post->ID ), + ), + 'collection' => array( + 'href' => rest_url( $collection ), + ), + ); + + if ( ! empty( $post->post_parent ) ) { + $links['parent'] = array( + 'href' => rest_url( rest_get_route_for_post( $post->post_parent ) ), + ); + } + + if ( ! empty( $post->post_author ) ) { + $links['author'] = array( + 'href' => rest_url( 'wp/v2/users/' . $post->post_author ), + 'embeddable' => true, + ); + } + + return $links; + } + /** * Restores the global post to its previous value after preparing a revision. * diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php index 082067b23eef2..3e9ff9fc37d5a 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php @@ -305,12 +305,16 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the request. * * @since 6.1.0 + * @since 7.2.0 Added the `self` and `https://api.w.org/post-type` links. * * @param WP_Taxonomy $taxonomy The taxonomy. * @return array Links for the given taxonomy. */ protected function prepare_links( $taxonomy ) { - return array( + $links = array( + 'self' => array( + 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $taxonomy->name ) ), + ), 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), @@ -318,6 +322,18 @@ protected function prepare_links( $taxonomy ) { 'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ), ), ); + + foreach ( $taxonomy->object_type as $type ) { + $post_type = get_post_type_object( $type ); + if ( $post_type && $post_type->show_in_rest ) { + $links['https://api.w.org/post-type'][] = array( + 'href' => rest_url( 'wp/v2/types/' . $post_type->name ), + 'post_type' => $post_type->name, + ); + } + } + + return $links; } /** diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php index 30e7dcdcd38c0..bfddeb2e4d0ad 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php @@ -36,9 +36,10 @@ class WP_REST_Template_Autosaves_Controller extends WP_REST_Autosaves_Controller * The base of the parent controller's route. * * @since 6.4.0 + * @since 7.2.0 Changed from private to protected. * @var string */ - private $parent_base; + protected $parent_base; /** * Constructor. @@ -237,16 +238,20 @@ protected function get_parent( $parent_id ) { * Prepares links for the request. * * @since 6.4.0 + * @since 7.2.0 Added the `collection` link. * * @param WP_Block_Template $template Template. * @return array Links for the given post. */ protected function prepare_links( $template ) { $links = array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '/%s/%s/%s/%s/%d', $this->namespace, $this->parent_base, $template->id, $this->rest_base, $template->wp_id ) ), ), - 'parent' => array( + 'collection' => array( + 'href' => rest_url( sprintf( '/%s/%s/%s/%s', $this->namespace, $this->parent_base, $template->id, $this->rest_base ) ), + ), + 'parent' => array( 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->parent_base, $template->id ) ), ), ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php index f88b60372b038..70684e72fe3da 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php @@ -35,9 +35,10 @@ class WP_REST_Template_Revisions_Controller extends WP_REST_Revisions_Controller * The base of the parent controller's route. * * @since 6.4.0 + * @since 7.2.0 Changed from private to protected. * @var string */ - private $parent_base; + protected $parent_base; /** * Constructor. @@ -268,16 +269,20 @@ public function delete_item_permissions_check( $request ) { * Prepares links for the request. * * @since 6.4.0 + * @since 7.2.0 Added the `collection` link. * * @param WP_Block_Template $template Template. * @return array Links for the given post. */ protected function prepare_links( $template ) { $links = array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '/%s/%s/%s/%s/%d', $this->namespace, $this->parent_base, $template->id, $this->rest_base, $template->wp_id ) ), ), - 'parent' => array( + 'collection' => array( + 'href' => rest_url( sprintf( '/%s/%s/%s/%s', $this->namespace, $this->parent_base, $template->id, $this->rest_base ) ), + ), + 'parent' => array( 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->parent_base, $template->id ) ), ), ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index 190eea6b203bb..3453597e7a0fa 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -966,6 +966,7 @@ private static function get_wp_templates_author_text_field( $template_object ) { * Prepares links for the request. * * @since 5.8.0 + * @since 7.2.0 Added the `author`, `https://api.w.org/theme`, and `https://api.w.org/autosaves` links. * * @param int $id ID. * @return array Links for the given post. @@ -983,8 +984,32 @@ protected function prepare_links( $id ) { ), ); + $template = get_block_template( $id, $this->post_type ); + + if ( $template instanceof WP_Block_Template ) { + $theme = wp_get_theme( $template->theme ); + if ( $theme->exists() ) { + $links['https://api.w.org/theme'] = array( + 'href' => rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ), + ); + } + + $post_type = get_post_type_object( $this->post_type ); + if ( ! empty( $template->wp_id ) && $post_type->get_autosave_rest_controller() instanceof WP_REST_Template_Autosaves_Controller && current_user_can( 'edit_post', $template->wp_id ) ) { + $links['https://api.w.org/autosaves'] = array( + 'href' => $links['self']['href'] . '/autosaves', + ); + } + } + + if ( $template instanceof WP_Block_Template && ! empty( $template->author ) ) { + $links['author'] = array( + 'href' => rest_url( 'wp/v2/users/' . $template->author ), + 'embeddable' => true, + ); + } + if ( post_type_supports( $this->post_type, 'revisions' ) ) { - $template = get_block_template( $id, $this->post_type ); if ( $template instanceof WP_Block_Template && ! empty( $template->wp_id ) ) { $revisions = wp_get_latest_revision_id_and_total_count( $template->wp_id ); $revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0; diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 1f7d676dfa893..69439724e5fc3 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -1010,6 +1010,13 @@ protected function prepare_links( $term ) { $taxonomy_obj = get_taxonomy( $term->taxonomy ); + if ( $taxonomy_obj->hierarchical ) { + $links['children'] = array( + 'href' => add_query_arg( 'parent', $term->term_id, $links['collection']['href'] ), + 'embeddable' => true, + ); + } + if ( empty( $taxonomy_obj->object_type ) ) { return $links; } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index dbdb46333f29b..66f682a82bb16 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -392,9 +392,10 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the request. * * @since 5.7.0 + * @since 7.2.0 Added the `up`, `https://api.w.org/theme-global-styles`, and `https://api.w.org/theme-style-variations` links. * * @param WP_Theme $theme Theme data. - * @return array Links for the given block type. + * @return array Links for the given theme. */ protected function prepare_links( $theme ) { $links = array( @@ -406,7 +407,22 @@ protected function prepare_links( $theme ) { ), ); + $parent = $theme->parent(); + if ( $parent && $parent->exists() ) { + $links['up'] = array( + 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $parent->get_stylesheet() ) ), + ); + } + if ( $this->is_same_theme( $theme, wp_get_theme() ) ) { + $styles_url = rest_url( 'wp/v2/global-styles/themes/' . $theme->get_stylesheet() ); + $links['https://api.w.org/theme-global-styles'] = array( + 'href' => $styles_url, + ); + $links['https://api.w.org/theme-style-variations'] = array( + 'href' => $styles_url . '/variations', + ); + // This creates a record for the active theme if not existent. $id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); } else { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 9b25cf7974cbc..ed65e9feb6453 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -1146,6 +1146,7 @@ public function prepare_item_for_response( $item, $request ) { * Prepares links for the user request. * * @since 4.7.0 + * @since 7.2.0 Added the `https://api.w.org/application-passwords` and `https://api.w.org/post_type` links. * * @param WP_User $user User object. * @return array Links for the given user. @@ -1160,6 +1161,39 @@ protected function prepare_links( $user ) { ), ); + // Only link to application passwords for viewers who may list them, so availability is not revealed to others. + if ( current_user_can( 'list_app_passwords', $user->ID ) && wp_is_application_passwords_available_for_user( $user ) ) { + $links['https://api.w.org/application-passwords'] = array( + 'href' => rest_url( sprintf( '%s/%s/%d/application-passwords', $this->namespace, $this->rest_base, $user->ID ) ), + ); + } + + $post_type_links = array(); + + foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { + // Only the posts controller supports filtering a collection by author. + if ( ! post_type_supports( $post_type->name, 'author' ) + || ! $post_type->get_rest_controller() instanceof WP_REST_Posts_Controller + ) { + continue; + } + + $rest_path = rest_get_route_for_post_type_items( $post_type->name ); + + if ( empty( $rest_path ) ) { + continue; + } + + $post_type_links[] = array( + 'href' => add_query_arg( 'author', $user->ID, rest_url( $rest_path ) ), + 'post_type' => $post_type->name, + ); + } + + if ( ! empty( $post_type_links ) ) { + $links['https://api.w.org/post_type'] = $post_type_links; + } + return $links; } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index 9b25298c347ba..1bd942b13ad69 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -776,7 +776,7 @@ protected function prepare_links( $prepared ) { 'embeddable' => true, ), 'https://api.w.org/sidebar' => array( - 'href' => rest_url( sprintf( 'wp/v2/sidebars/%s/', $prepared['sidebar'] ) ), + 'href' => rest_url( sprintf( 'wp/v2/sidebars/%s', $prepared['sidebar'] ) ), ), ); } diff --git a/tests/phpstan/baselines/method.childParameterType.neon b/tests/phpstan/baselines/method.childParameterType.neon index 7ddc1325be94c..c9bc195b33df4 100644 --- a/tests/phpstan/baselines/method.childParameterType.neon +++ b/tests/phpstan/baselines/method.childParameterType.neon @@ -48,8 +48,18 @@ parameters: identifier: method.childParameterType count: 1 path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php + - + message: '#^Parameter \#1 \$template \(WP_Block_Template\) of method WP_REST_Template_Autosaves_Controller\:\:prepare_links\(\) should be compatible with parameter \$post \(WP_Post\) of method WP_REST_Revisions_Controller\:\:prepare_links\(\)$#' + identifier: method.childParameterType + count: 1 + path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php - message: '#^Parameter \#1 \$parent_template_id \(string\) of method WP_REST_Template_Revisions_Controller\:\:get_parent\(\) should be compatible with parameter \$parent_post_id \(int\) of method WP_REST_Revisions_Controller\:\:get_parent\(\)$#' identifier: method.childParameterType count: 1 path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php + - + message: '#^Parameter \#1 \$template \(WP_Block_Template\) of method WP_REST_Template_Revisions_Controller\:\:prepare_links\(\) should be compatible with parameter \$post \(WP_Post\) of method WP_REST_Revisions_Controller\:\:prepare_links\(\)$#' + identifier: method.childParameterType + count: 1 + path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php diff --git a/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php b/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php index 44b2521226d37..9b71ccb6d0f0a 100644 --- a/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php +++ b/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php @@ -1120,6 +1120,8 @@ protected function check_font_face_data( $data, $post_id, $links ) { $this->assertSame( $expected, $links['self'][0]['href'], 'The links URL from the response data should match the post\'s REST endpoint.' ); $expected = rest_url( 'wp/v2/font-families/' . $post->post_parent . '/font-faces' ); $this->assertSame( $expected, $links['collection'][0]['href'], 'The links collection URL from the response data should match the REST endpoint.' ); + $expected = rest_url( 'wp/v2/types/wp_font_face' ); + $this->assertSame( $expected, $links['about'][0]['href'], 'The links about URL from the response data should match the post type REST endpoint.' ); $expected = rest_url( 'wp/v2/font-families/' . $post->post_parent ); $this->assertSame( $expected, $links['parent'][0]['href'], 'The links for a parent URL from the response data should match the parent\'s REST endpoint.' ); } diff --git a/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php b/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php index f3d95513b4e47..d6450ff17ae00 100644 --- a/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php +++ b/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php @@ -1065,6 +1065,8 @@ protected function check_font_family_data( $data, $post_id, $links ) { $this->assertSame( $expected, $links['self'][0]['href'], 'The links URL from the response data should match the post\'s REST endpoint.' ); $expected = rest_url( 'wp/v2/font-families' ); $this->assertSame( $expected, $links['collection'][0]['href'], 'The links collection URL from the response data should match the REST endpoint.' ); + $expected = rest_url( 'wp/v2/types/wp_font_family' ); + $this->assertSame( $expected, $links['about'][0]['href'], 'The links about URL from the response data should match the post type REST endpoint.' ); if ( ! $font_face_ids ) { return; diff --git a/tests/phpunit/tests/icons/wpRestIconCollectionsController.php b/tests/phpunit/tests/icons/wpRestIconCollectionsController.php index 7ed2473a30652..4192b7cedc898 100644 --- a/tests/phpunit/tests/icons/wpRestIconCollectionsController.php +++ b/tests/phpunit/tests/icons/wpRestIconCollectionsController.php @@ -114,6 +114,11 @@ public function test_get_item() { $this->assertSame( 'REST Test', $data['label'] ); $this->assertSame( 'A REST test collection.', $data['description'] ); + $links = $response->get_links(); + $this->assertSame( rest_url( 'wp/v2/icon-collections/rest-test-collection' ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/icon-collections' ), $links['collection'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/icons/rest-test-collection' ), $links['https://api.w.org/items'][0]['href'] ); + wp_unregister_icon_collection( 'rest-test-collection' ); } diff --git a/tests/phpunit/tests/icons/wpRestIconsController.php b/tests/phpunit/tests/icons/wpRestIconsController.php index 7a06a4a88846e..ba8488bd64dae 100644 --- a/tests/phpunit/tests/icons/wpRestIconsController.php +++ b/tests/phpunit/tests/icons/wpRestIconsController.php @@ -380,6 +380,12 @@ public function test_get_item_returns_specific_icon() { $this->assertTrue( $processor->next_token() ); $this->assertSame( 'SVG', $processor->get_tag(), 'Icon content should match the actual SVG asset' ); $this->assertSame( 'http://www.w3.org/2000/svg', $processor->get_attribute( 'xmlns' ), 'Icon content should match the actual SVG asset' ); + + $links = $response->get_links(); + $this->assertSame( rest_url( 'wp/v2/icons/core/arrow-left' ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/icons' ), $links['collection'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/icon-collections/core' ), $links['up'][0]['href'] ); + $this->assertTrue( $links['up'][0]['attributes']['embeddable'] ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php index 060a5c0912a94..835181ff9ba89 100644 --- a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php +++ b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php @@ -222,6 +222,22 @@ public function test_get_item() { $this->check_response( $response->get_data(), $item ); } + /** + * @covers WP_REST_Application_Passwords_Controller::prepare_links + */ + public function test_get_item_links() { + wp_set_current_user( self::$admin ); + list( , $item ) = WP_Application_Passwords::create_new_application_password( self::$admin, array( 'name' => 'App' ) ); + + $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$admin, $item['uuid'] ) ); + $links = $response->get_links(); + + $this->assertSame( rest_url( sprintf( 'wp/v2/users/%d/application-passwords/%s', self::$admin, $item['uuid'] ) ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( sprintf( 'wp/v2/users/%d/application-passwords', self::$admin ) ), $links['collection'][0]['href'] ); + $this->assertSame( rest_url( sprintf( 'wp/v2/users/%d', self::$admin ) ), $links['up'][0]['href'] ); + $this->assertTrue( $links['up'][0]['attributes']['embeddable'] ); + } + /** * @ticket 42790 */ diff --git a/tests/phpunit/tests/rest-api/rest-autosaves-controller.php b/tests/phpunit/tests/rest-api/rest-autosaves-controller.php index 24779b97c7d31..beab855900cf1 100644 --- a/tests/phpunit/tests/rest-api/rest-autosaves-controller.php +++ b/tests/phpunit/tests/rest-api/rest-autosaves-controller.php @@ -728,7 +728,11 @@ protected function check_get_autosave_response( $response, $autosave ) { $parent_controller = new WP_REST_Posts_Controller( $parent->post_type ); $parent_object = get_post_type_object( $parent->post_type ); $parent_base = ! empty( $parent_object->rest_base ) ? $parent_object->rest_base : $parent_object->name; + $autosaves_base = '/wp/v2/' . $parent_base . '/' . $autosave->post_parent . '/autosaves'; + $this->assertSame( rest_url( $autosaves_base . '/' . $autosave->ID ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( $autosaves_base ), $links['collection'][0]['href'] ); $this->assertSame( rest_url( '/wp/v2/' . $parent_base . '/' . $autosave->post_parent ), $links['parent'][0]['href'] ); + $this->assertSame( rest_url( '/wp/v2/users/' . $autosave->post_author ), $links['author'][0]['href'] ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index 5d1f893d87fd4..6051213752e39 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -1234,6 +1234,7 @@ protected function check_taxonomy_term( $term, $data, $links ) { 'self', 'collection', 'about', + 'children', 'https://api.w.org/post_type', ); @@ -1243,6 +1244,8 @@ protected function check_taxonomy_term( $term, $data, $links ) { $this->assertSameSets( $relations, array_keys( $links ) ); $this->assertStringContainsString( 'wp/v2/taxonomies/' . $term->taxonomy, $links['about'][0]['href'] ); + $this->assertSame( add_query_arg( 'parent', $term->term_id, rest_url( 'wp/v2/categories' ) ), $links['children'][0]['href'] ); + $this->assertTrue( $links['children'][0]['attributes']['embeddable'] ); $this->assertSame( add_query_arg( 'categories', $term->term_id, rest_url( 'wp/v2/posts' ) ), $links['https://api.w.org/post_type'][0]['href'] ); } diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php index 420e0b4e5b12f..daa940543b79d 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php @@ -588,6 +588,72 @@ public function test_get_item() { $this->assertStringContainsString( '/wp/v2/global-styles/' . self::$global_styles_id, $links['self'][0]['href'] ); } + /** + * @covers WP_REST_Global_Styles_Controller::get_theme_item + */ + public function test_get_theme_item_links_include_theme_and_variations() { + wp_set_current_user( self::$admin_id ); + $response = rest_do_request( '/wp/v2/global-styles/themes/' . get_stylesheet() ); + $this->assertSame( 200, $response->get_status() ); + $links = $response->get_links(); + $this->assertSame( rest_url( 'wp/v2/themes/' . get_stylesheet() ), $links['https://api.w.org/theme'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/global-styles/themes/' . get_stylesheet() . '/variations' ), $links['https://api.w.org/theme-style-variations'][0]['href'] ); + } + + /** + * @covers WP_REST_Global_Styles_Controller::prepare_links + */ + public function test_get_item_links() { + wp_set_current_user( self::$admin_id ); + + // The fixture is created without a current user, so its `tax_input` is not applied. + wp_set_post_terms( self::$global_styles_id, 'tt1-blocks', 'wp_theme' ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( rest_url( 'wp/v2/global-styles/' . self::$global_styles_id ), $links['self'][0]['href'], 'The self link should point at the global styles post.' ); + $this->assertSame( rest_url( 'wp/v2/types/wp_global_styles' ), $links['about'][0]['href'], 'The about link should point at the post type.' ); + $this->assertSame( rest_url( 'wp/v2/themes/tt1-blocks' ), $links['https://api.w.org/theme'][0]['href'], 'The theme link should point at the theme the styles belong to.' ); + $this->assertSame( rest_url( 'wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ), $links['version-history'][0]['href'], 'The version-history link should point at the revisions.' ); + $this->assertSame( 0, $links['version-history'][0]['attributes']['count'], 'There should be no revisions yet.' ); + $this->assertArrayNotHasKey( 'predecessor-version', $links, 'There should be no predecessor-version link without revisions.' ); + } + + /** + * @covers WP_REST_Global_Styles_Controller::prepare_links + */ + public function test_get_item_links_include_predecessor_version() { + wp_set_current_user( self::$admin_id ); + wp_update_post( + array( + 'ID' => self::$global_styles_id, + 'post_content' => wp_json_encode( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'isGlobalStylesUserThemeJSON' => true, + 'styles' => array( + 'color' => array( + 'background' => 'hotpink', + ), + ), + ) + ), + ) + ); + $revisions = wp_get_latest_revision_id_and_total_count( self::$global_styles_id ); + $this->assertGreaterThan( 0, $revisions['count'], 'Updating the post should have created a revision.' ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( $revisions['count'], $links['version-history'][0]['attributes']['count'], 'The version-history count should match the number of revisions.' ); + $this->assertSame( rest_url( 'wp/v2/global-styles/' . self::$global_styles_id . '/revisions/' . $revisions['latest_id'] ), $links['predecessor-version'][0]['href'], 'The predecessor-version link should point at the latest revision.' ); + $this->assertSame( $revisions['latest_id'], $links['predecessor-version'][0]['attributes']['id'], 'The predecessor-version id should be the latest revision.' ); + } + /** * @doesNotPerformAssertions */ diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php index b323f7e367740..25b211f5bcb45 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php @@ -386,6 +386,26 @@ public function test_get_item() { $this->check_get_revision_response( $data, $this->revision_1 ); } + /** + * @covers WP_REST_Global_Styles_Revisions_Controller::prepare_item_for_response + * @covers WP_REST_Revisions_Controller::prepare_links + */ + public function test_get_item_links() { + wp_set_current_user( self::$admin_id ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/' . $this->revision_1_id ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $revisions_base = 'wp/v2/global-styles/' . self::$global_styles_id . '/revisions'; + + $this->assertSame( rest_url( $revisions_base . '/' . $this->revision_1_id ), $links['self'][0]['href'], 'The self link should point at the revision.' ); + $this->assertSame( rest_url( $revisions_base ), $links['collection'][0]['href'], 'The collection link should point at the revisions of the global styles post.' ); + $this->assertSame( rest_url( 'wp/v2/global-styles/' . self::$global_styles_id ), $links['parent'][0]['href'], 'The parent link should point at the global styles post.' ); + $this->assertSame( rest_url( 'wp/v2/users/' . $this->revision_1->post_author ), $links['author'][0]['href'], 'The author link should point at the revision author.' ); + $this->assertTrue( $links['author'][0]['attributes']['embeddable'], 'The author link should be embeddable.' ); + } + /** * @ticket 56481 * @@ -468,6 +488,7 @@ public function test_get_item_embed_context() { 'date', 'id', 'parent', + '_links', ); $data = $response->get_data(); $this->assertSameSets( $fields, array_keys( $data[0] ) ); diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index 003abff8ac4c5..b6a3673b11c2b 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -806,4 +806,32 @@ protected function set_post_data( $args = array() ) { $args['type'] = 'page'; return $args; } + + /** + * @covers WP_REST_Posts_Controller::prepare_links + */ + public function test_get_item_links_include_children() { + $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); + $child_id = self::factory()->post->create( + array( + 'post_type' => 'page', + 'post_parent' => $page_id, + ) + ); + + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( add_query_arg( 'parent', $page_id, rest_url( 'wp/v2/pages' ) ), $links['children'][0]['href'] ); + $this->assertTrue( $links['children'][0]['attributes']['embeddable'] ); + $this->assertArrayNotHasKey( 'up', $links ); + + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $child_id ) ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( rest_url( sprintf( 'wp/v2/pages/%d', $page_id ) ), $links['up'][0]['href'] ); + $this->assertSame( add_query_arg( 'parent', $child_id, rest_url( 'wp/v2/pages' ) ), $links['children'][0]['href'] ); + } } diff --git a/tests/phpunit/tests/rest-api/rest-plugins-controller.php b/tests/phpunit/tests/rest-api/rest-plugins-controller.php index 1d4311a21f251..dd46772290d88 100644 --- a/tests/phpunit/tests/rest-api/rest-plugins-controller.php +++ b/tests/phpunit/tests/rest-api/rest-plugins-controller.php @@ -942,6 +942,8 @@ public function test_prepare_item() { $links = $response->get_links(); $this->assertArrayHasKey( 'self', $links ); $this->assertSame( rest_url( self::BASE . '/' . self::PLUGIN ), $links['self'][0]['href'] ); + $this->assertArrayHasKey( 'collection', $links ); + $this->assertSame( rest_url( self::BASE ), $links['collection'][0]['href'] ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php b/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php index f6bb1d795a114..cf6c4659e4252 100644 --- a/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php @@ -212,10 +212,14 @@ protected function check_post_status_obj( $status_obj, $data, $links ) { $this->assertSame( $status_obj->name, $data['slug'] ); $this->assertSameSets( array( + 'self', + 'collection', 'archives', ), array_keys( $links ) ); + $this->assertSame( rest_url( 'wp/v2/statuses/' . $status_obj->name ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/statuses' ), $links['collection'][0]['href'] ); $this->assertSame( $status_obj->date_floating, $data['date_floating'] ); } diff --git a/tests/phpunit/tests/rest-api/rest-post-types-controller.php b/tests/phpunit/tests/rest-api/rest-post-types-controller.php index f230373ce27a4..6f49646cf6869 100644 --- a/tests/phpunit/tests/rest-api/rest-post-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-types-controller.php @@ -144,6 +144,25 @@ public static function data_head_request_with_specified_fields_returns_success_r ); } + /** + * @covers WP_REST_Post_Types_Controller::prepare_links + */ + public function test_get_item_links_include_only_rest_taxonomies() { + register_taxonomy( 'hidden_taxonomy', 'post', array( 'show_in_rest' => false ) ); + try { + $response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/types/post' ) ); + $hrefs = wp_list_pluck( $response->get_links()['https://api.w.org/taxonomy'], 'href' ); + $this->assertContains( rest_url( 'wp/v2/taxonomies/category' ), $hrefs ); + $this->assertContains( rest_url( 'wp/v2/taxonomies/post_tag' ), $hrefs ); + $this->assertNotContains( rest_url( 'wp/v2/taxonomies/hidden_taxonomy' ), $hrefs ); + foreach ( $response->get_links()['https://api.w.org/taxonomy'] as $link ) { + $this->assertSame( rest_url( 'wp/v2/taxonomies/' . $link['attributes']['taxonomy'] ), $link['href'] ); + } + } finally { + unregister_taxonomy( 'hidden_taxonomy' ); + } + } + /** * @ticket 53656 */ @@ -369,8 +388,10 @@ protected function check_post_type_obj( $context, $post_type_obj, $data, $links $this->assertSame( ! empty( $post_type_obj->template_lock ) ? $post_type_obj->template_lock : false, $data['template_lock'] ); $links = test_rest_expand_compact_links( $links ); + $this->assertSame( rest_url( 'wp/v2/types/' . $post_type_obj->name ), $links['self'][0]['href'] ); $this->assertSame( rest_url( 'wp/v2/types' ), $links['collection'][0]['href'] ); $this->assertArrayHasKey( 'https://api.w.org/items', $links ); + $this->assertSame( rest_url( rest_get_route_for_post_type_items( $post_type_obj->name ) ), $links['https://api.w.org/items'][0]['href'] ); if ( 'edit' === $context ) { $this->assertSame( $post_type_obj->cap, $data['capabilities'] ); $this->assertSame( $post_type_obj->labels, $data['labels'] ); diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 1dd9805c21692..c42a39e646950 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -2255,6 +2255,9 @@ public function test_get_item_links() { $this->assertSame( 0, $links['version-history'][0]['attributes']['count'] ); $this->assertArrayNotHasKey( 'predecessor-version', $links ); + // Only hierarchical post types link to their children. + $this->assertArrayNotHasKey( 'children', $links ); + $attachments_url = rest_url( '/wp/v2/media' ); $attachments_url = add_query_arg( 'parent', self::$post_id, $attachments_url ); $this->assertSame( $attachments_url, $links['https://api.w.org/attachment'][0]['href'] ); @@ -2283,6 +2286,43 @@ public function test_get_item_links() { $this->assertSame( $category_url, $cat_link['href'] ); } + public function test_get_item_links_autosaves_require_permission_and_support() { + $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id ); + wp_set_current_user( 0 ); + $response = rest_get_server()->dispatch( $request ); + $this->assertArrayNotHasKey( 'https://api.w.org/autosaves', $response->get_links() ); + + wp_set_current_user( self::$editor_id ); + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( rest_url( 'wp/v2/posts/' . self::$post_id . '/autosaves' ), $response->get_links()['https://api.w.org/autosaves'][0]['href'] ); + + remove_post_type_support( 'post', 'autosave' ); + try { + $response = rest_get_server()->dispatch( $request ); + $this->assertArrayNotHasKey( 'https://api.w.org/autosaves', $response->get_links() ); + } finally { + add_post_type_support( 'post', 'autosave' ); + } + } + + public function test_get_item_links_autosaves_ignore_filtered_post_route() { + wp_set_current_user( self::$editor_id ); + $filter = static function () { + return '/custom/v1/posts/filtered'; + }; + add_filter( 'rest_route_for_post', $filter ); + try { + $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id ); + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 200, $response->get_status() ); + $links = $response->get_links(); + $this->assertSame( rest_url( '/custom/v1/posts/filtered' ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/posts/' . self::$post_id . '/autosaves' ), $links['https://api.w.org/autosaves'][0]['href'] ); + } finally { + remove_filter( 'rest_route_for_post', $filter ); + } + } + public function test_get_item_links_predecessor() { wp_update_post( array( diff --git a/tests/phpunit/tests/rest-api/rest-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-revisions-controller.php index a4e89863c7a2c..72827290b771b 100644 --- a/tests/phpunit/tests/rest-api/rest-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-revisions-controller.php @@ -922,7 +922,11 @@ protected function check_get_revision_response( $response, $revision ) { $parent_controller = new WP_REST_Posts_Controller( $parent->post_type ); $parent_object = get_post_type_object( $parent->post_type ); $parent_base = ! empty( $parent_object->rest_base ) ? $parent_object->rest_base : $parent_object->name; + $revisions_base = '/wp/v2/' . $parent_base . '/' . $revision->post_parent . '/revisions'; + $this->assertSame( rest_url( $revisions_base . '/' . $revision->ID ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( $revisions_base ), $links['collection'][0]['href'] ); $this->assertSame( rest_url( '/wp/v2/' . $parent_base . '/' . $revision->post_parent ), $links['parent'][0]['href'] ); + $this->assertSame( rest_url( '/wp/v2/users/' . $revision->post_author ), $links['author'][0]['href'] ); } /** diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 9ee6cc4cbed16..37342d22e17f0 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -232,6 +232,9 @@ public function test_build_wp_api_client_fixtures() { $this->markTestSkipped( 'This test can only be run on example.org' ); } + // Availability depends on the environment type, which would make the user fixtures differ between runs. + add_filter( 'wp_is_application_passwords_available', '__return_true' ); + // Set up data for individual endpoint responses. We need to specify // lots of different fields on these objects, otherwise the generated // fixture file will be different between runs of PHPUnit tests, which @@ -601,6 +604,7 @@ public function test_build_wp_api_client_fixtures() { 'PostsCollection.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4', 'PostsCollection.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts', 'PostsCollection.0._links.about.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/types/post', + 'PostsCollection.0._links.wp:autosaves.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/autosaves', 'PostsCollection.0._links.replies.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4', 'PostsCollection.0._links.version-history.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions', 'PostsCollection.0._links.predecessor-version.0.id' => 6, @@ -617,13 +621,19 @@ public function test_build_wp_api_client_fixtures() { 'postRevisions.0.parent' => 4, 'postRevisions.0.slug' => '4-autosave-v1', 'postRevisions.0.guid.rendered' => 'http://example.org/?p=6', + 'postRevisions.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions/6', + 'postRevisions.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions', 'postRevisions.0._links.parent.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4', + 'postRevisions.0._links.author.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'postRevisions.1.author' => 2, 'postRevisions.1.id' => 5, 'postRevisions.1.parent' => 4, 'postRevisions.1.slug' => '4-revision-v1', 'postRevisions.1.guid.rendered' => 'http://example.org/?p=5', + 'postRevisions.1._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions/5', + 'postRevisions.1._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions', 'postRevisions.1._links.parent.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4', + 'postRevisions.1._links.author.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'revision.author' => 2, 'revision.id' => 5, 'revision.parent' => 4, @@ -634,7 +644,10 @@ public function test_build_wp_api_client_fixtures() { 'postAutosaves.0.parent' => 4, 'postAutosaves.0.slug' => '4-autosave-v1', 'postAutosaves.0.guid.rendered' => 'http://example.org/?p=6', + 'postAutosaves.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/autosaves/6', + 'postAutosaves.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4/autosaves', 'postAutosaves.0._links.parent.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/posts/4', + 'postAutosaves.0._links.author.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'autosave.author' => 2, 'autosave.id' => 6, 'autosave.parent' => 4, @@ -647,10 +660,12 @@ public function test_build_wp_api_client_fixtures() { 'PagesCollection.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7', 'PagesCollection.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages', 'PagesCollection.0._links.about.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/types/page', + 'PagesCollection.0._links.wp:autosaves.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/autosaves', 'PagesCollection.0._links.replies.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7', 'PagesCollection.0._links.version-history.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions', 'PagesCollection.0._links.predecessor-version.0.id' => 9, 'PagesCollection.0._links.predecessor-version.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/9', + 'PagesCollection.0._links.children.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fpages&parent=7', 'PagesCollection.0._links.wp:attachment.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7', 'PageModel.id' => 7, 'PageModel.class_list.0' => 'post-7', @@ -661,13 +676,19 @@ public function test_build_wp_api_client_fixtures() { 'pageRevisions.0.parent' => 7, 'pageRevisions.0.slug' => '7-autosave-v1', 'pageRevisions.0.guid.rendered' => 'http://example.org/?p=9', + 'pageRevisions.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/9', + 'pageRevisions.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions', 'pageRevisions.0._links.parent.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7', + 'pageRevisions.0._links.author.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'pageRevisions.1.author' => 2, 'pageRevisions.1.id' => 8, 'pageRevisions.1.parent' => 7, 'pageRevisions.1.slug' => '7-revision-v1', 'pageRevisions.1.guid.rendered' => 'http://example.org/?p=8', + 'pageRevisions.1._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/8', + 'pageRevisions.1._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions', 'pageRevisions.1._links.parent.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7', + 'pageRevisions.1._links.author.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'pageRevision.author' => 2, 'pageRevision.id' => 8, 'pageRevision.parent' => 7, @@ -678,7 +699,10 @@ public function test_build_wp_api_client_fixtures() { 'pageAutosaves.0.parent' => 7, 'pageAutosaves.0.slug' => '7-autosave-v1', 'pageAutosaves.0.guid.rendered' => 'http://example.org/?p=9', + 'pageAutosaves.0._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/autosaves/9', + 'pageAutosaves.0._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7/autosaves', 'pageAutosaves.0._links.parent.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/pages/7', + 'pageAutosaves.0._links.author.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'pageAutosave.author' => 2, 'pageAutosave.id' => 9, 'pageAutosave.parent' => 7, @@ -756,6 +780,10 @@ public function test_build_wp_api_client_fixtures() { 'UsersCollection.1.link' => 'http://example.org/?author=2', 'UsersCollection.1._links.self.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2', 'UsersCollection.1._links.collection.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users', + 'UsersCollection.1._links.wp:application-passwords.0.href' => 'http://example.org/index.php?rest_route=/wp/v2/users/2/application-passwords', + 'UsersCollection.1._links.wp:post_type.0.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&author=2', + 'UsersCollection.1._links.wp:post_type.1.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fpages&author=2', + 'UsersCollection.1._links.wp:post_type.2.href' => 'http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&author=2', 'UserModel.id' => 2, 'UserModel.link' => 'http://example.org/?author=2', 'me.id' => 2, diff --git a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php index 4d8a57d5602b8..7186dd9376900 100644 --- a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php +++ b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php @@ -153,6 +153,29 @@ public function test_get_item() { $this->check_taxonomy_object_response( 'view', $response ); } + public function test_get_item_links_include_only_rest_post_types() { + register_post_type( + 'hidden_type', + array( + 'show_in_rest' => false, + 'taxonomies' => array( 'category' ), + ) + ); + try { + $response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' ) ); + $links = $response->get_links(); + $this->assertArrayNotHasKey( 'https://api.w.org/post_type', $links ); + $hrefs = wp_list_pluck( $links['https://api.w.org/post-type'], 'href' ); + $this->assertContains( rest_url( 'wp/v2/types/post' ), $hrefs ); + $this->assertNotContains( rest_url( 'wp/v2/types/hidden_type' ), $hrefs ); + foreach ( $links['https://api.w.org/post-type'] as $link ) { + $this->assertSame( rest_url( 'wp/v2/types/' . $link['attributes']['post_type'] ), $link['href'] ); + } + } finally { + unregister_post_type( 'hidden_type' ); + } + } + /** * @dataProvider data_readable_http_methods * @ticket 56481 @@ -387,8 +410,10 @@ protected function check_taxonomy_object( $context, $tax_obj, $data, $links ) { $this->assertSame( $tax_obj->hierarchical, $data['hierarchical'] ); $this->assertSame( $tax_obj->rest_base, $data['rest_base'] ); $this->assertSame( $tax_obj->rest_namespace, $data['rest_namespace'] ); + $this->assertSame( rest_url( 'wp/v2/taxonomies/' . $tax_obj->name ), $links['self'][0]['href'] ); $this->assertSame( rest_url( 'wp/v2/taxonomies' ), $links['collection'][0]['href'] ); $this->assertArrayHasKey( 'https://api.w.org/items', $links ); + $this->assertSame( rest_url( rest_get_route_for_taxonomy_items( $tax_obj->name ) ), $links['https://api.w.org/items'][0]['href'] ); if ( 'edit' === $context ) { $this->assertSame( $tax_obj->cap, $data['capabilities'] ); $this->assertSame( $tax_obj->labels, $data['labels'] ); diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 9c5a7ec0e8a07..511e116a77307 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -1461,6 +1461,24 @@ public function test_get_item() { $this->assertSameSets( $fields_links, array_keys( $links ) ); } + public function test_get_item_links_parent_and_active_theme_styles() { + wp_set_current_user( self::$admin_id ); + $response = rest_do_request( '/wp/v2/themes/block-theme-child' ); + $this->assertSame( 200, $response->get_status() ); + $links = $response->get_links(); + $this->assertSame( rest_url( 'wp/v2/themes/block-theme' ), $links['up'][0]['href'] ); + $this->assertArrayNotHasKey( 'https://api.w.org/theme-global-styles', $links ); + $this->assertArrayNotHasKey( 'https://api.w.org/theme-style-variations', $links ); + + $response = rest_do_request( '/wp/v2/themes/' . get_stylesheet() ); + $links = $response->get_links(); + $this->assertSame( rest_url( 'wp/v2/global-styles/themes/' . get_stylesheet() ), $links['https://api.w.org/theme-global-styles'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/global-styles/themes/' . get_stylesheet() . '/variations' ), $links['https://api.w.org/theme-style-variations'][0]['href'] ); + + $response = rest_do_request( '/wp/v2/themes/block-theme' ); + $this->assertArrayNotHasKey( 'up', $response->get_links() ); + } + /** * @ticket 50152 */ diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index f0b63fcff80a4..5834bf1daf290 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -3376,17 +3376,97 @@ protected function check_user_data( $user, $data, $context, $links ) { $this->assertArrayNotHasKey( 'locale', $data ); } - $this->assertSameSets( - array( - 'self', - 'collection', - ), - array_keys( $links ) + $expected_links = array( + 'self', + 'collection', + 'https://api.w.org/post_type', ); + if ( current_user_can( 'list_app_passwords', $user->ID ) && wp_is_application_passwords_available_for_user( $user ) ) { + $expected_links[] = 'https://api.w.org/application-passwords'; + } + + $links = test_rest_expand_compact_links( $links ); + unset( $links['curies'] ); + + $this->assertSameSets( $expected_links, array_keys( $links ) ); + $this->assertArrayNotHasKey( 'password', $data ); } + /** + * @covers WP_REST_Users_Controller::prepare_links + */ + public function test_get_item_links() { + add_filter( 'wp_is_application_passwords_available', '__return_true' ); + wp_set_current_user( self::$superadmin ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . self::$editor ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( rest_url( 'wp/v2/users/' . self::$editor ), $links['self'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/users' ), $links['collection'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/users/' . self::$editor . '/application-passwords' ), $links['https://api.w.org/application-passwords'][0]['href'] ); + + $post_type_links = wp_list_pluck( $links['https://api.w.org/post_type'], 'href', null ); + $post_types = array_column( array_column( $links['https://api.w.org/post_type'], 'attributes' ), 'post_type' ); + + $this->assertContains( 'post', $post_types, 'Posts support authors so should be linked.' ); + $this->assertContains( 'page', $post_types, 'Pages support authors so should be linked.' ); + $this->assertContains( 'attachment', $post_types, 'Attachments support authors so should be linked.' ); + $this->assertNotContains( 'wp_block', $post_types, 'Post types without author support should not be linked.' ); + $this->assertNotContains( 'wp_template', $post_types, 'Post types not served by the posts controller should not be linked.' ); + $this->assertContains( add_query_arg( 'author', self::$editor, rest_url( 'wp/v2/posts' ) ), $post_type_links ); + $this->assertContains( add_query_arg( 'author', self::$editor, rest_url( 'wp/v2/pages' ) ), $post_type_links ); + $this->assertContains( add_query_arg( 'author', self::$editor, rest_url( 'wp/v2/media' ) ), $post_type_links ); + } + + /** + * @covers WP_REST_Users_Controller::prepare_links + */ + public function test_get_item_links_without_application_passwords() { + add_filter( 'wp_is_application_passwords_available', '__return_false' ); + wp_set_current_user( self::$superadmin ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . self::$editor ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertArrayNotHasKey( 'https://api.w.org/application-passwords', $response->get_links() ); + } + + /** + * @covers WP_REST_Users_Controller::prepare_links + */ + public function test_get_item_links_application_passwords_require_permission() { + add_filter( 'wp_is_application_passwords_available', '__return_true' ); + + if ( is_multisite() ) { + wp_set_current_user( self::$user ); + $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . self::$editor ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertSame( 200, $response->get_status() ); + $this->assertArrayNotHasKey( 'https://api.w.org/application-passwords', $response->get_links() ); + } + + wp_set_current_user( self::$editor ); + + // A user who cannot edit the requested user must not learn whether application passwords are available for them. + $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . self::$authors['r_true_p_true'] ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertSame( 200, $response->get_status() ); + $this->assertArrayNotHasKey( 'https://api.w.org/application-passwords', $response->get_links() ); + + // This user may list their own application passwords while the feature is enabled. + $request = new WP_REST_Request( 'GET', '/wp/v2/users/' . self::$editor ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertSame( 200, $response->get_status() ); + $this->assertArrayHasKey( 'https://api.w.org/application-passwords', $response->get_links() ); + } + protected function check_get_user_response( $response, $context = 'view' ) { $this->assertSame( 200, $response->get_status() ); diff --git a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php index 0315b67dd9997..5c3f9b6865ffd 100644 --- a/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php +++ b/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php @@ -614,7 +614,8 @@ public function test_ability_response_links(): void { $links = $response->get_links(); $this->assertArrayHasKey( 'self', $links ); $this->assertArrayHasKey( 'collection', $links ); - $this->assertArrayHasKey( 'wp:action-run', $links ); + $this->assertArrayHasKey( 'up', $links ); + $this->assertArrayHasKey( 'https://api.w.org/action-run', $links ); // Verify link URLs $self_link = $links['self'][0]['href']; @@ -623,8 +624,16 @@ public function test_ability_response_links(): void { $collection_link = $links['collection'][0]['href']; $this->assertStringContainsString( '/wp-abilities/v1/abilities', $collection_link ); - $run_link = $links['wp:action-run'][0]['href']; + $this->assertSame( rest_url( 'wp-abilities/v1/categories/math' ), $links['up'][0]['href'] ); + $this->assertTrue( $links['up'][0]['attributes']['embeddable'] ); + + $run_link = $links['https://api.w.org/action-run'][0]['href']; $this->assertStringContainsString( '/wp-abilities/v1/abilities/test/calculator/run', $run_link ); + + // The custom relation should be compacted to the `wp:` CURIE in the response body. + $data = rest_get_server()->response_to_data( $response, false ); + $this->assertArrayHasKey( 'wp:action-run', $data['_links'] ); + $this->assertArrayHasKey( 'curies', $data['_links'] ); } /** diff --git a/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php b/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php index 514fa3835717b..fffa7f93f8f50 100644 --- a/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php +++ b/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php @@ -1076,4 +1076,35 @@ public function test_update_item_properly_handles_slashed_data() { $new_data = $response->get_data(); $this->assertSame( $params['title'], $new_data['title']['raw'] ); } + + /** + * @covers ::prepare_links + */ + public function test_get_item_links_include_parent_menu_item() { + wp_set_current_user( self::$admin_id ); + + $child_id = wp_update_nav_menu_item( + $this->menu_id, + 0, + array( + 'menu-item-type' => 'custom', + 'menu-item-title' => 'Child', + 'menu-item-url' => '#', + 'menu-item-status' => 'publish', + 'menu-item-parent-id' => $this->menu_item_id, + ) + ); + + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/menu-items/%d', $child_id ) ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( rest_url( sprintf( 'wp/v2/menu-items/%d', $this->menu_item_id ) ), $links['up'][0]['href'] ); + $this->assertTrue( $links['up'][0]['attributes']['embeddable'] ); + + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/menu-items/%d', $this->menu_item_id ) ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertArrayNotHasKey( 'up', $response->get_links(), 'A top level menu item should not link to a parent.' ); + } } diff --git a/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php b/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php index 9ea5c5abc5f60..47aa928b4f127 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php @@ -622,6 +622,12 @@ public function test_prepare_item_with_data_provider( $parent_post_property_name "Failed asserting that the self link ends with $template_id . '/autosaves/' . $autosave_db_post->ID." ); + $this->assertStringEndsWith( + $template_id . '/autosaves', + $links['collection'][0]['href'], + "Failed asserting that the collection link ends with $template_id/autosaves." + ); + $this->assertStringEndsWith( $template_id, $links['parent'][0]['href'], diff --git a/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php b/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php index b5c4c79b00c70..8b3dba0aeff84 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php @@ -866,6 +866,15 @@ public function test_prepare_item_with_data_provider( $parent_post_property_name ) ); + $this->assertStringEndsWith( + $template_id . '/revisions', + $links['collection'][0]['href'], + sprintf( + 'Failed asserting that the collection link ends with %s.', + $template_id . '/revisions' + ) + ); + $this->assertStringEndsWith( $template_id, $links['parent'][0]['href'], diff --git a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php index f881ca1dede87..0b02a869915ec 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php @@ -628,6 +628,7 @@ public function test_get_item_from_registry() { $this->assertSame( 'Description of test template', $data['description'], 'Template description mismatch.' ); $this->assertSame( 'Test Template', $data['title']['rendered'], 'Template title mismatch.' ); $this->assertSame( 'test-plugin', $data['plugin'], 'Plugin name mismatch.' ); + $this->assertArrayNotHasKey( 'https://api.w.org/autosaves', $response->get_links() ); unregister_block_template( $template_name ); @@ -656,6 +657,8 @@ public function test_get_item_dates_are_null_for_file_backed_template() { $this->assertSame( 200, $response->get_status(), 'Fetching a file-backed template should return 200.' ); $this->assertNull( $data['date'], 'The date should be null for a file-backed template.' ); $this->assertNull( $data['modified'], 'The modified date should be null for a file-backed template.' ); + $this->assertArrayNotHasKey( 'https://api.w.org/autosaves', $response->get_links() ); + $this->assertSame( rest_url( 'wp/v2/themes/block-theme' ), $response->get_links()['https://api.w.org/theme'][0]['href'] ); } /** @@ -1269,4 +1272,53 @@ public function test_prepare_item_for_database_injects_hooked_block() { 'The hooked block was not injected into the anchor block\'s ignoredHookedBlocks metadata.' ); } + + /** + * @covers WP_REST_Templates_Controller::prepare_links + */ + public function test_get_item_links_include_theme_and_permission_gated_autosaves() { + $request = new WP_REST_Request( 'GET', '/wp/v2/templates/' . get_stylesheet() . '//my_template' ); + wp_set_current_user( self::$admin_id ); + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 200, $response->get_status() ); + $links = $response->get_links(); + $this->assertSame( rest_url( 'wp/v2/themes/' . get_stylesheet() ), $links['https://api.w.org/theme'][0]['href'] ); + $this->assertSame( rest_url( 'wp/v2/templates/' . get_stylesheet() . '//my_template/autosaves' ), $links['https://api.w.org/autosaves'][0]['href'] ); + + wp_set_current_user( self::$editor_id ); + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 200, $response->get_status() ); + $this->assertArrayNotHasKey( 'https://api.w.org/autosaves', $response->get_links() ); + } + + public function test_get_item_links_include_author() { + wp_set_current_user( self::$admin_id ); + + $post = self::factory()->post->create_and_get( + array( + 'post_type' => 'wp_template', + 'post_name' => 'authored_template', + 'post_title' => 'Authored Template', + 'post_content' => 'Content', + 'post_author' => self::$admin_id, + 'tax_input' => array( + 'wp_theme' => array( get_stylesheet() ), + ), + ) + ); + wp_set_post_terms( $post->ID, get_stylesheet(), 'wp_theme' ); + + $request = new WP_REST_Request( 'GET', '/wp/v2/templates/' . get_stylesheet() . '//authored_template' ); + $response = rest_get_server()->dispatch( $request ); + $links = $response->get_links(); + + $this->assertSame( rest_url( 'wp/v2/users/' . self::$admin_id ), $links['author'][0]['href'] ); + $this->assertTrue( $links['author'][0]['attributes']['embeddable'] ); + + // A template without an author should not link to one. + $request = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' ); + $response = rest_get_server()->dispatch( $request ); + + $this->assertArrayNotHasKey( 'author', $response->get_links() ); + } } diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 5d209f1c79820..637e68944a2bc 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -13317,6 +13317,11 @@ mockedApiResponse.PostsCollection = [ "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions/6" } ], + "wp:autosaves": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/autosaves" + } + ], "wp:attachment": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4" @@ -13420,10 +13425,31 @@ mockedApiResponse.postRevisions = [ "meta_key": "" }, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions/6", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions" + } + ], "parent": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4" } + ], + "author": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2" + } ] } }, @@ -13452,10 +13478,31 @@ mockedApiResponse.postRevisions = [ "meta_key": "" }, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions/5", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/revisions" + } + ], "parent": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4" } + ], + "author": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2" + } ] } } @@ -13513,10 +13560,31 @@ mockedApiResponse.postAutosaves = [ "meta_key": "" }, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/autosaves/6", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4/autosaves" + } + ], "parent": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/posts/4" } + ], + "author": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2" + } ] } } @@ -13633,6 +13701,17 @@ mockedApiResponse.PagesCollection = [ "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/9" } ], + "children": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fpages&parent=7" + } + ], + "wp:autosaves": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/autosaves" + } + ], "wp:attachment": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7" @@ -13718,10 +13797,31 @@ mockedApiResponse.pageRevisions = [ "meta_key": "" }, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/9", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions" + } + ], "parent": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7" } + ], + "author": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2" + } ] } }, @@ -13750,10 +13850,31 @@ mockedApiResponse.pageRevisions = [ "meta_key": "" }, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions/8", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/revisions" + } + ], "parent": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7" } + ], + "author": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2" + } ] } } @@ -13811,10 +13932,31 @@ mockedApiResponse.pageAutosaves = [ "meta_key": "" }, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/autosaves/9", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7/autosaves" + } + ], "parent": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/pages/7" } + ], + "author": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2" + } ] } } @@ -13991,6 +14133,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/post", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14001,6 +14153,16 @@ mockedApiResponse.TypesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/posts" } ], + "wp:taxonomy": [ + { + "taxonomy": "category", + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/category" + }, + { + "taxonomy": "post_tag", + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/post_tag" + } + ], "curies": [ { "name": "wp", @@ -14023,6 +14185,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/page", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14055,6 +14227,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/attachment", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14089,6 +14271,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/nav_menu_item", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14099,6 +14291,12 @@ mockedApiResponse.TypesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/menu-items" } ], + "wp:taxonomy": [ + { + "taxonomy": "nav_menu", + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/nav_menu" + } + ], "curies": [ { "name": "wp", @@ -14123,6 +14321,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_block", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14133,6 +14341,12 @@ mockedApiResponse.TypesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/blocks" } ], + "wp:taxonomy": [ + { + "taxonomy": "wp_pattern_category", + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/wp_pattern_category" + } + ], "curies": [ { "name": "wp", @@ -14155,6 +14369,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_template", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14187,6 +14411,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_template_part", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14219,6 +14453,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_global_styles", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14251,6 +14495,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_navigation", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14283,6 +14537,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_font_family", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14315,6 +14579,16 @@ mockedApiResponse.TypesCollection = { "template": [], "template_lock": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_font_face", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/types" @@ -14361,6 +14635,21 @@ mockedApiResponse.StatusesCollection = { "slug": "publish", "date_floating": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses/publish", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses" + } + ], "archives": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/posts" @@ -14375,6 +14664,21 @@ mockedApiResponse.StatusesCollection = { "slug": "future", "date_floating": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses/future", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses" + } + ], "archives": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&status=future" @@ -14389,6 +14693,21 @@ mockedApiResponse.StatusesCollection = { "slug": "draft", "date_floating": true, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses/draft", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses" + } + ], "archives": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&status=draft" @@ -14403,6 +14722,21 @@ mockedApiResponse.StatusesCollection = { "slug": "pending", "date_floating": true, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses/pending", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses" + } + ], "archives": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&status=pending" @@ -14417,6 +14751,21 @@ mockedApiResponse.StatusesCollection = { "slug": "private", "date_floating": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses/private", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses" + } + ], "archives": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&status=private" @@ -14431,6 +14780,21 @@ mockedApiResponse.StatusesCollection = { "slug": "trash", "date_floating": false, "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses/trash", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], + "collection": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/statuses" + } + ], "archives": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&status=trash" @@ -14460,6 +14824,16 @@ mockedApiResponse.TaxonomiesCollection = { "rest_base": "categories", "rest_namespace": "wp/v2", "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/category", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies" @@ -14470,6 +14844,12 @@ mockedApiResponse.TaxonomiesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/categories" } ], + "wp:post-type": [ + { + "post_type": "post", + "href": "http://example.org/index.php?rest_route=/wp/v2/types/post" + } + ], "curies": [ { "name": "wp", @@ -14490,6 +14870,16 @@ mockedApiResponse.TaxonomiesCollection = { "rest_base": "tags", "rest_namespace": "wp/v2", "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/post_tag", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies" @@ -14500,6 +14890,12 @@ mockedApiResponse.TaxonomiesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/tags" } ], + "wp:post-type": [ + { + "post_type": "post", + "href": "http://example.org/index.php?rest_route=/wp/v2/types/post" + } + ], "curies": [ { "name": "wp", @@ -14520,6 +14916,16 @@ mockedApiResponse.TaxonomiesCollection = { "rest_base": "menus", "rest_namespace": "wp/v2", "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/nav_menu", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies" @@ -14530,6 +14936,12 @@ mockedApiResponse.TaxonomiesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/menus" } ], + "wp:post-type": [ + { + "post_type": "nav_menu_item", + "href": "http://example.org/index.php?rest_route=/wp/v2/types/nav_menu_item" + } + ], "curies": [ { "name": "wp", @@ -14550,6 +14962,16 @@ mockedApiResponse.TaxonomiesCollection = { "rest_base": "wp_pattern_category", "rest_namespace": "wp/v2", "_links": { + "self": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/wp_pattern_category", + "targetHints": { + "allow": [ + "GET" + ] + } + } + ], "collection": [ { "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies" @@ -14560,6 +14982,12 @@ mockedApiResponse.TaxonomiesCollection = { "href": "http://example.org/index.php?rest_route=/wp/v2/wp_pattern_category" } ], + "wp:post-type": [ + { + "post_type": "wp_block", + "href": "http://example.org/index.php?rest_route=/wp/v2/types/wp_block" + } + ], "curies": [ { "name": "wp", @@ -14624,6 +15052,12 @@ mockedApiResponse.CategoriesCollection = [ "href": "http://example.org/index.php?rest_route=/wp/v2/taxonomies/category" } ], + "children": [ + { + "embeddable": true, + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&parent=1" + } + ], "wp:post_type": [ { "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&categories=1" @@ -14765,6 +15199,32 @@ mockedApiResponse.UsersCollection = [ { "href": "http://example.org/index.php?rest_route=/wp/v2/users" } + ], + "wp:application-passwords": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/users/1/application-passwords" + } + ], + "wp:post_type": [ + { + "post_type": "post", + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&author=1" + }, + { + "post_type": "page", + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fpages&author=1" + }, + { + "post_type": "attachment", + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&author=1" + } + ], + "curies": [ + { + "name": "wp", + "href": "https://api.w.org/{rel}", + "templated": true + } ] } }, @@ -14802,6 +15262,32 @@ mockedApiResponse.UsersCollection = [ { "href": "http://example.org/index.php?rest_route=/wp/v2/users" } + ], + "wp:application-passwords": [ + { + "href": "http://example.org/index.php?rest_route=/wp/v2/users/2/application-passwords" + } + ], + "wp:post_type": [ + { + "post_type": "post", + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fposts&author=2" + }, + { + "post_type": "page", + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fpages&author=2" + }, + { + "post_type": "attachment", + "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&author=2" + } + ], + "curies": [ + { + "name": "wp", + "href": "https://api.w.org/{rel}", + "templated": true + } ] } }