From bb68e0d1c2ae1d8b90fb8dc8e0b05663131c2792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ka=CC=88gy?= Date: Thu, 24 Aug 2023 15:14:50 +0200 Subject: [PATCH] fix only enqueue editor assets in editor --- example/plugin.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/example/plugin.php b/example/plugin.php index 9d983165..1131c7fa 100644 --- a/example/plugin.php +++ b/example/plugin.php @@ -29,6 +29,17 @@ */ function register_block() { + if ( file_exists( EXAMPLE_PLUGIN_BLOCK_DIST_DIR ) ) { + $block_json_files = glob( EXAMPLE_PLUGIN_BLOCK_DIST_DIR . '*/block.json' ); + foreach ( $block_json_files as $filename ) { + $block_folder = dirname( $filename ); + register_block_type( $block_folder ); + }; + }; +}; + +add_action( 'enqueue_block_assets', __NAMESPACE__ . '\enqueue_block_editor_scripts' ); +function enqueue_block_editor_scripts() { $asset_file = include EXAMPLE_PLUGIN_DIST_PATH . 'index.asset.php'; wp_enqueue_script( @@ -38,15 +49,7 @@ function register_block() { $asset_file['version'], true ); - - if ( file_exists( EXAMPLE_PLUGIN_BLOCK_DIST_DIR ) ) { - $block_json_files = glob( EXAMPLE_PLUGIN_BLOCK_DIST_DIR . '*/block.json' ); - foreach ( $block_json_files as $filename ) { - $block_folder = dirname( $filename ); - register_block_type( $block_folder ); - }; - }; -}; +} function register_book_custom_post_type() { $labels = array(