-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Block-based template parts for Classic themes #3234
Changes from all commits
0200cfd
b4de22f
ecd664a
040c485
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,15 @@ | |
); | ||
} | ||
|
||
if ( ! wp_is_block_theme() ) { | ||
if ( ! ( current_theme_supports( 'block-template-parts' ) || wp_is_block_theme() ) ) { | ||
wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) ); | ||
} | ||
|
||
$is_template_part_editor = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] ); | ||
if ( ! wp_is_block_theme() && ! $is_template_part_editor ) { | ||
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); | ||
} | ||
|
||
/** | ||
* Do a server-side redirection if missing `postType` and `postId` | ||
* query args when visiting Site Editor. | ||
|
@@ -64,14 +69,24 @@ static function( $classes ) { | |
|
||
$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); | ||
$custom_settings = array( | ||
'siteUrl' => site_url(), | ||
'postsPerPage' => get_option( 'posts_per_page' ), | ||
'styles' => get_block_editor_theme_styles(), | ||
'defaultTemplateTypes' => $indexed_template_types, | ||
'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), | ||
'__unstableHomeTemplate' => $home_template, | ||
'siteUrl' => site_url(), | ||
'postsPerPage' => get_option( 'posts_per_page' ), | ||
'styles' => get_block_editor_theme_styles(), | ||
'defaultTemplateTypes' => $indexed_template_types, | ||
'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), | ||
'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before, the Site Editor always assumed layout support. |
||
'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), | ||
'__unstableHomeTemplate' => $home_template, | ||
); | ||
|
||
/** | ||
* We don't need home template resolution when block template parts are supported. | ||
* Set the value to true to satisfy the editor initialization guard clause. | ||
*/ | ||
if ( $custom_settings['supportsTemplatePartsMode'] ) { | ||
$custom_settings['__unstableHomeTemplate'] = true; | ||
} | ||
|
||
// Add additional back-compat patterns registered by `current_screen` et al. | ||
$custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); | ||
$custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5261,7 +5261,7 @@ function wp_widgets_add_menu() { | |
} | ||
|
||
$menu_name = __( 'Widgets' ); | ||
if ( wp_is_block_theme() ) { | ||
if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this to avoid conflicts between the |
||
$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); | ||
} else { | ||
$submenu['themes.php'][7] = array( $menu_name, 'edit_theme_options', 'widgets.php' ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,6 +388,7 @@ public function test_get_item_schema() { | |
$this->assertArrayHasKey( 'align-wide', $theme_supports ); | ||
$this->assertArrayHasKey( 'automatic-feed-links', $theme_supports ); | ||
$this->assertArrayHasKey( 'block-templates', $theme_supports ); | ||
$this->assertArrayHasKey( 'block-template-parts', $theme_supports ); | ||
$this->assertArrayHasKey( 'custom-header', $theme_supports ); | ||
$this->assertArrayHasKey( 'custom-background', $theme_supports ); | ||
$this->assertArrayHasKey( 'custom-logo', $theme_supports ); | ||
|
@@ -406,7 +407,7 @@ public function test_get_item_schema() { | |
$this->assertArrayHasKey( 'responsive-embeds', $theme_supports ); | ||
$this->assertArrayHasKey( 'title-tag', $theme_supports ); | ||
$this->assertArrayHasKey( 'wp-block-styles', $theme_supports ); | ||
$this->assertCount( 21, $theme_supports ); | ||
$this->assertCount( 22, $theme_supports ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hellofromtonya I belive something like this would solve the case you uncovered in your testing here: #3234 (comment)
As far as I'm aware that was not a known issue and no patch for it had been created.
@Mamaduka asked me to keep an eye on this PR since he is out traveling. I will create a PR on the Gutenberg Repo to fix the issue there aswell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually in looking at the code in Gutenberg it was handled as a completely separate admin page. So this issue only exists in this PR and only needs to get fixed here. No backport to Gutenberg is needed.
https://github.com/WordPress/gutenberg/blob/d19258cb5b85cea52e85a3e86c9550dd48d44fca/lib/compat/wordpress-6.1/template-parts-screen.php#L5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to make it easier to test, I have also created a separate PR against @Mamaduka's branch which applies the same fix as the one I have shown in the suggestion above: Mamaduka#48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that does resolve it. Well done @fabiankaegy - thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!