Skip to content

Commit

Permalink
[Patterns]: Load theme patterns only in block and site editor (#39493)
Browse files Browse the repository at this point in the history
* [Patterns]: Load theme patterns only in block and site editor

* split checks
  • Loading branch information
ntsekouras committed Mar 16, 2022
1 parent 00a7f89 commit 7e3ecdc
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/compat/wordpress-6.0/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,4 +32,22 @@ function gutenberg_register_remote_theme_patterns() {
}
}

add_action( 'init', 'gutenberg_register_remote_theme_patterns' );
add_action(
'current_screen',
function( $current_screen ) {
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;
}

$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();
}
}
);

0 comments on commit 7e3ecdc

Please sign in to comment.