Skip to content

Commit

Permalink
Fix: Enqueue editor styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdkei authored and mtdkei committed Feb 6, 2025
1 parent 2b8de99 commit ab44e46
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/blocks/_pro/post-list/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,23 @@ function vk_blocks_post_list_set_data() {
}
add_action( 'enqueue_block_editor_assets', 'vk_blocks_post_list_set_data' );


/**
* Enqueue editor styles
* Enqueue vk-components.css only once in the editor iframe.
*
* This function ensures that vk-components.css is only enqueued once,
* even if multiple blocks request it.
*
* @package vk-blocks
*/
function vk_blocks_enqueue_editor_iframe_post_list() {
function vk_blocks_register_block_post_list_editor_styles() {
static $loaded = false; // 既に実行済みならスキップ

if ( $loaded ) {
return;
}
$loaded = true;

// `vk-blocks-pro` のルートディレクトリを取得
$plugin_root_path = WP_PLUGIN_DIR . '/vk-blocks-pro';
$plugin_root_url = WP_PLUGIN_URL . '/vk-blocks-pro';
Expand All @@ -267,7 +280,7 @@ function vk_blocks_enqueue_editor_iframe_post_list() {
$css_path = $plugin_root_path . '/vendor/vektor-inc/vk-component/src/assets/css/vk-components.css';
$css_url = $plugin_root_url . '/vendor/vektor-inc/vk-component/src/assets/css/vk-components.css';

// すでに `#vk-components-editor-style` が `enqueue` されているかチェック
// `vk-components-editor-style` がすでに登録済みならスキップ
if ( is_admin() && ! wp_style_is( 'vk-components-editor-style', 'enqueued' ) && file_exists( $css_path ) ) {
wp_enqueue_style(
'vk-components-editor-style',
Expand All @@ -277,4 +290,4 @@ function vk_blocks_enqueue_editor_iframe_post_list() {
);
}
}
add_action( 'enqueue_block_assets', 'vk_blocks_enqueue_editor_iframe_post_list' );
add_action( 'enqueue_block_editor_assets', 'vk_blocks_register_block_post_list_editor_styles' );

0 comments on commit ab44e46

Please sign in to comment.