- Timestamp:
- 09/20/2022 09:19:10 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r54121 r54269 43 43 * 44 44 * @since 5.8.0 45 * @since 6.1.0 Endpoint for fallback template content. 45 46 */ 46 47 public function register_routes() { … … 63 64 ), 64 65 'schema' => array( $this, 'get_public_item_schema' ), 66 ) 67 ); 68 69 // Get fallback template content. 70 register_rest_route( 71 $this->namespace, 72 '/' . $this->rest_base . '/lookup', 73 array( 74 array( 75 'methods' => WP_REST_Server::READABLE, 76 'callback' => array( $this, 'get_template_fallback' ), 77 'permission_callback' => array( $this, 'get_item_permissions_check' ), 78 'args' => array( 79 'slug' => array( 80 'description' => __( 'The slug of the template to get the fallback for' ), 81 'type' => 'string', 82 'required' => true, 83 ), 84 'is_custom' => array( 85 'description' => __( ' Indicates if a template is custom or part of the template hierarchy' ), 86 'type' => 'boolean', 87 ), 88 'template_prefix' => array( 89 'description' => __( 'The template prefix for the created template. This is used to extract the main template type, e.g. in `taxonomy-books` extracts the `taxonomy`' ), 90 'type' => 'string', 91 ), 92 ), 93 ), 65 94 ) 66 95 ); … … 116 145 ) 117 146 ); 147 } 148 149 /** 150 * Returns the fallback template for the given slug. 151 * 152 * @since 6.1.0 153 * 154 * @param WP_REST_Request $request The request instance. 155 * @return WP_REST_Response|WP_Error 156 */ 157 public function get_template_fallback( $request ) { 158 $hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] ); 159 $fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' ); 160 $response = $this->prepare_item_for_response( $fallback_template, $request ); 161 return rest_ensure_response( $response ); 118 162 } 119 163 … … 526 570 } 527 571 572 if ( 'wp_template' === $this->post_type && isset( $request['is_wp_suggestion'] ) ) { 573 $changes->meta_input = wp_parse_args( 574 array( 575 'is_wp_suggestion' => $request['is_wp_suggestion'], 576 ), 577 $changes->meta_input = array() 578 ); 579 } 580 528 581 if ( 'wp_template_part' === $this->post_type ) { 529 582 if ( isset( $request['area'] ) ) {
Note: See TracChangeset
for help on using the changeset viewer.