wp/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php	Tue Dec 15 13:49:49 2020 +0100
@@ -11,6 +11,8 @@
  * Core class representing a search handler for posts in the REST API.
  *
  * @since 5.0.0
+ *
+ * @see WP_REST_Search_Handler
  */
 class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
 
@@ -146,7 +148,7 @@
 
 		$links = array();
 
-		$item_route = $this->detect_rest_item_route( $post );
+		$item_route = rest_get_route_for_post( $post );
 		if ( ! empty( $item_route ) ) {
 			$links['self'] = array(
 				'href'       => rest_url( $item_route ),
@@ -180,25 +182,16 @@
 	 * Attempts to detect the route to access a single item.
 	 *
 	 * @since 5.0.0
+	 * @deprecated 5.5.0 Use rest_get_route_for_post()
+	 * @see rest_get_route_for_post()
 	 *
 	 * @param WP_Post $post Post object.
 	 * @return string REST route relative to the REST base URI, or empty string if unknown.
 	 */
 	protected function detect_rest_item_route( $post ) {
-		$post_type = get_post_type_object( $post->post_type );
-		if ( ! $post_type ) {
-			return '';
-		}
+		_deprecated_function( __METHOD__, '5.5.0', 'rest_get_route_for_post()' );
 
-		// It's currently impossible to detect the REST URL from a custom controller.
-		if ( ! empty( $post_type->rest_controller_class ) && 'WP_REST_Posts_Controller' !== $post_type->rest_controller_class ) {
-			return '';
-		}
-
-		$namespace = 'wp/v2';
-		$rest_base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
-
-		return sprintf( '%s/%s/%d', $namespace, $rest_base, $post->ID );
+		return rest_get_route_for_post( $post );
 	}
 
 }