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 79e849f commit a1512f6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/blocks/_pro/post-list-slider/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,21 @@ function vk_blocks_post_list_slider_set_data() {
add_action( 'enqueue_block_editor_assets', 'vk_blocks_post_list_slider_set_data' );

/**
* Register editor styles for the Post List Slider block.
* Enqueue vk-components.css only once in the editor iframe.
*
* This function ensures that vk-components.css is properly loaded within the block editor's iframe.
* This function ensures that vk-components.css is only enqueued once,
* even if multiple blocks request it.
*
* @package vk-blocks
*/
function vk_blocks_register_block_post_list_slider_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 @@ -300,7 +308,7 @@ function vk_blocks_register_block_post_list_slider_editor_styles() {
$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 Down

0 comments on commit a1512f6

Please sign in to comment.