Changeset 51962 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 10/31/2021 11:15:10 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/rest-api.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r51958 r51962 3050 3050 } 3051 3051 3052 $post_type = get_post_type_object( $post->post_type );3053 if ( ! $post_type ) {3052 $post_type_route = rest_get_route_for_post_type_items( $post->post_type ); 3053 if ( ! $post_type_route ) { 3054 3054 return ''; 3055 3055 } 3056 3056 3057 $controller = $post_type->get_rest_controller(); 3058 if ( ! $controller ) { 3059 return ''; 3060 } 3061 3062 $route = ''; 3063 3064 // The only two controllers that we can detect are the Attachments and Posts controllers. 3065 if ( in_array( get_class( $controller ), array( 'WP_REST_Attachments_Controller', 'WP_REST_Posts_Controller' ), true ) ) { 3066 $namespace = 'wp/v2'; 3067 $rest_base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name; 3068 $route = sprintf( '/%s/%s/%d', $namespace, $rest_base, $post->ID ); 3069 } 3057 $route = sprintf( '%s/%d', $post_type_route, $post->ID ); 3070 3058 3071 3059 /** … … 3081 3069 3082 3070 /** 3071 * Gets the REST API route for a post type. 3072 * 3073 * @since 5.9.0 3074 * 3075 * @param string $post_type The name of a registered post type. 3076 * @return string The route path with a leading slash for the given post type, or an empty string if there is not a route. 3077 */ 3078 function rest_get_route_for_post_type_items( $post_type ) { 3079 $post_type = get_post_type_object( $post_type ); 3080 if ( ! $post_type ) { 3081 return ''; 3082 } 3083 3084 if ( ! $post_type->show_in_rest ) { 3085 return ''; 3086 } 3087 3088 $namespace = ! empty( $post_type->rest_namespace ) ? $post_type->rest_namespace : 'wp/v2'; 3089 $rest_base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name; 3090 $route = sprintf( '/%s/%s', $namespace, $rest_base ); 3091 3092 /** 3093 * Filters the REST API route for a post type. 3094 * 3095 * @since 5.9.0 3096 * 3097 * @param string $route The route path. 3098 * @param WP_Post_Type $post_type The post type object. 3099 */ 3100 return apply_filters( 'rest_route_for_post_type_items', $route, $post_type ); 3101 } 3102 3103 /** 3083 3104 * Gets the REST API route for a term. 3084 3105 *
Note: See TracChangeset
for help on using the changeset viewer.