Skip to content
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

WIP - Hybrid themes implementation #29298

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
953dfc1
Allow falling back to php templates
aristath Feb 16, 2021
d930f7d
inline doc
aristath Feb 16, 2021
31dad0e
Merge branch 'master' into try/templating-fallbacks
aristath Feb 24, 2021
4962acd
WIP
aristath Feb 24, 2021
3fe3ba0
Remove isFSETheme & isFSEEnabled
aristath Feb 24, 2021
414ea92
Merge branch 'master' into try/templating-take2
aristath Feb 25, 2021
c7866de
revert & refine
aristath Feb 25, 2021
670a763
Missed these in previous revert
aristath Feb 25, 2021
dbe1e8a
Add the fallback again
aristath Feb 25, 2021
e8a5bbc
cs
aristath Feb 25, 2021
c93b84f
Move option to experiments
aristath Feb 25, 2021
44dba24
Only show the experiment if not an FSE theme
aristath Feb 25, 2021
b2f7ae4
Merge branch 'master' into try/templating-take2
aristath Feb 26, 2021
30469de
Merge branch 'master' into try/templating-take2
aristath Feb 26, 2021
47e9f5f
Merge branch 'master' into try/templating-fallbacks
aristath Feb 26, 2021
0878b04
Massaging var names - pros @draganescu
aristath Feb 26, 2021
2c14b90
Merge branch 'try/templating-fallbacks' into try/templating-take2
aristath Feb 26, 2021
46eaf1c
Fix condition
aristath Feb 26, 2021
5a0f108
Run phpcbf to fix PHP CS issues
aristath Feb 26, 2021
94a48e2
Merge branch 'fix/run-phpcbf' into try/templating-fallbacks
aristath Feb 26, 2021
1fe8fce
CS fix
aristath Feb 26, 2021
b58f67e
Merge branch 'try/templating-fallbacks' into try/templating-take2
aristath Feb 26, 2021
ce82405
full-stop
aristath Feb 26, 2021
d06d6fc
Merge branch 'try/templating-fallbacks' into try/templating-take2
aristath Feb 26, 2021
fc2bb3c
Merge branch 'master' into try/templating-take2
aristath Mar 1, 2021
af13580
Merge branch 'trunk' into try/templating-fallbacks
aristath Mar 2, 2021
82bc77b
Merge branch 'try/templating-fallbacks' into try/templating-take2
aristath Mar 2, 2021
298b463
merge trunk
aristath Mar 23, 2021
9aa4fae
merge conflict
aristath Mar 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function gutenberg_menu() {
* @since 9.4.0
*/
function gutenberg_site_editor_menu() {
if ( gutenberg_is_fse_theme() ) {
if ( gutenberg_is_fse_enabled() ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow showing the site-editor if the user has opted-in, or we're in an FSE theme.

add_menu_page(
__( 'Site Editor (beta)', 'gutenberg' ),
sprintf(
Expand Down
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ function gutenberg_extend_block_editor_styles( $settings ) {
* @return array Filtered editor settings.
*/
function gutenberg_extend_block_editor_settings_with_fse_theme_flag( $settings ) {
$settings['isFSETheme'] = gutenberg_is_fse_theme();
$settings['isFSETheme'] = gutenberg_is_fse_enabled();

// Enable the new layout options for themes with a theme.json file.
$settings['supportsLayout'] = WP_Theme_JSON_Resolver::theme_has_support();
Expand Down
2 changes: 1 addition & 1 deletion lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @return bool
*/
function gutenberg_should_load_separate_block_assets() {
$load_separate_styles = gutenberg_is_fse_theme();
$load_separate_styles = gutenberg_is_fse_enabled();
/**
* Determine if separate styles will be loaded for blocks on-render or not.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function gutenberg_get_common_block_editor_settings() {
};

$settings = array(
'__unstableEnableFullSiteEditingBlocks' => gutenberg_is_fse_theme(),
'__unstableEnableFullSiteEditingBlocks' => gutenberg_is_fse_enabled(),
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
Expand Down Expand Up @@ -77,7 +77,7 @@ function gutenberg_get_common_block_editor_settings() {
* @return array Filtered settings.
*/
function gutenberg_extend_post_editor_settings( $settings ) {
$settings['__unstableEnableFullSiteEditingBlocks'] = gutenberg_is_fse_theme();
$settings['__unstableEnableFullSiteEditingBlocks'] = gutenberg_is_fse_enabled();
return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' );
Expand Down
13 changes: 13 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-widgets-in-customizer',
)
);
if ( ! gutenberg_is_fse_theme() ) {
add_settings_field(
'gutenberg-fse',
__( 'Full Site Editing', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Allow creating templates using the block editor', 'gutenberg' ),
'id' => 'gutenberg-fse',
)
);
}
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
28 changes: 17 additions & 11 deletions lib/full-site-editing/full-site-editing.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
* @package gutenberg
*/

/**
* Returns whether the FSE is enabled or not.
*
* @return boolean Whether FSE is enabled or not.
*/
function gutenberg_is_fse_enabled() {
return gutenberg_is_fse_theme() || gutenberg_is_experiment_enabled( 'gutenberg-fse' );
}

/**
* Returns whether the current theme is an FSE theme or not.
*
Expand Down Expand Up @@ -64,19 +73,16 @@ function gutenberg_remove_legacy_pages() {
*/
function gutenberg_adminbar_items( $wp_admin_bar ) {

// Early exit if not an FSE theme.
if ( ! gutenberg_is_fse_theme() ) {
return;
// Remove items if an FSE theme.
if ( gutenberg_is_fse_theme() ) {
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'customize-background' );
$wp_admin_bar->remove_node( 'customize-header' );
$wp_admin_bar->remove_node( 'widgets' );
}

// Remove customizer link.
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'customize-background' );
$wp_admin_bar->remove_node( 'customize-header' );
$wp_admin_bar->remove_node( 'widgets' );

// Add site-editor link.
if ( ! is_admin() && current_user_can( 'edit_theme_options' ) ) {
if ( gutenberg_is_fse_enabled() && ! is_admin() && current_user_can( 'edit_theme_options' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'site-editor',
Expand All @@ -101,7 +107,7 @@ function gutenberg_adminbar_items( $wp_admin_bar ) {
* @param array $menu_order Menu Order.
*/
function gutenberg_menu_order( $menu_order ) {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return $menu_order;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/full-site-editing/page-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @return array (Maybe) modified page templates array.
*/
function gutenberg_load_block_page_templates( $templates, $theme, $post, $post_type ) {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return $templates;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/full-site-editing/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Adds necessary filters to use 'wp_template' posts instead of theme template files.
*/
function gutenberg_add_template_loader_filters() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/full-site-editing/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Registers block editor 'wp_template_part' post type.
*/
function gutenberg_register_template_part_post_type() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ function gutenberg_register_template_part_post_type() {
* Registers the 'wp_template_part_area' taxonomy.
*/
function gutenberg_register_wp_template_part_area_taxonomy() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ function gutenberg_register_wp_template_part_area_taxonomy() {
* Fixes the label of the 'wp_template_part' admin menu entry.
*/
function gutenberg_fix_template_part_admin_menu_entry() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/full-site-editing/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function gutenberg_get_template_paths() {
* Registers block editor 'wp_template' post type.
*/
function gutenberg_register_template_post_type() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ function gutenberg_register_template_post_type() {
* Registers block editor 'wp_theme' taxonomy.
*/
function gutenberg_register_wp_theme_taxonomy() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ function gutenberg_grant_template_caps( array $allcaps ) {
* Fixes the label of the 'wp_template' admin menu entry.
*/
function gutenberg_fix_template_admin_menu_entry() {
if ( ! gutenberg_is_fse_theme() ) {
if ( ! gutenberg_is_fse_enabled() ) {
return;
}
global $submenu;
Expand Down
4 changes: 2 additions & 2 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function gutenberg_experimental_global_styles_settings( $settings ) {
$origin = 'theme';
if (
WP_Theme_JSON_Resolver::theme_has_support() &&
gutenberg_is_fse_theme()
gutenberg_is_fse_enabled()
) {
// Only lookup for the user data if we need it.
$origin = 'user';
Expand All @@ -224,7 +224,7 @@ function gutenberg_experimental_global_styles_settings( $settings ) {
function_exists( 'gutenberg_is_edit_site_page' ) &&
gutenberg_is_edit_site_page( $screen->id ) &&
WP_Theme_JSON_Resolver::theme_has_support() &&
gutenberg_is_fse_theme()
gutenberg_is_fse_enabled()
) {
$user_cpt_id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id();
$base_styles = WP_Theme_JSON_Resolver::get_merged_data( $theme_support_data, 'theme' )->get_raw_data();
Expand Down
15 changes: 15 additions & 0 deletions packages/edit-site/src/utils/get-closest-available-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
import { find } from 'lodash';

export default function getClosestAvailableTemplate( slug, templates ) {
// Fallback in case there are no templates.
if ( ! templates.length ) {
return {
id: 'index',
content: {
raw: '',
},
slug: 'index',
is_custom: false,
type: 'wp_template',
status: 'publish',
wp_id: null,
};
}

Comment on lines +8 to +21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part allows the creation of a new template from the dashboard. If the theme doesn't have any templates, there's nothing to fallback to and the site-editor throws errors which prevents the user from creating a template.
This is a simple tweak to allow falling back to something - even if that something is an empty string.

const template = find( templates, { slug } );
if ( template ) {
return template;
Expand Down