|
8 | 8 | use VektorInc\VK_Component\VK_Component_Posts;
|
9 | 9 |
|
10 | 10 | /**
|
11 |
| - * Boostrapの読み込み |
| 11 | + * VK Components(Bootstrap) を読み込むべきか判定 |
12 | 12 | *
|
13 |
| - * @param string $hook_suffix hook suffix. |
| 13 | + * @return bool 読み込む場合 true、読み込まない場合 false |
14 | 14 | */
|
15 |
| -function vk_blocks_load_vk_components( $hook_suffix ) { |
| 15 | +function vk_blocks_should_load_vk_components() { |
16 | 16 | $template = wp_get_theme()->Template;
|
17 |
| - // lightning 系(ベクトル)の場合 vk-components はテーマなどで読み込むので必要ない |
18 |
| - if ( 'lightning' === $template || 'lightning-pro' === $template || 'katawara' === $template ) { |
19 |
| - return; |
20 |
| - } |
| 17 | + // lightning 系(ベクトル)の場合 vk-components はテーマなどで読み込むので適用しない |
| 18 | + $should_load = ! in_array( $template, array( 'lightning', 'lightning-pro', 'katawara' ), true ); |
| 19 | + |
| 20 | + return apply_filters( 'vk_blocks_should_load_vk_components', $should_load ); |
| 21 | +} |
| 22 | + |
| 23 | +// 条件に合わなければここで return することで、以降の処理を実行しない |
| 24 | +if ( ! vk_blocks_should_load_vk_components() ) { |
| 25 | + return; |
| 26 | +} |
21 | 27 |
|
| 28 | +/** |
| 29 | + * VK Components(Bootstrap) の登録 & 読み込み |
| 30 | + */ |
| 31 | +function vk_blocks_register_vk_components_style() { |
22 | 32 | VK_Component_Posts::register_style( 'vk-components-style' );
|
| 33 | +} |
| 34 | +add_action( 'init', 'vk_blocks_register_vk_components_style' ); |
23 | 35 |
|
24 |
| - // 管理画面 |
| 36 | +/** |
| 37 | + * VK Components(Bootstrap) を管理画面とフロントに適用 |
| 38 | + * |
| 39 | + * @param string $hook_suffix hook suffix. |
| 40 | + */ |
| 41 | +function vk_blocks_enqueue_vk_components_style( $hook_suffix = '' ) { |
25 | 42 | if ( is_admin() ) {
|
26 |
| - if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) { |
| 43 | + if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) { |
27 | 44 | wp_enqueue_style( 'vk-components-style' );
|
28 | 45 | }
|
29 | 46 | } else {
|
30 | 47 | wp_enqueue_style( 'vk-components-style' );
|
31 | 48 | }
|
32 | 49 | }
|
33 |
| -add_action( 'admin_enqueue_scripts', 'vk_blocks_load_vk_components' ); |
34 |
| -add_action( 'wp_enqueue_scripts', 'vk_blocks_load_vk_components' ); |
| 50 | +add_action( 'admin_enqueue_scripts', 'vk_blocks_enqueue_vk_components_style' ); |
| 51 | +add_action( 'wp_enqueue_scripts', 'vk_blocks_enqueue_vk_components_style' ); |
| 52 | + |
| 53 | +/** |
| 54 | + * エディター用の VK Components(Bootstrap) を適用 |
| 55 | + */ |
| 56 | +function vk_blocks_enqueue_vk_components_editor_style() { |
| 57 | + // スタイルが登録されていない場合は登録 |
| 58 | + if ( ! wp_style_is( 'vk-components-style', 'registered' ) ) { |
| 59 | + VK_Component_Posts::register_style( 'vk-components-style' ); |
| 60 | + } |
| 61 | + |
| 62 | + // スタイルを適用 |
| 63 | + wp_enqueue_style( 'vk-components-style' ); |
| 64 | +} |
| 65 | +add_action( 'enqueue_block_assets', 'vk_blocks_enqueue_vk_components_editor_style' ); |
0 commit comments