VK All in One Expansion Unit - Version 9.42.0.0

Version Description

[ Specification Change ][ CSS Optimize ] Change to common setting

Download this release

Release Info

Developer kurudrive
Plugin Icon 128x128 VK All in One Expansion Unit
Version 9.42.0.0
Comparing to
See all releases

Code changes from version 9.41.0.0 to 9.42.0.0

admin/customizer.php CHANGED
@@ -111,33 +111,6 @@ function veu_customize_register_pagespeed( $wp_customize ) {
111
  )
112
  );
113
 
114
- // CSS Footer Setting.
115
- $wp_customize->add_setting(
116
- 'vkExUnit_pagespeeding[css_optimize]',
117
- array(
118
- 'default' => 'tree-shaking',
119
- 'type' => 'option',
120
- 'capability' => 'edit_theme_options',
121
- 'sanitize_callback' => 'veu_sanitize_radio',
122
- )
123
- );
124
- $wp_customize->add_control(
125
- 'vkExUnit_pagespeeding[css_optimize]',
126
- array(
127
- 'label' => __( 'Optimize CSS', 'vk-all-in-one-expansion-unit' ),
128
- 'section' => 'veu_speeding_setting',
129
- 'settings' => 'vkExUnit_pagespeeding[css_optimize]',
130
- 'description' => __( 'If you enable this setting that css file will be minified.', 'vk-all-in-one-expansion-unit' ),
131
- 'type' => 'select',
132
- 'choices' => array(
133
- 'default' => __( 'Nothing to do', 'vk-all-in-one-expansion-unit' ),
134
- 'tree-shaking' => __( 'Optimize ExUnit CSS ( Tree Shaking ) ( Beta )', 'vk-all-in-one-expansion-unit' ),
135
- //'optomize-all-css' => __( 'Optimize ExUnit CSS ( Tree Shaking + Preload ) ( Beta )', 'vk-all-in-one-expansion-unit' ),
136
- ),
137
- )
138
- );
139
-
140
-
141
  // JS Footer Setting.
142
  $wp_customize->add_setting(
143
  'vkExUnit_pagespeeding[js_footer]',
111
  )
