Changeset 56051
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r55992 r56051 151 151 * 152 152 * @since 6.1.0 153 * @since 6.3.0 Ignore empty templates. 153 154 * 154 155 * @param WP_REST_Request $request The request instance. … … 156 157 */ 157 158 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 ); 159 $hierarchy = get_template_hierarchy( $request['slug'], $request['is_custom'], $request['template_prefix'] ); 160 161 do { 162 $fallback_template = resolve_block_template( $request['slug'], $hierarchy, '' ); 163 array_shift( $hierarchy ); 164 } while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) ); 165 166 $response = $this->prepare_item_for_response( $fallback_template, $request ); 167 161 168 return rest_ensure_response( $response ); 162 169 } -
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r55992 r56051 838 838 $response = rest_get_server()->dispatch( $request ); 839 839 $this->assertSame( 'page', $response->get_data()['slug'], 'Should fallback to `page.html`.' ); 840 // Should fallback to `index.html`. 841 $request->set_param( 'slug', 'author' ); 842 $request->set_param( 'ignore_empty', true ); 843 $request->set_param( 'template_prefix', 'tag' ); 844 $request->set_param( 'is_custom', false ); 845 $response = rest_get_server()->dispatch( $request ); 846 $this->assertSame( 'index', $response->get_data()['slug'], 'Should fallback to `index.html` when ignore_empty is `true`.' ); 840 847 } 841 848 }
Note: See TracChangeset
for help on using the changeset viewer.