-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitialize.php
173 lines (152 loc) · 5.08 KB
/
initialize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Initialize VK All in One Expansion Unit
*
* @package VK All in One Expansion Unit
*/
/*
Delete old function data
Load modules
Add vkExUnit css
Add vkExUnit js
*/
/*
Delete old function data
*/
$options = get_option( 'veu_deprecated' );
if ( empty( $options['9.72.0'] ) ) {
require VEU_DIRECTORY_PATH . '/delete-old-option-meta.php';
$options['9.72.0'] = 'done';
update_option( 'veu_deprecated', $options );
}
/*
Load modules
*/
// ./admin/admin.php は veu_load_packages() の中に入れると
// * ExUnit のカスタマイズパネルが出なくなる
// * ExUnit_Custom_Html の読み込みでエラーになる
require_once VEU_DIRECTORY_PATH . '/admin/admin.php';
/**
* Load package manager & packages
*
* @return void
*/
function veu_load_packages() {
// after_setup_theme を経由して veu-package-manager.php を読み込まないと.
// 6.7 で _load_textdomain_just_in_time のエラーが出る.
require_once VEU_DIRECTORY_PATH . '/veu-package-manager.php';
// template-tags-veuでpackageの関数を使うので package-managerを先に読み込んでいる.
require_once VEU_DIRECTORY_PATH . '/inc/template-tags/template-tags-config.php';
require_once VEU_DIRECTORY_PATH . '/inc/common-block.php';
require VEU_DIRECTORY_PATH . '/inc/footer-copyright-change.php';
veu_package_include(); // package_manager.php.
}
add_action( 'after_setup_theme', 'veu_load_packages' );
/**
* Add vkExUnit css
*/
function veu_load_css_action() {
$hook_point = apply_filters( 'veu_enqueue_point_common_css', 'wp_enqueue_scripts' );
// priority 5 : possible to overwrite from theme design skin.
add_action( $hook_point, 'veu_print_css', 5 );
}
add_action( 'after_setup_theme', 'veu_load_css_action' );
/**
* Regisyter vkExUnit css
*/
function vwu_register_css() {
$options = veu_get_common_options();
wp_register_style( 'vkExUnit_common_style', plugins_url( '', __FILE__ ) . '/assets/css/vkExUnit_style.css', array(), VEU_VERSION, 'all' );
}
add_action( 'wp_enqueue_scripts', 'vwu_register_css', 3 );
add_action( 'admin_enqueue_scripts', 'vwu_register_css', 3 );
/**
* Print vkExUnit css
*/
function veu_print_css() {
wp_enqueue_style( 'vkExUnit_common_style' );
}
/**
* Print vkExUnit editor css
*/
function veu_print_editor_css() {
add_editor_style( plugins_url( '', __FILE__ ) . '/assets/css/vkExUnit_editor_style.css' );
}
add_action( 'after_setup_theme', 'veu_print_editor_css' );
/**
* ブロックエディタ用のCSS読み込み( ↑ だけだと効かない )
*/
function veu_print_block_editor_css() {
wp_register_style(
'veu-block-editor',
plugins_url( '', __FILE__ ) . '/assets/css/vkExUnit_editor_style.css',
array(),
filemtime( plugin_dir_path( __FILE__ ) )
);
}
add_action( 'init', 'veu_print_block_editor_css' );
/**
* Print Js
*/
function veu_print_js() {
$options = apply_filters( 'vkExUnit_master_js_options', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
wp_register_script( 'vkExUnit_master-js', plugins_url( '', __FILE__ ) . '/assets/js/all.min.js', array(), VEU_VERSION, true );
wp_localize_script( 'vkExUnit_master-js', 'vkExOpt', apply_filters( 'vkExUnit_localize_options', $options ) );
wp_enqueue_script( 'vkExUnit_master-js' );
}
add_action( 'wp_enqueue_scripts', 'veu_print_js' );
/**
* Change old options
*/
function change_old_options() {
$option = get_option( 'vkExUnit_pagespeeding' );
if ( isset( $option['common'] ) ) {
$option['css_exunit'] = true;
unset( $option['common'] );
}
if ( isset( $option['css_exunit'] ) ) {
$option['css_optimize'] = 'tree-shaking';
unset( $option['css_exunit'] );
}
if ( isset( $option['js_footer'] ) ) {
unset( $option['js_footer'] );
}
update_option( 'vkExUnit_pagespeeding', $option );
}
add_action( 'after_setup_theme', 'change_old_options', 4 );
/**
* Change enqueue point to footer
*
* @param string $enqueue_point enqueue point.
* @return string
*/
function veu_change_enqueue_point_to_footer( $enqueue_point ) {
$enqueue_point = 'wp_footer';
return $enqueue_point;
}
/**
* Inline styles
*/
function veu_inline_styles() {
$dynamic_css = ':root {
--ver_page_top_button_url:url(' . VEU_DIRECTORY_URI . '/assets/images/to-top-btn-icon.svg);
}
@font-face {
font-weight: normal;
font-style: normal;
font-family: "vk_sns";
src: url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.eot?-bq20cj");
src: url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.eot?#iefix-bq20cj") format("embedded-opentype"),
url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.woff?-bq20cj") format("woff"),
url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.ttf?-bq20cj") format("truetype"),
url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.svg?-bq20cj#vk_sns") format("svg");
}';
// delete before after space.
$dynamic_css = trim( $dynamic_css );
// convert tab and br to space.
$dynamic_css = preg_replace( '/[\n\r\t]/', '', $dynamic_css );
// Change multiple spaces to single space.
$dynamic_css = preg_replace( '/\s(?=\s)/', '', $dynamic_css );
wp_add_inline_style( 'vkExUnit_common_style', $dynamic_css );
}
add_action( 'wp_head', 'veu_inline_styles', 5 );