From 93bd8e9d0df9346a6923424f8135570be1bcbf36 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 7 Dec 2021 10:00:00 +0100 Subject: [PATCH] Better synchronisation between Gutenberg and Core code (#37141) --- .../wordpress-5.9/theme-templates.php} | 3 ++ .../default-template-types.php | 40 ------------------- lib/full-site-editing/edit-site-page.php | 8 +++- lib/full-site-editing/template-loader.php | 4 +- lib/load.php | 8 +--- 5 files changed, 13 insertions(+), 50 deletions(-) rename lib/{full-site-editing/block-templates.php => compat/wordpress-5.9/theme-templates.php} (95%) delete mode 100644 lib/full-site-editing/default-template-types.php diff --git a/lib/full-site-editing/block-templates.php b/lib/compat/wordpress-5.9/theme-templates.php similarity index 95% rename from lib/full-site-editing/block-templates.php rename to lib/compat/wordpress-5.9/theme-templates.php index a3db2bd0402503..bb61cf9c898cbf 100644 --- a/lib/full-site-editing/block-templates.php +++ b/lib/compat/wordpress-5.9/theme-templates.php @@ -68,4 +68,7 @@ function gutenberg_filter_wp_template_unique_post_slug( $override_slug, $slug, $ return $override_slug; } + +// Remove 5.8 filter if existant. +remove_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug' ); add_filter( 'pre_wp_unique_post_slug', 'gutenberg_filter_wp_template_unique_post_slug', 10, 5 ); diff --git a/lib/full-site-editing/default-template-types.php b/lib/full-site-editing/default-template-types.php deleted file mode 100644 index daaf3c5fb9e5ba..00000000000000 --- a/lib/full-site-editing/default-template-types.php +++ /dev/null @@ -1,40 +0,0 @@ - [ 'title' => 'Index', 'description' => 'Index template' ] ]` - * - * ...to indexed array with slug as property: - * `[ [ 'slug' => 'index', 'title' => 'Index', 'description' => 'Index template' ] ]` - * - * @return array The default template types as an indexed array. - */ -function gutenberg_get_indexed_default_template_types() { - $indexed_template_types = array(); - $default_template_types = get_default_block_template_types(); - foreach ( $default_template_types as $slug => $template_type ) { - $template_type['slug'] = (string) $slug; - $indexed_template_types[] = $template_type; - } - return $indexed_template_types; -} - -/** - * Return a list of all overrideable default template type slugs. - * - * @see get_query_template - * - * @return string[] List of all overrideable default template type slugs. - */ -function gutenberg_get_template_type_slugs() { - return array_keys( get_default_block_template_types() ); -} diff --git a/lib/full-site-editing/edit-site-page.php b/lib/full-site-editing/edit-site-page.php index 1bd0a26ff63b5c..5cf61b6b917509 100644 --- a/lib/full-site-editing/edit-site-page.php +++ b/lib/full-site-editing/edit-site-page.php @@ -148,11 +148,17 @@ static function( $classes ) { } ); + $indexed_template_types = array(); + foreach ( get_default_block_template_types() as $slug => $template_type ) { + $template_type['slug'] = (string) $slug; + $indexed_template_types[] = $template_type; + } + $custom_settings = array( 'siteUrl' => site_url(), 'postsPerPage' => get_option( 'posts_per_page' ), 'styles' => gutenberg_get_editor_styles(), - 'defaultTemplateTypes' => gutenberg_get_indexed_default_template_types(), + 'defaultTemplateTypes' => $indexed_template_types, 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), '__experimentalBlockPatterns' => WP_Block_Patterns_Registry::get_instance()->get_all_registered(), '__experimentalBlockPatternCategories' => WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(), diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index 4d38388877f699..5077d024724915 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -12,8 +12,8 @@ function gutenberg_add_template_loader_filters() { if ( ! gutenberg_supports_block_templates() ) { return; } - - foreach ( gutenberg_get_template_type_slugs() as $template_type ) { + $template_type_slugs = array_keys( get_default_block_template_types() ); + foreach ( $template_type_slugs as $template_type ) { if ( 'embed' === $template_type ) { // Skip 'embed' for now because it is not a regular template type. continue; } diff --git a/lib/load.php b/lib/load.php index 6688625bf5d76b..4bb1884c36873d 100644 --- a/lib/load.php +++ b/lib/load.php @@ -103,18 +103,12 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-5.9/class-gutenberg-block-template.php'; require __DIR__ . '/compat/wordpress-5.9/templates.php'; require __DIR__ . '/compat/wordpress-5.9/template-parts.php'; +require __DIR__ . '/compat/wordpress-5.9/theme-templates.php'; require __DIR__ . '/editor-settings.php'; - - -// These are used by some FSE features -// as well as global styles. require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-schema-gutenberg.php'; require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php'; require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-resolver-gutenberg.php'; - require __DIR__ . '/full-site-editing/full-site-editing.php'; -require __DIR__ . '/full-site-editing/block-templates.php'; -require __DIR__ . '/full-site-editing/default-template-types.php'; require __DIR__ . '/full-site-editing/template-loader.php'; require __DIR__ . '/full-site-editing/edit-site-page.php'; require __DIR__ . '/compat/wordpress-5.9/wp-theme-get-post-templates.php';