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 bdf1959c62..9c842d0717 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 @@ -653,7 +653,14 @@ class WP_REST_Application_Passwords_Controller extends WP_REST_Controller { protected function prepare_links( WP_User $user, $item ) { return array( 'self' => array( - 'href' => rest_url( sprintf( '%s/users/%d/application-passwords/%s', $this->namespace, $user->ID, $item['uuid'] ) ), + 'href' => rest_url( + sprintf( + '%s/users/%d/application-passwords/%s', + $this->namespace, + $user->ID, + $item['uuid'] + ) + ), ), ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php index 33409ed188..91d725c5f4 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php @@ -347,7 +347,11 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller { if ( $block_type->is_dynamic() ) { $links['https://api.w.org/render-block'] = array( - 'href' => add_query_arg( 'context', 'edit', rest_url( sprintf( '%s/%s/%s', 'wp/v2', 'block-renderer', $block_type->name ) ) ), + 'href' => add_query_arg( + 'context', + 'edit', + rest_url( sprintf( '%s/%s/%s', 'wp/v2', 'block-renderer', $block_type->name ) ) + ), ); } 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 e1b348b408..0f6d103cae 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 @@ -125,6 +125,34 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller { return urldecode( $id_or_stylesheet ); } + /** + * Get the post, if the ID is valid. + * + * @since 5.9.0 + * + * @param int $id Supplied ID. + * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. + */ + protected function get_post( $id ) { + $error = new WP_Error( + 'rest_global_styles_not_found', + __( 'No global styles config exist with that id.' ), + array( 'status' => 404 ) + ); + + $id = (int) $id; + if ( $id <= 0 ) { + return $error; + } + + $post = get_post( $id ); + if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) { + return $error; + } + + return $post; + } + /** * Checks if a given request has access to read a single global style. * @@ -377,35 +405,6 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller { return $response; } - /** - * Get the post, if the ID is valid. - * - * @since 5.9.0 - * - * @param int $id Supplied ID. - * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. - */ - protected function get_post( $id ) { - $error = new WP_Error( - 'rest_global_styles_not_found', - __( 'No global styles config exist with that id.' ), - array( 'status' => 404 ) - ); - - $id = (int) $id; - if ( $id <= 0 ) { - return $error; - } - - $post = get_post( $id ); - if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) { - return $error; - } - - return $post; - } - - /** * Prepares links for the request. * diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php index 17903fcd33..ff9ab8e48f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php @@ -207,6 +207,44 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller { return apply_filters( 'rest_prepare_menu_location', $response, $location, $request ); } + /** + * Prepares links for the request. + * + * @since 5.9.0 + * + * @param stdClass $location Menu location. + * @return array Links for the given menu location. + */ + protected function prepare_links( $location ) { + $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); + + // Entity meta. + $links = array( + 'self' => array( + 'href' => rest_url( trailingslashit( $base ) . $location->name ), + ), + 'collection' => array( + 'href' => rest_url( $base ), + ), + ); + + $locations = get_nav_menu_locations(); + $menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0; + if ( $menu ) { + $path = rest_get_route_for_term( $menu ); + if ( $path ) { + $url = rest_url( $path ); + + $links['https://api.w.org/menu'][] = array( + 'href' => $url, + 'embeddable' => true, + ); + } + } + + return $links; + } + /** * Retrieves the menu location's schema, conforming to JSON Schema. * @@ -260,42 +298,4 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller { 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ); } - - /** - * Prepares links for the request. - * - * @since 5.9.0 - * - * @param stdClass $location Menu location. - * @return array Links for the given menu location. - */ - protected function prepare_links( $location ) { - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); - - // Entity meta. - $links = array( - 'self' => array( - 'href' => rest_url( trailingslashit( $base ) . $location->name ), - ), - 'collection' => array( - 'href' => rest_url( $base ), - ), - ); - - $locations = get_nav_menu_locations(); - $menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0; - if ( $menu ) { - $path = rest_get_route_for_term( $menu ); - if ( $path ) { - $url = rest_url( $path ); - - $links['https://api.w.org/menu'][] = array( - 'href' => $url, - 'embeddable' => true, - ); - } - } - - 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 4da8e7aa18..2ba4238e4a 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 @@ -625,7 +625,14 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller { protected function prepare_links( $item ) { return array( 'self' => array( - 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, substr( $item['_file'], 0, - 4 ) ) ), + 'href' => rest_url( + sprintf( + '%s/%s/%s', + $this->namespace, + $this->rest_base, + substr( $item['_file'], 0, - 4 ) + ) + ), ), ); } 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 173125a8e1..13ecec4744 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 @@ -260,6 +260,25 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { return apply_filters( 'rest_prepare_post_type', $response, $post_type, $request ); } + /** + * Prepares links for the request. + * + * @since 6.1.0 + * + * @param WP_Post_Type $post_type The post type. + * @return array Links for the given post type. + */ + protected function prepare_links( $post_type ) { + return array( + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + 'https://api.w.org/items' => array( + 'href' => rest_url( rest_get_route_for_post_type_items( $post_type->name ) ), + ), + ); + } + /** * Retrieves the post type's schema, conforming to JSON Schema. * @@ -384,23 +403,4 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ); } - - /** - * Prepares links for the request. - * - * @since 6.1.0 - * - * @param WP_Post_Type $post_type The post type. - * @return array Links for the given post type. - */ - protected function prepare_links( $post_type ) { - return array( - 'collection' => array( - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), - ), - 'https://api.w.org/items' => array( - 'href' => rest_url( rest_get_route_for_post_type_items( $post_type->name ) ), - ), - ); - } } diff --git a/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 bc987b42f8..7376df60df 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 @@ -288,6 +288,25 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { return apply_filters( 'rest_prepare_taxonomy', $response, $taxonomy, $request ); } + /** + * Prepares links for the request. + * + * @since 6.1.0 + * + * @param @param WP_Taxonomy $taxonomy The taxonomy. + * @return array Links for the given taxonomy. + */ + protected function prepare_links( $taxonomy ) { + return array( + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + 'https://api.w.org/items' => array( + 'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ), + ), + ); + } + /** * Retrieves the taxonomy's schema, conforming to JSON Schema. * @@ -427,24 +446,4 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { ); return $new_params; } - - /** - * Prepares links for the request. - * - * @since 6.1.0 - * - * @param @param WP_Taxonomy $taxonomy The taxonomy. - * @return array Links for the given taxonomy. - */ - protected function prepare_links( $taxonomy ) { - return array( - 'collection' => array( - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), - ), - 'https://api.w.org/items' => array( - 'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ), - ), - ); - } - }