Skip to content

Commit

Permalink
Automatically enable FSE for FSE themes (#26500)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Nov 2, 2020
1 parent f0600a4 commit d8188cd
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 140 deletions.
21 changes: 11 additions & 10 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ function gutenberg_menu() {
'gutenberg_navigation_page'
);
}
if ( array_key_exists( 'gutenberg-full-site-editing', get_option( 'gutenberg-experiments' ) ) ) {
add_menu_page(
__( 'Site Editor (beta)', 'gutenberg' ),
__( 'Site Editor (beta)', 'gutenberg' ),
'edit_theme_options',
'gutenberg-edit-site',
'gutenberg_edit_site_page',
'dashicons-layout'
);
}
}

if ( gutenberg_is_fse_theme() ) {
add_menu_page(
__( 'Site Editor (beta)', 'gutenberg' ),
__( 'Site Editor (beta)', 'gutenberg' ),
'edit_theme_options',
'gutenberg-edit-site',
'gutenberg_edit_site_page',
'dashicons-layout'
);
}

if ( current_user_can( 'edit_posts' ) ) {
Expand Down
33 changes: 14 additions & 19 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,20 @@ function gutenberg_reregister_core_block_types() {
),
'block_names' => array_merge(
array(
'archives.php' => 'core/archives',
'block.php' => 'core/block',
'calendar.php' => 'core/calendar',
'categories.php' => 'core/categories',
'cover.php' => 'core/cover',
'latest-comments.php' => 'core/latest-comments',
'latest-posts.php' => 'core/latest-posts',
'navigation.php' => 'core/navigation',
'navigation-link.php' => 'core/navigation-link',
'rss.php' => 'core/rss',
'search.php' => 'core/search',
'shortcode.php' => 'core/shortcode',
'social-link.php' => 'core/social-link',
'tag-cloud.php' => 'core/tag-cloud',
),
! gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' )
? array()
:
array(
'archives.php' => 'core/archives',
'block.php' => 'core/block',
'calendar.php' => 'core/calendar',
'categories.php' => 'core/categories',
'cover.php' => 'core/cover',
'latest-comments.php' => 'core/latest-comments',
'latest-posts.php' => 'core/latest-posts',
'navigation.php' => 'core/navigation',
'navigation-link.php' => 'core/navigation-link',
'rss.php' => 'core/rss',
'search.php' => 'core/search',
'shortcode.php' => 'core/shortcode',
'social-link.php' => 'core/social-link',
'tag-cloud.php' => 'core/tag-cloud',
'post-author.php' => 'core/post-author',
'post-comment.php' => 'core/post-comment',
'post-comment-author.php' => 'core/post-comment-author',
Expand Down
16 changes: 2 additions & 14 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-navigation',
)
);
add_settings_field(
'gutenberg-full-site-editing',
__( 'Full Site Editing', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable Full Site Editing (Warning: A block-based theme is required for this experiment to work properly. We recommend using this only in a development environment.)', 'gutenberg' ),
'id' => 'gutenberg-full-site-editing',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down Expand Up @@ -109,10 +98,9 @@ function gutenberg_display_experiment_section() {
*/
function gutenberg_experiments_editor_settings( $settings ) {
$experiments_settings = array(
'__experimentalEnableFullSiteEditing' => gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ),
'__unstableEnableFullSiteEditingBlocks' => gutenberg_is_fse_theme(),
);

$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
if ( false !== $gradient_presets ) {
$experiments_settings['gradients'] = $gradient_presets;
}
Expand Down
30 changes: 30 additions & 0 deletions lib/full-site-editing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Full Site Editing Utils
*
* @package gutenberg
*/

/**
* Returns whether the current theme is an FSE theme or not.
*
* @return boolean Whether the current theme is an FSE theme or not.
*/
function gutenberg_is_fse_theme() {
return is_readable( STYLESHEETPATH . '/block-templates/index.html' );
}

/**
* Show a notice when a Full Site Editing theme is used.
*/
function gutenberg_full_site_editing_notice() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}
?>
<div class="notice notice-warning">
<p><?php _e( 'You\'re using an experimental Full Site Editing theme. Full Site Editing is an experimental feature and potential API changes are to be expected!', 'gutenberg' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'gutenberg_full_site_editing_notice' );
14 changes: 6 additions & 8 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ function gutenberg_is_experiment_enabled( $name ) {
require dirname( __FILE__ ) . '/compat.php';
require dirname( __FILE__ ) . '/utils.php';

// Include FSE related files only if the experiment is enabled.
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ) ) {
require dirname( __FILE__ ) . '/templates.php';
require dirname( __FILE__ ) . '/template-parts.php';
require dirname( __FILE__ ) . '/template-loader.php';
require dirname( __FILE__ ) . '/edit-site-page.php';
require dirname( __FILE__ ) . '/edit-site-export.php';
}
require dirname( __FILE__ ) . '/full-site-editing.php';
require dirname( __FILE__ ) . '/templates.php';
require dirname( __FILE__ ) . '/template-parts.php';
require dirname( __FILE__ ) . '/template-loader.php';
require dirname( __FILE__ ) . '/edit-site-page.php';
require dirname( __FILE__ ) . '/edit-site-export.php';

require dirname( __FILE__ ) . '/block-patterns.php';
require dirname( __FILE__ ) . '/blocks.php';
Expand Down
4 changes: 4 additions & 0 deletions lib/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function get_template_types() {
* Adds necessary filters to use 'wp_template' posts instead of theme template files.
*/
function gutenberg_add_template_loader_filters() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}

foreach ( get_template_types() as $template_type ) {
if ( 'embed' === $template_type ) { // Skip 'embed' for now because it is not a regular template type.
continue;
Expand Down
8 changes: 8 additions & 0 deletions lib/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* Registers block editor 'wp_template_part' post type.
*/
function gutenberg_register_template_part_post_type() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}

$labels = array(
'name' => __( 'Template Parts', 'gutenberg' ),
'singular_name' => __( 'Template Part', 'gutenberg' ),
Expand Down Expand Up @@ -88,6 +92,10 @@ function gutenberg_filter_wp_template_part_wp_unique_post_slug( $slug, $post_ID,
* Fixes the label of the 'wp_template_part' admin menu entry.
*/
function gutenberg_fix_template_part_admin_menu_entry() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}

global $submenu;
if ( ! isset( $submenu['themes.php'] ) ) {
return;
Expand Down
7 changes: 7 additions & 0 deletions lib/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function gutenberg_get_template_paths() {
* Registers block editor 'wp_template' post type.
*/
function gutenberg_register_template_post_type() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}

$labels = array(
'name' => __( 'Templates', 'gutenberg' ),
'singular_name' => __( 'Template', 'gutenberg' ),
Expand Down Expand Up @@ -124,6 +128,9 @@ function gutenberg_filter_wp_template_wp_unique_post_slug( $slug, $post_ID, $pos
* Fixes the label of the 'wp_template' admin menu entry.
*/
function gutenberg_fix_template_admin_menu_entry() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}
global $submenu;
if ( ! isset( $submenu['themes.php'] ) ) {
return;
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ _Properties_
- _codeEditingEnabled_ `boolean`: Whether or not the user can switch to the code editor
- _\_\_experimentalCanUserUseUnfilteredHTML_ `boolean`: Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.
- _\_\_experimentalBlockDirectory_ `boolean`: Whether the user has enabled the Block Directory
- _\_\_experimentalEnableFullSiteEditing_ `boolean`: Whether the user has enabled Full Site Editing
- _\_\_experimentalBlockPatterns_ `Array`: Array of objects representing the block patterns
- _\_\_experimentalBlockPatternCategories_ `Array`: Array of objects representing the block pattern categories

Expand Down
2 changes: 0 additions & 2 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const PREFERENCES_DEFAULTS = {
* @property {boolean} codeEditingEnabled Whether or not the user can switch to the code editor
* @property {boolean} __experimentalCanUserUseUnfilteredHTML Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.
* @property {boolean} __experimentalBlockDirectory Whether the user has enabled the Block Directory
* @property {boolean} __experimentalEnableFullSiteEditing Whether the user has enabled Full Site Editing
* @property {Array} __experimentalBlockPatterns Array of objects representing the block patterns
* @property {Array} __experimentalBlockPatternCategories Array of objects representing the block pattern categories
*/
Expand Down Expand Up @@ -149,7 +148,6 @@ export const SETTINGS_DEFAULTS = {
availableLegacyWidgets: {},
__experimentalCanUserUseUnfilteredHTML: false,
__experimentalBlockDirectory: false,
__experimentalEnableFullSiteEditing: false,
__mobileEnablePageTemplates: false,
__experimentalBlockPatterns: [],
__experimentalBlockPatternCategories: [],
Expand Down
9 changes: 3 additions & 6 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ export const registerCoreBlocks = (
/**
* Function to register experimental core blocks depending on editor settings.
*
* @param {Object} settings Editor settings.
*
* @param {boolean} enableFSEBlocks Whether to enable the full site editing blocks.
* @example
* ```js
* import { __experimentalRegisterExperimentalCoreBlocks } from '@wordpress/block-library';
Expand All @@ -203,15 +202,13 @@ export const registerCoreBlocks = (
*/
export const __experimentalRegisterExperimentalCoreBlocks =
process.env.GUTENBERG_PHASE === 2
? ( settings ) => {
const { __experimentalEnableFullSiteEditing } = settings;

? ( enableFSEBlocks ) => {
[
navigation,
navigationLink,

// Register Full Site Editing Blocks.
...( __experimentalEnableFullSiteEditing
...( enableFSEBlocks
? [
siteLogo,
siteTagline,
Expand Down
18 changes: 8 additions & 10 deletions packages/block-library/src/site-logo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ function render_block_core_site_logo( $attributes ) {
* Registers the `core/site-logo` block on the server.
*/
function register_block_core_site_logo() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ) ) {
register_block_type_from_metadata(
__DIR__ . '/site-logo',
array(
'render_callback' => 'render_block_core_site_logo',
)
);
add_filter( 'pre_set_theme_mod_custom_logo', 'sync_site_logo_to_theme_mod' );
add_filter( 'theme_mod_custom_logo', 'override_custom_logo_theme_mod' );
}
register_block_type_from_metadata(
__DIR__ . '/site-logo',
array(
'render_callback' => 'render_block_core_site_logo',
)
);
add_filter( 'pre_set_theme_mod_custom_logo', 'sync_site_logo_to_theme_mod' );
add_filter( 'theme_mod_custom_logo', 'override_custom_logo_theme_mod' );
}
add_action( 'init', 'register_block_core_site_logo' );

Expand Down
5 changes: 5 additions & 0 deletions packages/e2e-test-utils/src/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ export async function activateTheme( slug ) {
}
const activateButton = await themeCard.$( '.button.activate' );
await activateButton.click();
await page.waitForFunction(
() =>
document.body &&
document.body.innerText.includes( 'New theme activated' )
);
await switchUserToTest();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import {
useExperimentalFeatures,
navigationPanel,
} from '../../experimental-features';
import { navigationPanel } from '../../experimental-features';

const visitSiteEditor = async () => {
const query = addQueryArgs( '', {
Expand Down Expand Up @@ -149,12 +146,10 @@ describe( 'Multi-entity editor states', () => {
const templatePartName = 'Test Template Part Name Edit';
const nestedTPName = 'Test Nested Template Part Name Edit';

useExperimentalFeatures( [ '#gutenberg-full-site-editing' ] );

beforeAll( async () => {
await activateTheme( 'twentytwentyone-blocks' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
await activateTheme( 'twentytwentyone-blocks' );
} );

afterAll( async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import {
useExperimentalFeatures,
navigationPanel,
} from '../../experimental-features';
import { navigationPanel } from '../../experimental-features';

describe( 'Multi-entity save flow', () => {
// Selectors - usable between Post/Site editors.
Expand Down Expand Up @@ -58,12 +55,10 @@ describe( 'Multi-entity save flow', () => {
}
};

useExperimentalFeatures( [ '#gutenberg-full-site-editing' ] );

beforeAll( async () => {
await activateTheme( 'twentytwentyone-blocks' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
await activateTheme( 'twentytwentyone-blocks' );
} );

afterAll( async () => {
Expand Down
9 changes: 2 additions & 7 deletions packages/e2e-tests/specs/experiments/template-part.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import {
useExperimentalFeatures,
navigationPanel,
} from '../../experimental-features';
import { navigationPanel } from '../../experimental-features';

describe( 'Template Part', () => {
useExperimentalFeatures( [ '#gutenberg-full-site-editing' ] );

beforeAll( async () => {
await activateTheme( 'twentytwentyone-blocks' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
await activateTheme( 'twentytwentyone-blocks' );
} );
afterAll( async () => {
await trashAllPosts( 'wp_template' );
Expand Down
9 changes: 1 addition & 8 deletions packages/e2e-tests/specs/performance/site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import { basename, join } from 'path';
import { writeFileSync } from 'fs';

/**
* Internal dependencies
*/
import { useExperimentalFeatures } from '../../experimental-features';

/**
* WordPress dependencies
*/
Expand All @@ -22,12 +17,10 @@ import { addQueryArgs } from '@wordpress/url';
jest.setTimeout( 1000000 );

describe( 'Site Editor Performance', () => {
useExperimentalFeatures( [ '#gutenberg-full-site-editing' ] );

beforeAll( async () => {
await activateTheme( 'twentytwentyone-blocks' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
await activateTheme( 'twentytwentyone-blocks' );
} );
afterAll( async () => {
await trashAllPosts( 'wp_template' );
Expand Down
Loading

0 comments on commit d8188cd

Please sign in to comment.