112
  );
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  // JS Footer Setting.
115
  $wp_customize->add_setting(
116
  'vkExUnit_pagespeeding[js_footer]',
gulpfile.js CHANGED
@@ -67,10 +67,19 @@ gulp.task('block', function (done) {
67
  .pipe(gulp.dest('./assets/js/'));
68
  });
69
 
70
- gulp.task('text-domain', function () {
71
- return gulp.src(['./inc/font-awesome/**/*'])
72
- .pipe(replace('vk_font_awesome_version_textdomain', 'vk-all-in-one-expansion-unit' ))
73
- .pipe(gulp.dest('./inc/font-awesome/'));
 
 
 
 
 
 
 
 
 
74
  });
75
 
76
  gulp.task('sass', function() {
67
  .pipe(gulp.dest('./assets/js/'));
68
  });
69
 
70
+ gulp.task("text-domain", function(done) {
71
+ // font-awesome.
72
+ gulp.src(["./inc/font-awesome/package/*.php"])
73
+ .pipe(replace("'vk_font_awesome_version_textdomain'", "'vk-all-in-one-expansion-unit'"))
74
+ .pipe(gulp.dest("./inc/font-awesome/package/"));
75
+ // term-color.
76
+ gulp.src(["./inc/term-color/package/*.php"])
77
+ .pipe(replace("'vk_term_color_textdomain'","'vk-all-in-one-expansion-unit'"))
78
+ .pipe(gulp.dest("./inc/term-color/package/"));
79
+ gulp.src(["./inc/vk-css-optimize/package/*.php"])
80
+ .pipe(replace("'css_optimize_textdomain'","'vk-all-in-one-expansion-unit'"))
81
+ .pipe(gulp.dest("./inc/vk-css-optimize/package/"));
82
+ done();
83
  });
84
 
85
  gulp.task('sass', function() {
inc/vk-css-optimize/package/class-css-tree-shaking.php CHANGED
@@ -1,228 +1,230 @@
1
- <?php
2
- /**
3
- * CSS Simple Tree Shaking
4
- *
5
- * Description: CSS 定義データから未使用の id, class, tag に関する定義を取り除き縮小化します
6
- *
7
- * Version: 1.0.2
8
- * Author: enomoto@celtislab
9
- * Author URI: https://celtislab.net/
10
- * License: GPLv2
11
- *
12
- */
13
- namespace celtislab;
14
-
15
- defined( 'ABSPATH' ) || exit;
16
-
17
- class CSS_tree_shaking {
18
-
19
- private static $cmplist;
20
- private static $varlist;
21
- private static $jsaddlist;
22
- private static $atrule_data;
23
- function __construct() {}
24
-
25
- // アットルール一時退避( @{md5key} に置き換えておく)
26
- private static function atrule_store($css){
27
- $pattern = array( '|(@(\-[\w]+\-)?keyframes.+?\{)(.+?\})\}|',
28
- '|(@(\-[\w]+\-)?supports.+?\{)(.+?\})\}|',
29
- '|(@(\-[\w]+\-)?media.+?\{)(.+?\})\}|',
30
- '|@[^;\{]+?;|',
31
- '|@[^;\{]+?\{(.+?)\}|'
32
- );
33
- foreach ( $pattern as $atrule ) {
34
- $css = preg_replace_callback( $atrule, function($matches) {
35
- $key = 'AR_' . md5($matches[0]);
36
- $data = $matches[0];
37
- if(!empty($matches[3])){
38
- $incss = self::atrule_store( $matches[3] );
39
- $incss = self::tree_shaking( $incss );
40
- $data = (!empty($incss))? $matches[1] . $incss . '}' : '';
41
- }
42
- self::$atrule_data[ $key ] = $data;
43
- return '@{' . $key . '}';
44
- }, $css);
45
- }
46
- return $css;
47
- }
48
-
49
- //アットルール復元
50
- private static function atrule_restore($css){
51
- $css = preg_replace_callback('|@\{(.+?)\}|', function($matches) {
52
- $data = $matches[0];
53
- $key = $matches[1];
54
- if(strpos($key, 'AR_') !== false){
55
- $data = (!empty(self::$atrule_data[ $key ]))? self::atrule_restore( self::$atrule_data[ $key ] ) : '';
56
- }
57
- return $data;
58
- }, $css);
59
- return $css;
60
- }
61
-
62
- //CSS から未使用の id, class, tag を含む定義を削除
63
- private static function tree_shaking($css) {
64
- $ncss = preg_replace_callback("|(.+?)(\{.+?\})|u", function($matches) {
65
- $data = $matches[0];
66
- $sel = $matches[1];
67
- if($sel !== '@'){
68
- $pattern = array( 'id' => '|(#)([\w\-\\%]+)|u',
69
- 'class' => '|(\.)([\w\-\\%]+)|u',
70
- 'tag' => '/(^|[,\s>\+~\(\)\]\|])([\w\-]+)/iu'
71
- );
72
-
73
- $slist = array_map("trim", explode(',', $sel));
74
- foreach ($slist as $s) {
75
- //selector の判定条件から :not(...) を除外 ($_s で判定して削除時は $s で行う)
76
- $_s = $s;
77
- if(preg_match('/:not\(.+?\)/', $s)){
78
- $_s = preg_replace( '/:not\(.+?\)/', '', $s );
79
- }
80
- foreach (array('id','class','tag') as $item) {
81
- if(!empty($_s) && preg_match_all( $pattern[$item], $_s, $match)){
82
- foreach ($match[2] as $val) {
83
- //$jsaddlist 登録名が一部でも含まれていれば削除しない(処理を簡略化するため上位層のセレクタのみで判定)
84
- if(in_array($val, self::$jsaddlist))
85
- break;
86
-
87
- //$cmplist 登録名に含まれていないものが一つでもあれば削除
88
- if(!preg_match('/^[0-9]+/', $val) && !in_array($val, self::$cmplist[$item])){
89
- $sel = preg_replace( '/(' . preg_quote($s) . ')(,|$)/u', '$2', $sel, 1 );
90
- $s = '';
91
- break;
92
- }
93
- }
94
- }
95
- }
96
- }
97
- $sel = preg_replace('/,+/su', ',', $sel);
98
- $sel = preg_replace('/\s+/su', ' ', $sel);
99
- $sel = trim($sel);
100
- $sel = trim($sel, ',');
101
- $data = (!empty($sel))? $sel . $matches[2] : '';
102
- }
103
- return $data;
104
- }, $css);
105
- return $ncss;
106
- }
107
-
108
- //未使用変数定義の削除(tree_shaking 実行後に実施する必要あり)
109
- public static function tree_shaking4var($css) {
110
- $ncss = $css;
111
- self::$varlist = array();
112
- if(preg_match_all( '/var\((\-\-.+?)\)/iu', $css, $vmatchs)){
113
- foreach ($vmatchs[1] as $v) {
114
- $v = trim($v);
115
- if(!in_array($v, self::$varlist)){
116
- self::$varlist[] = $v;
117
- }
118
- }
119
- }
120
- //url() 定義時は文字列中に ; がそのまま含まれている場合があるの分けて処理
121
- $ncss = preg_replace_callback( '|(\-\-[\w\-]+?):url\(.+?\);?|u', function($matches) {
122
- $data = $matches[0];
123
- if(!in_array(trim($matches[1]), self::$varlist)){
124
- $data = '';
125
- }
126
- return $data;
127
- }, $ncss);
128
- $ncss = preg_replace_callback( '|(\-\-[\w\-]+?):(.+?)([;\}])|u', function($matches) {
129
- $data = $matches[0];
130
- if(!preg_match('|url\(|u', $matches[2]) && !in_array(trim($matches[1]), self::$varlist)){
131
- $data = ($matches[3] === '}')? '}' : '';
132
- }
133
- return $data;
134
- }, $ncss);
135
-
136
- return $ncss;
137
- }
138
-
139
- /*=============================================================
140
- * CSS 内のコメント、改行、空白等を削除するだけのシンプルな縮小化
141
- */
142
- public static function simple_minify( $css ) {
143
- $res = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css );
144
- if(!empty($res)){
145
- $css = $res;
146
- $css = str_replace(array("\r", "\n"), '', $css);
147
- $css = str_replace("\t", ' ', $css);
148
- $css = preg_replace('/\s+/su', ' ', $css);
149
- $css = preg_replace('/\s([\{\}:=,\)*\/;>])/', '$1', $css);
150
- $css = preg_replace('/([\{\}:=,\(*\/!;>])\s/', '$1', $css);
151
- }
152
- return $css;
153
- }
154
-
155
- /*=============================================================
156
- * CSS 内の未使用 id, class, tag に関する定義を取り除く縮小化
157
- */
158
- public static function extended_minify($css, $html, $jsaddlist=array()) {
159
- self::$atrule_data = array();
160
- self::$jsaddlist = $jsaddlist; //JS によりDOMロード後に追加される ID や class 等が除外されなくするための名前の事前登録用
161
- $inidata = array(
162
- 'id' => array(
163
- 'page_top',
164
- ),
165
- 'class' => array(
166
- 'device-mobile',
167
- 'header_scrolled',
168
- 'active',
169
- 'menu-open',
170
- 'vk-mobile-nav-menu-btn',
171
- 'vk-mobile-nav-open',
172
- 'vk-menu-acc-active',
173
- 'acc-parent-open',
174
- 'acc-btn',
175
- 'acc-btn-open',
176
- 'acc-btn-close',
177
- 'acc-child-open',
178
- 'carousel-item-left',
179
- 'carousel-item-next',
180
- 'carousel-item-right',
181
- 'carousel-item-prev',
182
- 'form-control',
183
- 'btn',
184
- 'btn-primary',
185
- '.vk_post_imgOuter a:hover .card-img-overlay::after',
186
- ),
187
- 'tag' => array(
188
- 'a',
189
- 'html',
190
- 'head',
191
- 'body',
192
- 'title',
193
- 'style',
194
- 'meta',
195
- 'link',
196
- 'script',
197
- 'noscript'
198
- )
199
- );
200
- $inidata = apply_filters( 'css_tree_shaking_exclude', $inidata );
201
- $pattern = array( 'id' => '|[\s\t\'"]id\s?=\s?[\'"](.+?)[\'"]|u',
202
- 'class' => '|[\s\t\'"]class\s?=\s?[\'"](.+?)[\'"]|u',
203
- 'tag' => '|<([\w\-]+)|iu'
204
- );
205
-
206
- if(empty(self::$cmplist['parse'])){
207
- self::$cmplist['parse'] = true;
208
- foreach (array('id','class','tag') as $item) {
209
- self::$cmplist[$item] = $inidata[$item];
210
- if(preg_match_all( $pattern[$item], $html, $matches)){
211
- foreach ($matches[1] as $val) {
212
- $arr = array_map("trim", explode(' ', $val));
213
- foreach($arr as $dt){
214
- if(!empty($dt) && !in_array($dt, self::$cmplist[$item]))
215
- self::$cmplist[$item][] = $dt;
216
- }
217
- }
218
- }
219
- }
220
- }
221
- $css = self::simple_minify( $css );
222
- $css = self::atrule_store( $css );
223
- $css = self::tree_shaking( $css );
224
- $css = self::atrule_restore( $css );
225
- $css = self::tree_shaking4var( $css );
226
- return $css;
227
- }
228
- }
 
 
1
+ <?php
2
+ /*
3
+ The original of this file is located at:
4
+ https://github.com/vektor-inc/vektor-wp-libraries
5
+ If you want to change this file, please change the original file.
6
+ */
7
+ /**
8
+ * CSS Simple Tree Shaking
9
+ *
10
+ * Description: CSS 定義データから未使用の id, class, tag に関する定義を取り除き縮小化します
11
+ *
12
+ * Version: 1.0.2
13
+ * Author: enomoto@celtislab
14
+ * Author URI: https://celtislab.net/
15
+ * License: GPLv2
16
+ *
17
+ */
18
+ namespace celtislab;
19
+
20
+ defined( 'ABSPATH' ) || exit;
21
+
22
+ class CSS_tree_shaking {
23
+
24
+ private static $cmplist;
25
+ private static $varlist;
26
+ private static $jsaddlist;
27
+ private static $atrule_data;
28
+ function __construct() {}
29
+
30
+ // アットルール一時退避( @{md5key} に置き換えておく)
31
+ private static function atrule_store($css){
32
+ $pattern = array( '|(@(\-[\w]+\-)?keyframes.+?\{)(.+?\})\}|',
33
+ '|(@(\-[\w]+\-)?supports.+?\{)(.+?\})\}|',
34
+ '|(@(\-[\w]+\-)?media.+?\{)(.+?\})\}|',
35
+ '|@[^;\{]+?;|',
36
+ '|@[^;\{]+?\{(.+?)\}|'
37
+ );
38
+ foreach ( $pattern as $atrule ) {
39
+ $css = preg_replace_callback( $atrule, function($matches) {
40
+ $key = 'AR_' . md5($matches[0]);
41
+ $data = $matches[0];
42
+ if(!empty($matches[3])){
43
+ $incss = self::atrule_store( $matches[3] );
44
+ $incss = self::tree_shaking( $incss );
45
+ $data = (!empty($incss))? $matches[1] . $incss . '}' : '';
46
+ }
47
+ self::$atrule_data[ $key ] = $data;
48
+ return '@{' . $key . '}';
49
+ }, $css);
50
+ }
51
+ return $css;
52
+ }
53
+
54
+ //アットルール復元
55
+ private static function atrule_restore($css){
56
+ $css = preg_replace_callback('|@\{(.+?)\}|', function($matches) {
57
+ $data = $matches[0];
58
+ $key = $matches[1];
59
+ if(strpos($key, 'AR_') !== false){
60
+ $data = (!empty(self::$atrule_data[ $key ]))? self::atrule_restore( self::$atrule_data[ $key ] ) : '';
61
+ }
62
+ return $data;
63
+ }, $css);
64
+ return $css;
65
+ }
66
+
67
+ //CSS から未使用の id, class, tag を含む定義を削除
68
+ private static function tree_shaking($css) {
69
+ $ncss = preg_replace_callback("|(.+?)(\{.+?\})|u", function($matches) {
70
+ $data = $matches[0];
71
+ $sel = $matches[1];
72
+ if($sel !== '@'){
73
+ $pattern = array( 'id' => '|(#)([\w\-\\%]+)|u',
74
+ 'class' => '|(\.)([\w\-\\%]+)|u',
75
+ 'tag' => '/(^|[,\s>\+~\(\)\]\|])([\w\-]+)/iu'
76
+ );
77
+
78
+ $slist = array_map("trim", explode(',', $sel));
79
+ foreach ($slist as $s) {
80
+ //selector の判定条件から :not(...) を除外 ($_s で判定して削除時は $s で行う)
81
+ $_s = $s;
82
+ if(preg_match('/:not\(.+?\)/', $s)){
83
+ $_s = preg_replace( '/:not\(.+?\)/', '', $s );
84
+ }
85
+ foreach (array('id','class','tag') as $item) {
86
+ if(!empty($_s) && preg_match_all( $pattern[$item], $_s, $match)){
87
+ foreach ($match[2] as $val) {
88
+ //$jsaddlist 登録名が一部でも含まれていれば削除しない(処理を簡略化するため上位層のセレクタのみで判定)
89
+ if(in_array($val, self::$jsaddlist))
90
+ break;
91
+
92
+ //$cmplist 登録名に含まれていないものが一つでもあれば削除
93
+ if(!preg_match('/^[0-9]+/', $val) && !in_array($val, self::$cmplist[$item])){
94
+ $sel = preg_replace( '/(' . preg_quote($s) . ')(,|$)/u', '$2', $sel, 1 );
95
+ $s = '';
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ $sel = preg_replace('/,+/su', ',', $sel);
103
+ $sel = preg_replace('/\s+/su', ' ', $sel);
104
+ $sel = trim($sel);
105
+ $sel = trim($sel, ',');
106
+ $data = (!empty($sel))? $sel . $matches[2] : '';
107
+ }
108
+ return $data;
109
+ }, $css);
110
+ return $ncss;
111
+ }
112
+
113
+ //未使用変数定義の削除(tree_shaking 実行後に実施する必要あり)
114
+ public static function tree_shaking4var($css) {
115
+ $ncss = $css;
116
+ self::$varlist = array();
117
+ if(preg_match_all( '/var\((\-\-.+?)\)/iu', $css, $vmatchs)){
118
+ foreach ($vmatchs[1] as $v) {
119
+ $v = trim($v);
120
+ if(!in_array($v, self::$varlist)){
121
+ self::$varlist[] = $v;
122
+ }
123
+ }
124
+ }
125
+ //url() 定義時は文字列中に ; がそのまま含まれている場合があるの分けて処理
126
+ $ncss = preg_replace_callback( '|(\-\-[\w\-]+?):url\(.+?\);?|u', function($matches) {
127
+ $data = $matches[0];
128
+ if(!in_array(trim($matches[1]), self::$varlist)){
129
+ $data = '';
130
+ }
131
+ return $data;
132
+ }, $ncss);
133
+ $ncss = preg_replace_callback( '|(\-\-[\w\-]+?):(.+?)([;\}])|u', function($matches) {
134
+ $data = $matches[0];
135
+ if(!preg_match('|url\(|u', $matches[2]) && !in_array(trim($matches[1]), self::$varlist)){
136
+ $data = ($matches[3] === '}')? '}' : '';
137
+ }
138
+ return $data;
139
+ }, $ncss);
140
+
141
+ return $ncss;
142
+ }
143
+
144
+ /*=============================================================
145
+ * CSS 内のコメント、改行、空白等を削除するだけのシンプルな縮小化
146
+ */
147
+ public static function simple_minify( $css ) {
148
+ $res = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css );
149
+ if(!empty($res)){
150
+ $css = $res;
151
+ $css = str_replace(array("\r", "\n"), '', $css);
152
+ $css = str_replace("\t", ' ', $css);
153
+ $css = preg_replace('/\s+/su', ' ', $css);
154
+ $css = preg_replace('/\s([\{\}:=,\)*\/;>])/', '$1', $css);
155
+ $css = preg_replace('/([\{\}:=,\(*\/!;>])\s/', '$1', $css);
156
+ }
157
+ return $css;
158
+ }
159
+
160
+ /*=============================================================
161
+ * CSS 内の未使用 id, class, tag に関する定義を取り除く縮小化
162
+ */
163
+ public static function extended_minify($css, $html, $jsaddlist=array()) {
164
+ self::$atrule_data = array();
165
+ self::$jsaddlist = $jsaddlist; //JS によりDOMロード後に追加される ID や class 等が除外されなくするための名前の事前登録用
166
+ $inidata = array(
167
+ 'id' => array(),
168
+ 'class' => array(
169
+ 'device-mobile',
170
+ 'header_scrolled',
171
+ 'active',
172
+ 'menu-open',
173
+ 'vk-mobile-nav-menu-btn',
174
+ 'vk-mobile-nav-open',
175
+ 'vk-menu-acc-active',
176
+ 'acc-parent-open',
177
+ 'acc-btn',
178
+ 'acc-btn-open',
179
+ 'acc-btn-close',
180
+ 'acc-child-open',
181
+ 'carousel-item-left',
182
+ 'carousel-item-next',
183
+ 'carousel-item-right',
184
+ 'carousel-item-prev',
185
+ 'form-control',
186
+ 'btn',
187
+ 'btn-primary',
188
+ '.vk_post_imgOuter a:hover .card-img-overlay::after',
189
+ ),
190
+ 'tag' => array(
191
+ 'html',
192
+ 'head',
193
+ 'body',
194
+ 'title',
195
+ 'style',
196
+ 'meta',
197
+ 'link',
198
+ 'script',
199
+ 'noscript'
200
+ )
201
+ );
202
+ $inidata = apply_filters( 'css_tree_shaking_exclude', $inidata );
203
+ $pattern = array( 'id' => '|[\s\t\'"]id\s?=\s?[\'"](.+?)[\'"]|u',
204
+ 'class' => '|[\s\t\'"]class\s?=\s?[\'"](.+?)[\'"]|u',
205
+ 'tag' => '|<([\w\-]+)|iu'
206
+ );
207
+
208
+ if(empty(self::$cmplist['parse'])){
209
+ self::$cmplist['parse'] = true;
210
+ foreach (array('id','class','tag') as $item) {
211
+ self::$cmplist[$item] = $inidata[$item];
212
+ if(preg_match_all( $pattern[$item], $html, $matches)){
213
+ foreach ($matches[1] as $val) {
214
+ $arr = array_map("trim", explode(' ', $val));
215
+ foreach($arr as $dt){
216
+ if(!empty($dt) && !in_array($dt, self::$cmplist[$item]))
217
+ self::$cmplist[$item][] = $dt;
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+ $css = self::simple_minify( $css );
224
+ $css = self::atrule_store( $css );
225
+ $css = self::tree_shaking( $css );
226
+ $css = self::atrule_restore( $css );
227
+ $css = self::tree_shaking4var( $css );
228
+ return $css;
229
+ }
230
+ }
inc/vk-css-optimize/package/class-vk-css-optimize.php CHANGED
@@ -1,8 +1,13 @@
1
  <?php
 
 
 
 
 
 
2
  /**
3
  * VK CSS Optimize
4
  *
5
- * @package Lightning
6
  */
7
 
8
  /**
@@ -12,44 +17,250 @@ if ( ! class_exists( 'VK_CSS_Optimize' ) ) {
12
  class VK_CSS_Optimize {
13
 
14
  public function __construct() {
15
- add_action( 'get_header', array( __CLASS__, 'get_html_start' ), 2147483647 );
16
- add_action( 'shutdown', array( __CLASS__, 'get_html_end' ), 0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
 
19
  public static function get_html_start() {
20
- ob_start( 'VK_CSS_Optimize::css_optimize' );
21
  }
22
 
23
  public static function get_html_end() {
24
- if ( ob_get_length() ) {
25
  ob_end_flush();
26
  }
27
  }
28
 
29
- public static function css_optimize( $buffer ) {
30
- $options = get_option( 'lightning_theme_options' );
 
 
 
 
 
 
 
31
 
32
  // CSS Tree Shaking.
33
  require_once dirname( __FILE__ ) . '/class-css-tree-shaking.php';
34
- global $vk_css_tree_shaking_array;
 
35
  foreach ( $vk_css_tree_shaking_array as $vk_css_array ) {
36
  $options['ssl']['verify_peer'] = false;
37
  $options['ssl']['verify_peer_name'] = false;
38
 
39
- require_once ABSPATH . 'wp-admin/includes/file.php';
40
  $path_name = $vk_css_array['path'];
41
- if ( WP_Filesystem() ) {
42
  global $wp_filesystem;
43
- $css = $wp_filesystem->get_contents( $path_name );
44
  }
45
 
46
- $css = celtislab\CSS_tree_shaking::extended_minify( $css, $buffer );
47
- $buffer = str_replace(
48
  '<link rel=\'stylesheet\' id=\'' . $vk_css_array['id'] . '-css\' href=\'' . $vk_css_array['url'] . '?ver=' . $vk_css_array['version'] . '\' type=\'text/css\' media=\'all\' />',
49
  '<style id=\'' . $vk_css_array['id'] . '-css\' type=\'text/css\'>' . $css . '</style>',
50
  $buffer
51
  );
52
- $buffer = str_replace(
53
  '<link rel=\'stylesheet\' id=\'' . $vk_css_array['id'] . '-css\' href=\'' . $vk_css_array['url'] . '\' type=\'text/css\' media=\'all\' />',
54
  '<style id=\'' . $vk_css_array['id'] . '-css\' type=\'text/css\'>' . $css . '</style>',
55
  $buffer
@@ -57,18 +268,63 @@ if ( ! class_exists( 'VK_CSS_Optimize' ) ) {
57
 
58
  }
59
 
60
- if ( ! empty( $options['optimize_css'] ) && 'optomize-all-css' === $options['optimize_css'] ) {
61
- // CSS Preload.
62
- $buffer = str_replace(
63
- 'link rel=\'stylesheet\'',
64
- 'link rel="preload" as="style" onload="this.onload=null;this.rel=\'stylesheet\'"',
65
- $buffer
66
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  }
68
 
69
- return $buffer;
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
  new VK_CSS_Optimize();
74
  }
1
  <?php
2
+ /*
3
+ The original of this file is located at:
4
+ https://github.com/vektor-inc/vektor-wp-libraries
5
+ If you want to change this file, please change the original file.
6
+ */
7
+
8
  /**
9
  * VK CSS Optimize
10
  *
 
11
  */
12
 
13
  /**
17
  class VK_CSS_Optimize {
18
 
19
  public function __construct() {
20
+ add_action( 'customize_register', array( __CLASS__, 'customize_register' ) );
21
+ add_filter( 'css_tree_shaking_exclude', array( __CLASS__, 'tree_shaking_exclude' ) );
22
+
23
+ $options = VK_CSS_Optimize::get_css_optimize_options();
24
+
25
+ if ( ! empty( $options['tree_shaking'] ) ) {
26
+ add_action( 'get_header', array( __CLASS__, 'get_html_start' ), 2147483647 );
27
+ add_action( 'shutdown', array( __CLASS__, 'get_html_end' ), 0 );
28
+ }
29
+
30
+ if ( ! empty( $options['preload'] ) ) {
31
+ add_filter( 'style_loader_tag', array( __CLASS__, 'css_preload' ), 10, 4 );
32
+ }
33
+ }
34
+
35
+ public static function customize_register( $wp_customize ){
36
+ global $prefix_customize_panel;
37
+ $wp_customize->add_section(
38
+ 'css_optimize', array(
39
+ 'title' => $prefix_customize_panel . __( 'CSS Optimize ( Speed up ) Settings', 'vk-all-in-one-expansion-unit' ),
40
+ 'priority' => 450,
41
+ )
42
+ );
43
+
44
+ // Tree shaking
45
+ ////////////////////////////////////////////////////////////////
46
+
47
+ $wp_customize->add_setting(
48
+ 'tree_shaking_title',
49
+ array(
50
+ 'sanitize_callback' => 'sanitize_text_field',
51
+ )
52
+ );
53
+ $wp_customize->add_control(
54
+ new Custom_Html_Control(
55
+ $wp_customize,
56
+ 'tree_shaking_title',
57
+ array(
58
+ 'label' => __( 'Tree shaking', 'vk-all-in-one-expansion-unit' ),
59
+ 'section' => 'css_optimize',
60
+ 'type' => 'text',
61
+ 'custom_title_sub' => '',
62
+ // 'custom_html' => __( 'Move part of CSS and JS to the footer to improve display speed.', 'vk-all-in-one-expansion-unit' ),
63
+ )
64
+ )
65
+ );
66
+
67
+ $wp_customize->add_setting(
68
+ 'vk_css_optimize_options[tree_shaking]',
69
+ array(
70
+ 'default' => '',
71
+ 'type' => 'option',
72
+ 'capability' => 'edit_theme_options',
73
+ 'sanitize_callback' => array( 'VK_Helpers', 'sanitize_choice' ),
74
+ )
75
+ );
76
+ $wp_customize->add_control(
77
+ 'vk_css_optimize_options[tree_shaking]',
78
+ array(
79
+ 'label' => __( 'Tree shaking activation settings', 'vk-all-in-one-expansion-unit' ),
80
+ 'section' => 'css_optimize',
81
+ 'settings' => 'vk_css_optimize_options[tree_shaking]',
82
+ 'type' => 'select',
83
+ 'description' => __( 'Output only the main CSS of the page inline', 'vk-all-in-one-expansion-unit' ),
84
+ 'choices' => array(
85
+ '' => __( 'Nothing to do', 'vk-all-in-one-expansion-unit' ),
86
+ 'active' => __( 'Active Tree shaking (Recomend)', 'vk-all-in-one-expansion-unit' ),
87
+ ),
88
+ )
89
+ );
90
+
91
+ $wp_customize->add_setting(
92
+ 'vk_css_optimize_options[tree_shaking_class_exclude]',
93
+ array(
94
+ 'default' => '',
95
+ 'type' => 'option',
96
+ 'capability' => 'edit_theme_options',
97
+ 'sanitize_callback' => 'sanitize_text_field',
98
+ )
99
+ );
100
+ $wp_customize->add_control(
101
+ 'vk_css_optimize_options[tree_shaking_class_exclude]',
102
+ array(
103
+ 'label' => __( 'Exclude class of tree shaking', 'vk-all-in-one-expansion-unit' ),
104
+ 'section' => 'css_optimize',
105
+ 'settings' => 'vk_css_optimize_options[tree_shaking_class_exclude]',
106
+ 'type' => 'textarea',
107
+ 'description' => __( 'If you choose "Active Tree shaking" that delete the useless css.If you using active css class that please fill in class name. Ex) btn-active,slide-active,scrolled', 'vk-all-in-one-expansion-unit' ),
108
+ )
109
+ );
110
+
111
+ // Preload
112
+ ////////////////////////////////////////////////////////////////
113
+ $wp_customize->add_setting(
114
+ 'css_preload_title',
115
+ array(
116
+ 'sanitize_callback' => 'sanitize_text_field',
117
+ )
118
+ );
119
+ $wp_customize->add_control(
120
+ new Custom_Html_Control(
121
+ $wp_customize,
122
+ 'css_preload_title',
123
+ array(
124
+ 'label' => __( 'Preload CSS', 'vk-all-in-one-expansion-unit' ),
125
+ 'section' => 'css_optimize',
126
+ 'type' => 'text',
127
+ 'custom_title_sub' => '',
128
+ // 'custom_html' => __( 'Move part of CSS and JS to the footer to improve display speed.', 'vk-all-in-one-expansion-unit' ),
129
+ )
130
+ )
131
+ );
132
+
133
+ $wp_customize->add_setting(
134
+ 'vk_css_optimize_options[preload]',
135
+ array(
136
+ 'default' => '',
137
+ 'type' => 'option',
138
+ 'capability' => 'edit_theme_options',
139
+ 'sanitize_callback' => 'sanitize_text_field',
140
+ )
141
+ );
142
+ $wp_customize->add_control(
143
+ 'vk_css_optimize_options[preload]',
144
+ array(
145
+ 'label' => __( 'Preload CSS activation settings', 'vk-all-in-one-expansion-unit' ),
146
+ 'section' => 'css_optimize',
147
+ 'settings' => 'vk_css_optimize_options[preload]',
148
+ 'description' => __( 'Preload css except for critical css', 'vk-all-in-one-expansion-unit' ),
149
+ 'type' => 'select',
150
+ 'choices' => array(
151
+ '' => __( 'Nothing to do', 'vk-all-in-one-expansion-unit' ),
152
+ 'active' => __( 'Active Preload CSS (Recomend)', 'vk-all-in-one-expansion-unit' ),
153
+ ),
154
+ )
155
+ );
156
+
157
+ }
158
+
159
+ /**
160
+ *
161
+ */
162
+ public static function get_css_optimize_options(){
163
+
164
+ $theme_textdomain = wp_get_theme()->get( 'TextDomain' );
165
+ if ( 'lightning' === $theme_textdomain || 'lightning-pro' === $theme_textdomain ){
166
+ $old_options = get_option( 'lightning_theme_options' );
167
+ } else if ( 'katawara' === $theme_textdomain ){
168
+ $old_options = get_option( 'katawara_theme_options' );
169
+ } else {
170
+ $old_options = get_option( 'vk_blocks_options' );
171
+ }
172
+
173
+ $vk_css_optimize_options = get_option( 'vk_css_optimize_options' );
174
+ $vk_css_optimize_options_default = array(
175
+ 'tree_shaking' => 'active',
176
+ 'preload' => 'active',
177
+ );
178
+
179
+ // fall back function
180
+ // Actualy other array exist but optimize_css is most important
181
+ if ( ! isset( $vk_css_optimize_options['tree_shaking'] ) ) {
182
+
183
+ if ( isset( $old_options['optimize_css'] ) ){
184
+ if ( $old_options['optimize_css'] === 'optomize-all-css' || $old_options['optimize_css'] === 'tree-shaking' ){
185
+ $vk_css_optimize_options['tree_shaking'] = 'active';
186
+ } else {
187
+ $vk_css_optimize_options['tree_shaking'] = '';
188
+ }
189
+ }
190
+ }
191
+
192
+ if ( ! isset( $vk_css_optimize_options['tree_shaking_class_exclude'] ) ) {
193
+ if ( ! empty( $old_options['tree_shaking_class_exclude'] ) ){
194
+ $vk_css_optimize_options['tree_shaking_class_exclude'] = esc_html( $old_options['tree_shaking_class_exclude'] );
195
+ }
196
+ }
197
+
198
+ if ( ! isset( $vk_css_optimize_options['preload'] ) ) {
199
+
200
+ if ( isset( $old_options['optimize_css'] ) ){
201
+ if ( $old_options['optimize_css'] === 'optomize-all-css'){
202
+ $vk_css_optimize_options['preload'] ='active';
203
+ } else {
204
+ $vk_css_optimize_options['preload'] = '';
205
+ }
206
+
207
+ }
208
+
209
+ }
210
+ $vk_css_optimize_options = wp_parse_args( $vk_css_optimize_options, $vk_css_optimize_options_default );
211
+ if (
212
+ ! isset( $vk_css_optimize_options['tree_shaking'] ) ||
213
+ ! isset( $vk_css_optimize_options['tree_shaking_class_exclude'] ) ||
214
+ ! isset( $vk_css_optimize_options['preload'] )
215
+ ){
216
+ update_option( 'vk_css_optimize_options', $vk_css_optimize_options );
217
+ }
218
+
219
+ return $vk_css_optimize_options;
220
  }
221
 
222
  public static function get_html_start() {
223
+ ob_start( 'VK_CSS_Optimize::css_tree_shaking_buffer' );
224
  }
225
 
226
  public static function get_html_end() {
227
+ if ( ob_get_length() ){
228
  ob_end_flush();
229
  }
230
  }
231
 
232
+ public static function css_tree_shaking_array() {
233
+ $vk_css_tree_shaking_array = array();
234
+ $vk_css_tree_shaking_array = apply_filters( 'vk_css_tree_shaking_array', $vk_css_tree_shaking_array );
235
+ return $vk_css_tree_shaking_array;
236
+ }
237
+
238
+ public static function css_tree_shaking_buffer( $buffer ) {
239
+
240
+ $options = VK_CSS_Optimize::get_css_optimize_options();
241
 
242
  // CSS Tree Shaking.
243
  require_once dirname( __FILE__ ) . '/class-css-tree-shaking.php';
244
+ $vk_css_tree_shaking_array = VK_CSS_Optimize::css_tree_shaking_array();
245
+
246
  foreach ( $vk_css_tree_shaking_array as $vk_css_array ) {
247
  $options['ssl']['verify_peer'] = false;
248
  $options['ssl']['verify_peer_name'] = false;
249
 
250
+ require_once(ABSPATH.'wp-admin/includes/file.php');
251
  $path_name = $vk_css_array['path'];
252
+ if( WP_Filesystem() ){
253
  global $wp_filesystem;
254
+ $css = $wp_filesystem->get_contents($path_name);
255
  }
256
 
257
+ $css = celtislab\CSS_tree_shaking::extended_minify( $css, $buffer );
258
+ $buffer = str_replace(
259
  '<link rel=\'stylesheet\' id=\'' . $vk_css_array['id'] . '-css\' href=\'' . $vk_css_array['url'] . '?ver=' . $vk_css_array['version'] . '\' type=\'text/css\' media=\'all\' />',
260
  '<style id=\'' . $vk_css_array['id'] . '-css\' type=\'text/css\'>' . $css . '</style>',
261
  $buffer
262
  );
263
+ $buffer = str_replace(
264
  '<link rel=\'stylesheet\' id=\'' . $vk_css_array['id'] . '-css\' href=\'' . $vk_css_array['url'] . '\' type=\'text/css\' media=\'all\' />',
265
  '<style id=\'' . $vk_css_array['id'] . '-css\' type=\'text/css\'>' . $css . '</style>',
266
  $buffer
268
 
269
  }
270
 
271
+ return $buffer;
272
+ }
273
+
274
+ public static function css_preload( $tag, $handle, $href, $media ) {
275
+
276
+ $vk_css_tree_shaking_array = VK_CSS_Optimize::css_tree_shaking_array();
277
+
278
+ $tree_shaking_handles = array();
279
+
280
+ $options = VK_CSS_Optimize::get_css_optimize_options();
281
+
282
+ // tree shaking がかかっているものはpreloadから除外する
283
+ // でないと表示時に一瞬崩れて結局実用性に問題があるため
284
+ foreach ( $vk_css_tree_shaking_array as $vk_css_array ) {
285
+ $tree_shaking_handles[] = $vk_css_array['id'];
286
+ }
287
+ // クリティカルじゃないCSS(tree shakingにかけているもの以外)をpreload
288
+ if ( ! in_array( $handle, $tree_shaking_handles ) ){
289
+ $tag = "<link rel='preload' id='".$handle."-css' href='".$href."' as='style' onload=\"this.onload=null;this.rel='stylesheet'\"/>\n";
290
+ $tag .= "<link rel='stylesheet' id='".$handle."-css' href='".$href."' media='print' onload=\"this.media='all'; this.onload=null;\">\n";
291
  }
292
 
293
+ return $tag;
294
  }
295
 
296
+
297
+ /**
298
+ * Exclude CSS.
299
+ *
300
+ * @param string $inidata exclude css class.
301
+ */
302
+ public static function tree_shaking_exclude( $inidata ) {
303
+ $options = VK_CSS_Optimize::get_css_optimize_options();
304
+
305
+ $exclude_classes_array = array();
306
+
307
+ if ( ! empty( $options['tree_shaking_class_exclude'] ) ) {
308
+
309
+ // delete before after space.
310
+ $exclude_clssses = trim( $options['tree_shaking_class_exclude'] );
311
+
312
+ // convert tab and br to space.
313
+ $exclude_clssses = preg_replace( '/[\n\r\t]/', '', $exclude_clssses );
314
+
315
+ // Change multiple spaces to single space.
316
+ $exclude_clssses = preg_replace( '/\s/', '', $exclude_clssses );
317
+ $exclude_clssses = str_replace( ',', ',', $exclude_clssses );
318
+ $exclude_clssses = str_replace( '、', ',', $exclude_clssses );
319
+ $exclude_classes_array = explode( ',', $exclude_clssses );
320
+
321
+ }
322
+
323
+ $inidata['class'] = array_merge( $inidata['class'], $exclude_classes_array );
324
+
325
+ return $inidata;
326
+ }
327
+
328
  }
329
  new VK_CSS_Optimize();
330
  }
inc/vk-css-optimize/vk-css-optimize-config.php CHANGED
@@ -2,54 +2,24 @@
2
  /**
3
  * VK CSS Tree Shaking Config
4
  *
5
- * @package Lightning
6
  */
7
 
8
- /**
9
- * Optimize CSS.
10
- */
11
- function veu_optimize_css() {
12
- $options = get_option( 'vkExUnit_pagespeeding' );
13
-
14
- if ( ! isset( $options['css_optimize'] ) ) {
15
- $options['css_optimize'] = 'default';
16
- } elseif ( 'optomize-all-css' === $options['css_optimize'] ) {
17
- $options['css_optimize'] = 'tree-shaking';
18
- update_option( 'vkExUnit_pagespeeding', $options );
19
- }
20
-
21
- if ( ! empty( $options['css_optimize'] ) && ( 'optomize-all-css' === $options['css_optimize'] || 'tree-shaking' === $options['css_optimize'] ) ) {
22
-
23
- // 表示位置の配列.
24
- global $vk_css_tree_shaking_array;
25
- global $vkExUnit_version;
26
-
27
- if ( empty( $vk_css_tree_shaking_array ) ) {
28
- $vk_css_tree_shaking_array = array(
29
- array(
30
- 'id' => 'vkExUnit_common_style',
31
- 'url' => veu_get_directory_uri( '/assets/css/vkExUnit_style.css' ),
32
- 'path' => veu_get_directory( '/assets/css/vkExUnit_style.css' ),
33
- 'version' => $vkExUnit_version,
34
- ),
35
- );
36
- } else {
37
- $add_array = array(
38
- 'id' => 'vkExUnit_common_style',
39
- 'url' => veu_get_directory_uri( '/assets/css/vkExUnit_style.css' ),
40
- 'path' => veu_get_directory( '/assets/css/vkExUnit_style.css' ),
41
- 'version' => $vkExUnit_version,
42
- );
43
- array_push( $vk_css_tree_shaking_array, $add_array );
44
- }
45
 
46
- $vk_css_tree_shaking_array = apply_filters( 'vk_css_tree_shaking_array', $vk_css_tree_shaking_array );
47
- if ( ! class_exists( 'VK_CSS_Optimize' ) ) {
48
- require_once dirname( __FILE__ ) . '/package/class-vk-css-optimize.php';
49
- }
50
- }
 
 
 
 
51
  }
52
- add_action( 'after_setup_theme', 'veu_optimize_css' );
53
 
54
  /**
55
  * CSS Tree Shaking Exclude
2
  /**
3
  * VK CSS Tree Shaking Config
4
  *
5
+ * @package ExUnit
6
  */
7
 
8
+ if ( ! class_exists( 'VK_CSS_Optimize' ) ) {
9
+ require_once dirname( __FILE__ ) . '/package/class-vk-css-optimize.php';
10
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ function veu_css_tree_shaking_array( $vk_css_tree_shaking_array ){
13
+ global $vkExUnit_version;
14
+ $vk_css_tree_shaking_array[] = array(
15
+ 'id' => 'vkExUnit_common_style',
16
+ 'url' => veu_get_directory_uri( '/assets/css/vkExUnit_style.css' ),
17
+ 'path' => veu_get_directory( '/assets/css/vkExUnit_style.css' ),
18
+ 'version' => $vkExUnit_version,
19
+ );
20
+ return $vk_css_tree_shaking_array;
21
  }
22
+ add_filter( 'vk_css_tree_shaking_array', 'veu_css_tree_shaking_array' );
23
 
24
  /**
25
  * CSS Tree Shaking Exclude
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: Google Analytics, New posts, Related Posts, sitemap, sns, twitter card, Facebook Page Plugin, OG tags,
5
  Requires at least: 5.0.0
6
  Tested up to: 5.5.1
7
- Stable tag: 9.41.0.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -81,6 +81,9 @@ e.g.
81
 
82
  == Changelog ==
83
 
 
 
 
84
  = 9.41.0.0 =
85
  [ Specification Change ] Cope with G-XXXXXXXXXX
86
  [ Bug fix ][ Facebook Page Plugin / twitter widget ] fix unload
4
  Tags: Google Analytics, New posts, Related Posts, sitemap, sns, twitter card, Facebook Page Plugin, OG tags,
5
  Requires at least: 5.0.0
6
  Tested up to: 5.5.1
7
+ Stable tag: 9.42.0.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
81
 
82
  == Changelog ==
83
 
84
+ = 9.42.0.0 =
85
+ [ Specification Change ][ CSS Optimize ] Change to common setting
86
+
87
  = 9.41.0.0 =
88
  [ Specification Change ] Cope with G-XXXXXXXXXX
89
  [ Bug fix ][ Facebook Page Plugin / twitter widget ] fix unload
vkExUnit.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: VK All in One Expansion Unit
4
  * Plugin URI: https://ex-unit.nagoya
5
  * Description: This plug-in is an integrated plug-in with a variety of features that make it powerful your web site. Many features can be stopped individually. Example Facebook Page Plugin,Social Bookmarks,Print OG Tags,Print Twitter Card Tags,Print Google Analytics tag,New post widget,Insert Related Posts and more!
6
- * Version: 9.41.0.0
7
  * Author: Vektor,Inc.
8
  * Text Domain: vk-all-in-one-expansion-unit
9
  * Domain Path: /languages
3
  * Plugin Name: VK All in One Expansion Unit
4
  * Plugin URI: https://ex-unit.nagoya
5
  * Description: This plug-in is an integrated plug-in with a variety of features that make it powerful your web site. Many features can be stopped individually. Example Facebook Page Plugin,Social Bookmarks,Print OG Tags,Print Twitter Card Tags,Print Google Analytics tag,New post widget,Insert Related Posts and more!
6
+ * Version: 9.42.0.0
7
  * Author: Vektor,Inc.
8
  * Text Domain: vk-all-in-one-expansion-unit
9
  * Domain Path: /languages