From 4226bc868958c23cd317bda757aa2ebf2dff18c4 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Tue, 22 Jun 2021 02:58:07 +0000 Subject: [PATCH] Themes: Prevent a Full Site Editing theme from being activated when Gutenberg is not active. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a theme that uses the Full Site Editing feature is activated and the Gutenberg plugin is not present, the site will currently show a text notice on the front end. The user is not made aware of this unless they visit the front end of their site. This adds a check that will prevent a theme from being activated when the `full-site-editing` tag is present in the theme’s `style.css` header and the Gutenberg plugin is not active to prevent this scenario. These checks can be removed once Full Site Editing is completely merged into Core. Props desrosj, marybaum, chanthaboune. See #53410. git-svn-id: https://develop.svn.wordpress.org/trunk@51193 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/customize.php | 10 +++++++++- src/wp-includes/theme.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php index f2eb07e9b5..fdbc7f7b9e 100644 --- a/src/wp-admin/customize.php +++ b/src/wp-admin/customize.php @@ -184,8 +184,16 @@ do_action( 'customize_controls_head' ); theme()->get( 'RequiresWP' ) ); $compatible_php = is_php_version_compatible( $wp_customize->theme()->get( 'RequiresPHP' ) ); + $fse_safe = true; + + // Check if the theme requires the FSE to work correctly. + $theme_tags = $wp_customize->theme()->get( 'Tags' ); + + if ( ! empty( $theme_tags ) && in_array( 'full-site-editing', $theme_tags, true ) && ! is_plugin_active( 'gutenberg/gutenberg.php' ) ) { + $fse_safe = false; + } ?> - + is_theme_active() ? __( 'Publish' ) : __( 'Activate & Publish' ); ?>
diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 7d4b62684b..cbf1849d21 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -908,6 +908,20 @@ function validate_current_theme() { function validate_theme_requirements( $stylesheet ) { $theme = wp_get_theme( $stylesheet ); + // If the theme is a Full Site Editing theme, check for the presence of the Gutenberg plugin. + $theme_tags = $theme->get( 'Tags' ); + + if ( ! empty( $theme_tags ) && in_array( 'full-site-editing', $theme_tags, true ) && ! is_plugin_active( 'gutenberg/gutenberg.php' ) ) { + return new WP_Error( + 'theme_requires_fse', + sprintf( + /* translators: %s: Theme name. */ + _x( 'Error: This theme (%s) uses Full Site Editing, which requires the Gutenberg plugin to be activated.', 'theme' ), + $theme->display( 'Name' ) + ) + ); + } + $requirements = array( 'requires' => ! empty( $theme->get( 'RequiresWP' ) ) ? $theme->get( 'RequiresWP' ) : '', 'requires_php' => ! empty( $theme->get( 'RequiresPHP' ) ) ? $theme->get( 'RequiresPHP' ) : '',