From e0756da7abca27598ad7ef8fd62bb2abb419780b Mon Sep 17 00:00:00 2001 From: Maggie Date: Tue, 11 May 2021 08:14:25 +0200 Subject: [PATCH] Fix core-block-patterns support on GB (#31546) * fix core-block-patterns support on GB * return early * do not register any GB patterns Co-authored-by: ntsekouras --- lib/block-patterns.php | 450 +++++++++++++++++++++-------------------- 1 file changed, 230 insertions(+), 220 deletions(-) diff --git a/lib/block-patterns.php b/lib/block-patterns.php index 8d0c4b025a0ca..4b7cdcc4b209c 100644 --- a/lib/block-patterns.php +++ b/lib/block-patterns.php @@ -5,234 +5,244 @@ * @package gutenberg */ -// Register categories used for block patterns. -register_block_pattern_category( 'query', array( 'label' => __( 'Query', 'gutenberg' ) ) ); - -// Initial Query block patterns. -register_block_pattern( - 'query/standard-posts', - array( - 'title' => __( 'Standard', 'gutenberg' ), - 'blockTypes' => array( 'core/query' ), - 'categories' => array( 'query' ), - 'content' => ' -
- - - - - -
- - - -
- ', - ) -); - -register_block_pattern( - 'query/medium-posts', - array( - 'title' => __( 'Image at left', 'gutenberg' ), - 'blockTypes' => array( 'core/query' ), - 'categories' => array( 'query' ), - 'content' => ' -
- - -
-
- - -
-
-
- - -
- ', - ) -); - -register_block_pattern( - 'query/small-posts', - array( - 'title' => __( 'Small image and title', 'gutenberg' ), - 'blockTypes' => array( 'core/query' ), - 'categories' => array( 'query' ), - 'content' => ' -
- - -
-
- - -
-
- - -
- ', - ) -); - -register_block_pattern( - 'query/grid-posts', - array( - 'title' => __( 'Grid', 'gutenberg' ), - 'blockTypes' => array( 'core/query' ), - 'categories' => array( 'query' ), - 'content' => ' -
- - -
- -
- - - - ', - ) -); +/** + * Register Gutenberg bundled patterns. + */ +function register_gutenberg_patterns() { + // Register categories used for block patterns. + register_block_pattern_category( 'query', array( 'label' => __( 'Query', 'gutenberg' ) ) ); + + // Initial Query block patterns. + register_block_pattern( + 'query/standard-posts', + array( + 'title' => __( 'Standard', 'gutenberg' ), + 'blockTypes' => array( 'core/query' ), + 'categories' => array( 'query' ), + 'content' => ' +
+ + + + + +
+ + + +
+ ', + ) + ); + + register_block_pattern( + 'query/medium-posts', + array( + 'title' => __( 'Image at left', 'gutenberg' ), + 'blockTypes' => array( 'core/query' ), + 'categories' => array( 'query' ), + 'content' => ' +
+ + +
+
+ + +
+
+
+ + +
+ ', + ) + ); + + register_block_pattern( + 'query/small-posts', + array( + 'title' => __( 'Small image and title', 'gutenberg' ), + 'blockTypes' => array( 'core/query' ), + 'categories' => array( 'query' ), + 'content' => ' +
+ + +
+
+ + +
+
+ + +
+ ', + ) + ); + + register_block_pattern( + 'query/grid-posts', + array( + 'title' => __( 'Grid', 'gutenberg' ), + 'blockTypes' => array( 'core/query' ), + 'categories' => array( 'query' ), + 'content' => ' +
+ + +
+ +
+ + + + ', + ) + ); + + register_block_pattern( + 'query/large-title-posts', + array( + 'title' => __( 'Large title', 'gutenberg' ), + 'blockTypes' => array( 'core/query' ), + 'categories' => array( 'query' ), + 'content' => ' +
+
+ +
+ + + +
+
+ + + +
+
+ +
+
+ ', + ) + ); + + register_block_pattern( + 'query/offset-posts', + array( + 'title' => __( 'Offset', 'gutenberg' ), + 'blockTypes' => array( 'core/query' ), + 'categories' => array( 'query' ), + 'content' => ' +
+
+
+
+ + + + + + +
+
+ + +
+
+ + + + + + +
+
+
+
+ ', + ) + ); + + // Initial block pattern to be used with block transformations with patterns. + register_block_pattern( + 'social-links/shared-background-color', + array( + 'title' => __( 'Social links with a shared background color', 'gutenberg' ), + 'categories' => array( 'buttons' ), + 'blockTypes' => array( 'core/social-links' ), + 'viewportWidth' => 500, + 'content' => ' + + ', + ) + ); +} -register_block_pattern( - 'query/large-title-posts', - array( - 'title' => __( 'Large title', 'gutenberg' ), - 'blockTypes' => array( 'core/query' ), - 'categories' => array( 'query' ), - 'content' => ' -
-
- -
- - - -
-
- - - -
-
- -
-
- ', - ) -); +/** + * Deactivate the legacy patterns bundled with WordPress, and add new block patterns for testing. + * More details in the trac issue (https://core.trac.wordpress.org/ticket/52846). + */ +function update_core_patterns() { + $core_block_patterns = array( + 'text-two-columns', + 'two-buttons', + 'two-images', + 'text-two-columns-with-images', + 'text-three-columns-buttons', + 'large-header', + 'large-header-button', + 'three-buttons', + 'heading-paragraph', + 'quote', + ); + + $new_core_block_patterns = array( + 'media-text-nature', + 'two-images-gallery', + 'three-columns-media-text', + 'quote', + 'large-header-left', + 'large-header-text-button', + 'media-text-art', + 'text-two-columns-title', + 'three-columns-text', + 'text-two-columns-title-offset', + 'heading', + 'three-images-gallery', + 'text-two-columns', + 'media-text-arquitecture', + 'two-buttons', + ); + + foreach ( $core_block_patterns as $core_block_pattern ) { + $name = 'core/' . $core_block_pattern; + if ( WP_Block_Patterns_Registry::get_instance()->is_registered( $name ) ) { + unregister_block_pattern( $name ); + } + } -register_block_pattern( - 'query/offset-posts', - array( - 'title' => __( 'Offset', 'gutenberg' ), - 'blockTypes' => array( 'core/query' ), - 'categories' => array( 'query' ), - 'content' => ' -
-
-
-
- - - - - - -
-
- - -
-
- - - - - - -
-
-
-
- ', - ) -); + foreach ( $new_core_block_patterns as $core_block_pattern ) { + register_block_pattern( + 'core/' . $core_block_pattern, + require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php' + ); + } +} -// Initial block pattern to be used with block transformations with patterns. -register_block_pattern( - 'social-links/shared-background-color', - array( - 'title' => __( 'Social links with a shared background color', 'gutenberg' ), - 'categories' => array( 'buttons' ), - 'blockTypes' => array( 'core/social-links' ), - 'viewportWidth' => 500, - 'content' => ' - - ', - ) -); -// Deactivate the legacy patterns bundled with WordPress, and add new block patterns for testing. -// More details in the trac issue (https://core.trac.wordpress.org/ticket/52846). add_action( 'init', function() { - - $core_block_patterns = array( - 'text-two-columns', - 'two-buttons', - 'two-images', - 'text-two-columns-with-images', - 'text-three-columns-buttons', - 'large-header', - 'large-header-button', - 'three-buttons', - 'heading-paragraph', - 'quote', - ); - - $new_core_block_patterns = array( - 'media-text-nature', - 'two-images-gallery', - 'three-columns-media-text', - 'quote', - 'large-header-left', - 'large-header-text-button', - 'media-text-art', - 'text-two-columns-title', - 'three-columns-text', - 'text-two-columns-title-offset', - 'heading', - 'three-images-gallery', - 'text-two-columns', - 'media-text-arquitecture', - 'two-buttons', - ); - - if ( ! function_exists( 'unregister_block_pattern' ) ) { + if ( ! get_theme_support( 'core-block-patterns' ) || ! function_exists( 'unregister_block_pattern' ) ) { return; } - - foreach ( $core_block_patterns as $core_block_pattern ) { - $name = 'core/' . $core_block_pattern; - if ( WP_Block_Patterns_Registry::get_instance()->is_registered( $name ) ) { - unregister_block_pattern( $name ); - } - } - - foreach ( $new_core_block_patterns as $core_block_pattern ) { - register_block_pattern( - 'core/' . $core_block_pattern, - require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php' - ); - } - + register_gutenberg_patterns(); + update_core_patterns(); } );