wp/wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   168 
   168 
   169 		if ( ! $template ) {
   169 		if ( ! $template ) {
   170 			return new WP_Error(
   170 			return new WP_Error(
   171 				'rest_post_invalid_parent',
   171 				'rest_post_invalid_parent',
   172 				__( 'Invalid template parent ID.' ),
   172 				__( 'Invalid template parent ID.' ),
   173 				array( 'status' => 404 )
   173 				array( 'status' => WP_Http::NOT_FOUND )
       
   174 			);
       
   175 		}
       
   176 
       
   177 		$parent_post_id = isset( $template->wp_id ) ? (int) $template->wp_id : 0;
       
   178 
       
   179 		if ( $parent_post_id <= 0 ) {
       
   180 			return new WP_Error(
       
   181 				'rest_invalid_template',
       
   182 				__( 'Templates based on theme files can\'t have revisions.' ),
       
   183 				array( 'status' => WP_Http::BAD_REQUEST )
   174 			);
   184 			);
   175 		}
   185 		}
   176 
   186 
   177 		return get_post( $template->wp_id );
   187 		return get_post( $template->wp_id );
   178 	}
   188 	}
   187 	 * @return WP_REST_Response Response object.
   197 	 * @return WP_REST_Response Response object.
   188 	 */
   198 	 */
   189 	public function prepare_item_for_response( $item, $request ) {
   199 	public function prepare_item_for_response( $item, $request ) {
   190 		$template = _build_block_template_result_from_post( $item );
   200 		$template = _build_block_template_result_from_post( $item );
   191 		$response = $this->parent_controller->prepare_item_for_response( $template, $request );
   201 		$response = $this->parent_controller->prepare_item_for_response( $template, $request );
       
   202 
       
   203 		// Don't prepare the response body for HEAD requests.
       
   204 		if ( $request->is_method( 'HEAD' ) ) {
       
   205 			return $response;
       
   206 		}
   192 
   207 
   193 		$fields = $this->get_fields_for_response( $request );
   208 		$fields = $this->get_fields_for_response( $request );
   194 		$data   = $response->get_data();
   209 		$data   = $response->get_data();
   195 
   210 
   196 		if ( in_array( 'parent', $fields, true ) ) {
   211 		if ( in_array( 'parent', $fields, true ) ) {