From b723c92cabef56b452cb4e7258ba9bf89fc53389 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 16 Mar 2022 12:34:01 +0200 Subject: [PATCH 1/2] [Patterns]: Load theme patterns only in block and site editor --- lib/compat/wordpress-6.0/block-patterns.php | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/compat/wordpress-6.0/block-patterns.php b/lib/compat/wordpress-6.0/block-patterns.php index 1558240efeb2ab..f244e7514653ed 100644 --- a/lib/compat/wordpress-6.0/block-patterns.php +++ b/lib/compat/wordpress-6.0/block-patterns.php @@ -10,12 +10,6 @@ * `theme.json` file. */ function gutenberg_register_remote_theme_patterns() { - $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true ); - $theme_has_support = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); - if ( ! get_theme_support( 'core-block-patterns' ) || ! $should_load_remote || ! $theme_has_support ) { - return; - } - $pattern_settings = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data()->get_patterns(); if ( empty( $pattern_settings ) ) { return; @@ -38,4 +32,18 @@ function gutenberg_register_remote_theme_patterns() { } } -add_action( 'init', 'gutenberg_register_remote_theme_patterns' ); +add_action( + 'current_screen', + function( $current_screen ) { + $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true ); + $theme_has_support = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); + if ( ! get_theme_support( 'core-block-patterns' ) || ! $should_load_remote || ! $theme_has_support ) { + return; + } + + $is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) ); + if ( $current_screen->is_block_editor || $is_site_editor ) { + gutenberg_register_remote_theme_patterns(); + } + } +); From ac9298f1c158e148c38d1941a6106384db74c0d7 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 16 Mar 2022 14:34:39 +0200 Subject: [PATCH 2/2] split checks --- lib/compat/wordpress-6.0/block-patterns.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.0/block-patterns.php b/lib/compat/wordpress-6.0/block-patterns.php index f244e7514653ed..d5b131c88f5300 100644 --- a/lib/compat/wordpress-6.0/block-patterns.php +++ b/lib/compat/wordpress-6.0/block-patterns.php @@ -35,9 +35,13 @@ function gutenberg_register_remote_theme_patterns() { add_action( 'current_screen', function( $current_screen ) { - $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true ); - $theme_has_support = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support(); - if ( ! get_theme_support( 'core-block-patterns' ) || ! $should_load_remote || ! $theme_has_support ) { + if ( ! get_theme_support( 'core-block-patterns' ) ) { + return; + } + if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) { + return; + } + if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { return; }