From 6cf879ad0fc09c4775afd032d6f5cbc20a099a0e Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 20 May 2021 20:51:34 +1000 Subject: [PATCH] Updated filters after #28800, which introduced a remote call to patterns directory to fetch and then register patterns. This commit provides filters to opt out of: 1. removing core patterns, in case Gutenberg users want to use Core patterns 2. adding Gutenberg patterns 3. loading core patterns from remote source --- lib/block-patterns.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/block-patterns.php b/lib/block-patterns.php index ccc6f8bbf7b68e..04dc127da1ddf3 100644 --- a/lib/block-patterns.php +++ b/lib/block-patterns.php @@ -239,8 +239,16 @@ function() { if ( ! get_theme_support( 'core-block-patterns' ) || ! function_exists( 'unregister_block_pattern' ) ) { return; } - remove_core_patterns(); - register_gutenberg_patterns(); + + // Provides a way to opt-out of removing core patterns. + if ( apply_filters( 'remove_core_patterns', true ) ) { + remove_core_patterns(); + } + + // Provides a way to opt-out of pattern registration. + if ( apply_filters( 'register_gutenberg_patterns', true ) ) { + register_gutenberg_patterns(); + } } ); @@ -251,6 +259,11 @@ function( $current_screen ) { return; } + // Provides a way to opt-out of remotely loading core patterns. + if ( ! apply_filters( 'load_remote_patterns', true ) ) { + 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 ) { load_remote_patterns();