Changeset 53093
- Timestamp:
- 04/07/2022 01:33:03 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/site-editor.php
r52995 r53093 22 22 if ( ! wp_is_block_theme() ) { 23 23 wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) ); 24 } 25 26 /** 27 * Do a server-side redirection if missing `postType` and `postId` 28 * query args when visiting Site Editor. 29 */ 30 $home_template = _resolve_home_block_template(); 31 if ( $home_template && empty( $_GET['postType'] ) && empty( $_GET['postId'] ) ) { 32 $redirect_url = add_query_arg( 33 $home_template, 34 admin_url( 'site-editor.php' ) 35 ); 36 wp_safe_redirect( $redirect_url ); 37 exit; 24 38 } 25 39 … … 57 71 'defaultTemplateTypes' => $indexed_template_types, 58 72 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 73 '__unstableHomeTemplate' => $home_template, 59 74 '__experimentalBlockPatterns' => WP_Block_Patterns_Registry::get_instance()->get_all_registered(), 60 75 '__experimentalBlockPatternCategories' => WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(), -
trunk/src/wp-includes/block-template.php
r52697 r53093 332 332 } 333 333 } 334 335 /** 336 * Returns the correct template for the site's home page. 337 * 338 * @access private 339 * @since 6.0.0 340 * 341 * @return array|null A template object, or null if none could be found. 342 */ 343 function _resolve_home_block_template() { 344 $show_on_front = get_option( 'show_on_front' ); 345 $front_page_id = get_option( 'page_on_front' ); 346 347 if ( 'page' === $show_on_front && $front_page_id ) { 348 return array( 349 'postType' => 'page', 350 'postId' => $front_page_id, 351 ); 352 } 353 354 $hierarchy = array( 'front-page', 'home', 'index' ); 355 $template = resolve_block_template( 'home', $hierarchy, '' ); 356 357 if ( ! $template ) { 358 return null; 359 } 360 361 return array( 362 'postType' => 'wp_template', 363 'postId' => $template->id, 364 ); 365 } -
trunk/tests/phpunit/tests/block-template.php
r52697 r53093 189 189 $this->assertSame( '', $resolved_template_path ); 190 190 } 191 192 /** 193 * Covers: https://github.com/WordPress/gutenberg/pull/38817. 194 * 195 * @ticket 55505 196 */ 197 public function test_resolve_home_block_template_default_hierarchy() { 198 $template = _resolve_home_block_template(); 199 200 $this->assertSame( 'wp_template', $template['postType'] ); 201 $this->assertSame( get_stylesheet() . '//index', $template['postId'] ); 202 } 203 204 /** 205 * @ticket 55505 206 */ 207 public function test_resolve_home_block_template_static_homepage() { 208 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 209 update_option( 'show_on_front', 'page' ); 210 update_option( 'page_on_front', $post_id ); 211 212 $template = _resolve_home_block_template(); 213 214 $this->assertSame( 'page', $template['postType'] ); 215 $this->assertSame( $post_id, $template['postId'] ); 216 217 delete_option( 'show_on_front', 'page' ); 218 } 219 220 /** 221 * @ticket 55505 222 */ 223 public function test_resolve_home_block_template_no_resolution() { 224 switch_theme( 'stylesheetonly' ); 225 $template = _resolve_home_block_template(); 226 227 $this->assertNull( $template ); 228 } 191 229 }
Note: See TracChangeset
for help on using the changeset viewer.