- Timestamp:
- 11/08/2021 11:09:53 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r51962 r52062 157 157 $query['area'] = $request['area']; 158 158 } 159 if ( isset( $request['post_type'] ) ) { 160 $query['post_type'] = $request['post_type']; 161 } 159 162 160 163 $templates = array(); … … 188 191 */ 189 192 public function get_item( $request ) { 190 $template = get_block_template( $request['id'], $this->post_type ); 193 if ( isset( $request['source'] ) && 'theme' === $request['source'] ) { 194 $template = get_block_file_template( $request['id'], $this->post_type ); 195 } else { 196 $template = get_block_template( $request['id'], $this->post_type ); 197 } 191 198 192 199 if ( ! $template ) { … … 221 228 if ( ! $template ) { 222 229 return new WP_Error( 'rest_template_not_found', __( 'No templates exist with that id.' ), array( 'status' => 404 ) ); 230 } 231 232 if ( isset( $request['source'] ) && 'theme' === $request['source'] ) { 233 wp_delete_post( $template->wp_id, true ); 234 return $this->prepare_item_for_response( get_block_file_template( $request['id'], $this->post_type ), $request ); 223 235 } 224 236 … … 396 408 } 397 409 410 if ( 'wp_template_part' === $this->post_type ) { 411 if ( isset( $request['area'] ) ) { 412 $changes->tax_input['wp_template_part_area'] = _filter_block_template_part_area( $request['area'] ); 413 } elseif ( null !== $template && 'custom' !== $template->source && $template->area ) { 414 $changes->tax_input['wp_template_part_area'] = _filter_block_template_part_area( $template->area ); 415 } elseif ( ! $template->area ) { 416 $changes->tax_input['wp_template_part_area'] = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; 417 } 418 } 419 398 420 return $changes; 399 421 } … … 503 525 * 504 526 * @since 5.8.0 527 * @since 5.9.0 Added `'area'` and `'post_type'`. 505 528 * 506 529 * @return array Collection parameters. … … 508 531 public function get_collection_params() { 509 532 return array( 510 'context' => $this->get_context_param(),511 'wp_id' => array(533 'context' => $this->get_context_param(), 534 'wp_id' => array( 512 535 'description' => __( 'Limit to the specified post id.' ), 513 536 'type' => 'integer', 514 537 ), 538 'area' => array( 539 'description' => __( 'Limit to the specified template part area.' ), 540 'type' => 'string', 541 ), 542 'post_type' => array( 543 'description' => __( 'Post type to get the templates for.' ), 544 'type' => 'string', 545 ), 515 546 ); 516 547 } … … 520 551 * 521 552 * @since 5.8.0 553 * @since 5.9.0 Added `'area'`. 522 554 * 523 555 * @return array Item schema data. … … 597 629 ); 598 630 631 if ( 'wp_template_part' === $this->post_type ) { 632 $schema['properties']['area'] = array( 633 'description' => __( 'Where the template part is intended for use (header, footer, etc.)' ), 634 'type' => 'string', 635 'context' => array( 'embed', 'view', 'edit' ), 636 ); 637 } 638 599 639 $this->schema = $schema; 600 640
Note: See TracChangeset
for help on using the changeset viewer.