|
8 | 8 | use VektorInc\VK_Component\VK_Component_Posts;
|
9 | 9 |
|
10 | 10 | /**
|
11 |
| - * VK Components(Bootstrap) を読み込むべきか判定 |
| 11 | + * Boostrapの読み込み |
12 | 12 | *
|
13 |
| - * @return bool 読み込む場合 true、読み込まない場合 false |
| 13 | + * @param string $hook_suffix hook suffix. |
14 | 14 | */
|
15 |
| -function vk_blocks_should_load_vk_components() { |
| 15 | +function vk_blocks_load_vk_components( $hook_suffix ) { |
16 | 16 | $template = wp_get_theme()->Template;
|
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 |
| -} |
| 17 | + // lightning 系(ベクトル)の場合 vk-components はテーマなどで読み込むので必要ない |
| 18 | + if ( 'lightning' === $template || 'lightning-pro' === $template || 'katawara' === $template ) { |
| 19 | + return; |
| 20 | + } |
27 | 21 |
|
28 |
| -/** |
29 |
| - * VK Components(Bootstrap) の登録 & 読み込み |
30 |
| - */ |
31 |
| -function vk_blocks_register_vk_components_style() { |
32 | 22 | VK_Component_Posts::register_style( 'vk-components-style' );
|
33 |
| -} |
34 |
| -add_action( 'init', 'vk_blocks_register_vk_components_style' ); |
35 | 23 |
|
36 |
| -/** |
37 |
| - * VK Components(Bootstrap) を管理画面とフロントに適用 |
38 |
| - * |
39 |
| - * @param string $hook_suffix hook suffix. |
40 |
| - */ |
41 |
| -function vk_blocks_enqueue_vk_components_style( $hook_suffix = '' ) { |
| 24 | + // 管理画面 |
42 | 25 | if ( is_admin() ) {
|
43 |
| - if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) { |
| 26 | + if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) { |
44 | 27 | wp_enqueue_style( 'vk-components-style' );
|
45 | 28 | }
|
46 | 29 | } else {
|
47 | 30 | wp_enqueue_style( 'vk-components-style' );
|
48 | 31 | }
|
49 | 32 | }
|
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' ); |
| 33 | +add_action( 'admin_enqueue_scripts', 'vk_blocks_load_vk_components' ); |
| 34 | +add_action( 'wp_enqueue_scripts', 'vk_blocks_load_vk_components' ); |
0 commit comments