diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 2c9bf40f19..2b543be296 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -418,7 +418,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $response->header( 'X-WP-TotalPages', (int) $max_pages ); $request_params = $request->get_query_params(); - $base = add_query_arg( urlencode_deep( $request_params ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); + $collection_url = rest_url( rest_get_route_for_post_type_items( $this->post_type ) ); + $base = add_query_arg( urlencode_deep( $request_params ), $collection_url ); if ( $page > 1 ) { $prev_page = $page - 1; @@ -777,7 +778,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $response = rest_ensure_response( $response ); $response->set_status( 201 ); - $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $post_id ) ) ); + $response->header( 'Location', rest_url( rest_get_route_for_post( $post ) ) ); return $response; } @@ -2030,15 +2031,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { * @return array Links for the given post. */ protected function prepare_links( $post ) { - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); - // Entity meta. $links = array( 'self' => array( - 'href' => rest_url( trailingslashit( $base ) . $post->ID ), + 'href' => rest_url( rest_get_route_for_post( $post->ID ) ), ), 'collection' => array( - 'href' => rest_url( $base ), + 'href' => rest_url( rest_get_route_for_post_type_items( $this->post_type ) ), ), 'about' => array( 'href' => rest_url( 'wp/v2/types/' . $this->post_type ), @@ -2066,15 +2065,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) { $revisions = wp_get_latest_revision_id_and_total_count( $post->ID ); $revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0; + $revisions_base = sprintf( '/%s/%s/%d/revisions', $this->namespace, $this->rest_base, $post->ID ); $links['version-history'] = array( - 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ), + 'href' => rest_url( $revisions_base ), 'count' => $revisions_count, ); if ( $revisions_count > 0 ) { $links['predecessor-version'] = array( - 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $revisions['latest_id'] ), + 'href' => rest_url( $revisions_base . '/' . $revisions['latest_id'] ), 'id' => $revisions['latest_id'], ); } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index bea3ddac78..23f9ada215 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -334,7 +334,8 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { $response->header( 'X-WP-TotalPages', (int) $max_pages ); $request_params = $request->get_query_params(); - $base = add_query_arg( urlencode_deep( $request_params ), rest_url( sprintf( '%s/%s/%d/%s', $this->namespace, $this->parent_base, $request['parent'], $this->rest_base ) ) ); + $base_path = rest_url( sprintf( '%s/%s/%d/%s', $this->namespace, $this->parent_base, $request['parent'], $this->rest_base ) ); + $base = add_query_arg( urlencode_deep( $request_params ), $base_path ); if ( $page > 1 ) { $prev_page = $page - 1; @@ -620,7 +621,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { $response = rest_ensure_response( $data ); if ( ! empty( $data['parent'] ) ) { - $response->add_link( 'parent', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->parent_base, $data['parent'] ) ) ); + $response->add_link( 'parent', rest_url( rest_get_route_for_post( $data['parent'] ) ) ); } /** diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index 6d70372cbc..7e60674890 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -687,14 +687,12 @@ class WP_REST_Templates_Controller extends WP_REST_Controller { * @return array Links for the given post. */ protected function prepare_links( $id ) { - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); - $links = array( 'self' => array( - 'href' => rest_url( trailingslashit( $base ) . $id ), + 'href' => rest_url( rest_get_route_for_post( $id ) ), ), 'collection' => array( - 'href' => rest_url( $base ), + 'href' => rest_url( rest_get_route_for_post_type_items( $this->post_type ) ), ), 'about' => array( 'href' => rest_url( 'wp/v2/types/' . $this->post_type ), diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 3a0baeac71..52ad18d184 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -303,7 +303,10 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $response->header( 'X-WP-TotalPages', (int) $max_pages ); - $base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( $this->namespace . '/' . $this->rest_base ) ); + $request_params = $request->get_query_params(); + $collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ); + $base = add_query_arg( urlencode_deep( $request_params ), $collection_url ); + if ( $page > 1 ) { $prev_page = $page - 1; @@ -893,13 +896,12 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { * @return array Links for the given term. */ protected function prepare_links( $term ) { - $base = $this->namespace . '/' . $this->rest_base; $links = array( 'self' => array( - 'href' => rest_url( trailingslashit( $base ) . $term->term_id ), + 'href' => rest_url( rest_get_route_for_term( $term ) ), ), 'collection' => array( - 'href' => rest_url( $base ), + 'href' => rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ), ), 'about' => array( 'href' => rest_url( sprintf( 'wp/v2/taxonomies/%s', $this->taxonomy ) ), @@ -911,7 +913,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { if ( $parent_term ) { $links['up'] = array( - 'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ), + 'href' => rest_url( rest_get_route_for_term( $parent_term ) ), 'embeddable' => true, ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 24d368af53..bdd6a421ea 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54120'; +$wp_version = '6.1-alpha-54121'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.