From 26f3d59c2b1fb6dade2f5b53af721b71e8eda4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 7 Apr 2022 17:21:53 +0200 Subject: [PATCH] fix only filter `plugins_url` on pre WordPress 6.0 versions This is because 6.0 changed some things in how this worked which meant the filter broke existin blocks. Because of that 6.0 now allows themes nativley to register blocks from within them as per: https://core.trac.wordpress.org/changeset/53091 --- themes/10up-theme/includes/blocks.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/themes/10up-theme/includes/blocks.php b/themes/10up-theme/includes/blocks.php index a86c56eb..2fd41595 100644 --- a/themes/10up-theme/includes/blocks.php +++ b/themes/10up-theme/includes/blocks.php @@ -47,8 +47,14 @@ function setup() { * @return void */ function register_theme_blocks() { - // Filter the plugins URL to allow us to have blocks in themes with linked assets. i.e editorScripts - add_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 ); + global $wp_version; + + $is_pre_wp_6 = version_compare( $wp_version, '6.0', '<' ); + + if ( $is_pre_wp_6 ) { + // Filter the plugins URL to allow us to have blocks in themes with linked assets. i.e editorScripts + add_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 ); + } // Register all the blocks in the theme if ( file_exists( TENUP_THEME_BLOCK_DIR ) ) { @@ -82,8 +88,10 @@ function register_theme_blocks() { }; }; - // Remove the filter after we register the blocks - remove_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 ); + if ( $is_pre_wp_6 ) { + // Remove the filter after we register the blocks + remove_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 ); + } } /**