PluginProbe
VK Blocks / 1.37.0.0
VK Blocks v1.37.0.0
1.126.4 1.126.3 1.126.1 1.126.2 1.126.0 1.125.0 1.124.0 1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 All 287 releases
vk-blocks / vk-blocks.php

vk-blocks.php in VK Blocks 1.37.0.0, at vk-blocks.php

305 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: VK Blocks
4 * Plugin URI: https://github.com/vektor-inc/vk-blocks
5 * Description: This is a plugin that extends Gutenberg's blocks.
6 * Version: 1.37.0.0
7 * Stable tag: 1.36.2.0
8 * Requires at least: 5.8
9 * Author: Vektor,Inc.
10 * Author URI: https://vektor-inc.co.jp
11 * Text Domain: vk-blocks
12 *
13 * @package vk-blocks
14 */
15
16 // Do not load directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /*
22 無料版の VK Blocks の無効化が正常に動作しなかった場合に無料版の関数が�
23 �に定義され
24 重複 -> Fatal error になるため function_exists は フォールバックとして付与している
25 */
26 if ( ! function_exists( 'vk_blocks_get_version' ) ) {
27 /**
28 * Get Plugin Version
29 *
30 * @return string
31 */
32 function vk_blocks_get_version() {
33 $data = get_file_data( __FILE__, array( 'version' => 'Version' ) );
34 return $data['version'];
35 }
36 }
37
38 if ( ! function_exists( 'vk_blocks_deactivate_plugin' ) ) {
39 /**
40 * Plugin deactive function
41 *
42 * @param string $plugin_path Plugin path to disable.
43 * @return void
44 */
45 function vk_blocks_deactivate_plugin( $plugin_path ) {
46 include_once ABSPATH . 'wp-admin/includes/plugin.php';
47 if ( is_plugin_active( $plugin_path ) ) {
48 $active_plugins = get_option( 'active_plugins' );
49 // delete active plugin.
50 $active_plugins = array_diff( $active_plugins, array( $plugin_path ) );
51 // re index active plugin.
52 $active_plugins = array_values( $active_plugins );
53 update_option( 'active_plugins', $active_plugins );
54 }
55 }
56 }
57
58 /**
59 * Deactive VK Blocks ( Free )
60 *
61 * 読み込んでだ時に無料版が有効化されていたら、誤動作しないようになるべく早く無効化するためそのまま実行させている
62 * VK Blocks 無料版の 1.36.0 で vk_blocks_is_pro を function_exists を経由せずに定義してしまっているため、
63 * 無料版 1.36.0 を停止する前に vk_blocks_is_pro を定義するとエラーになるため、
64 * vk_blocks_is_pro の定義前に無料版の無効化処理を行っている
65 * 1.36.0無料版有効化時にPRo版を有効化時に一瞬エラーが表示されるが、再読み込みで復帰する
66 * 1.36.0無料版をアップデートしてもらわないとこれは避けられないので、当面はこのまま運用する
67 *
68 * プロ版での読み込みかどうかの判定は strpos を使っているが、
69 * strpos は"合致している"にも関わらず返り値は"0"を返してしまうため !== false で処理している.
70 */
71 if ( strpos( plugin_dir_path( __FILE__ ), 'vk-blocks-pro' ) !== false ) {
72 include_once ABSPATH . 'wp-admin/includes/plugin.php';
73
74 if ( is_plugin_active( 'vk-blocks-pro/vk-blocks.php' ) ) {
75 // Deactive Plugin VK Blocks ( free ).
76 if ( function_exists( 'vk_blocks_deactivate_plugin' ) ) {
77 vk_blocks_deactivate_plugin( 'vk-blocks/vk-blocks.php' );
78 }
79 }
80
81 // Deactive ExUnit included VK Blocks.
82 $vk_blocks_exunit_common_options = get_option( 'vkExUnit_common_options' );
83 if ( ! empty( $vk_blocks_exunit_common_options['active_vk-blocks'] ) ) {
84 $vk_blocks_exunit_common_options['active_vk-blocks'] = false;
85 update_option( 'vkExUnit_common_options', $vk_blocks_exunit_common_options );
86 }
87
88 // Deactive VK Grid Colomun Card Plugin.
89 if ( is_plugin_active( 'vk-gridcolcard/vk-gridcolcard.php' ) ) {
90 if ( function_exists( 'vk_blocks_deactivate_plugin' ) ) {
91 vk_blocks_deactivate_plugin( 'vk-gridcolcard/vk-gridcolcard.php' );
92 }
93 }
94 }
95
96 if ( is_admin() && ! is_network_admin() ) {
97 $vk_blocks_options = get_option( 'vkExUnit_common_options' );
98 if ( ! empty( $vk_blocks_options['active_vk-blocks'] ) ) {
99 $vk_blocks_options['active_vk-blocks'] = false;
100 update_option( 'vkExUnit_common_options', $vk_blocks_options );
101
102 add_action(
103 'admin_notices',
104 function() {
105 echo '<div class="updated notice"><p>';
106 echo esc_html( __( 'Disabled Blocks module on VK All in One Expansion Unit. Because VK-Blocks Plugin running.', 'vk-blocks' ) );
107 echo '</p></div>';
108 }
109 );
110 }
111 }
112
113 /*
114 無料版の VK Blocks の無効化が正常に動作しなかった場合に無料版の関数が�
115 �に定義され
116 重複 -> Fatal error になるため function_exists は フォールバックとして付与している
117 */
118 if ( ! function_exists( 'vk_blocks_is_pro' ) ) {
119 /**
120 * Check Free or Pro
121 *
122 * @return bool
123 */
124 function vk_blocks_is_pro() {
125 $return = false;
126 // 注意 : strpos() は合致した開始位置を返すので、最初に合致すると、
127 // "合致している"にも関わらず返り値は"0"を返してしまうため !== false で処理している.
128 if ( strpos( plugin_dir_path( __FILE__ ), 'vk-blocks-pro' ) !== false ) {
129 $return = true;
130 }
131 return $return;
132 }
133 }
134
135 /****************************************************************************************
136 * Start VK Blocks
137 * 無料版を無効化した後に書かないと関数の二重宣言などになるので注意
138 */
139
140 // Composer のファイルを読み込み ( composer install --no-dev ).
141 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
142 // Set plugin dir path.
143 if ( ! defined( 'VK_BLOCKS_DIR_PATH' ) ) {
144 define( 'VK_BLOCKS_DIR_PATH', plugin_dir_path( __FILE__ ) );
145 }
146 // Set Plugin Dir URL.
147 if ( ! defined( 'VK_BLOCKS_DIR_URL' ) ) {
148 define( 'VK_BLOCKS_DIR_URL', plugin_dir_url( __FILE__ ) );
149 }
150 // Load VK Blocks
151 require_once plugin_dir_path( __FILE__ ) . 'inc/vk-blocks-config.php';
152
153
154 /****************************************************************************************
155 * Load updater ( Pro version only )
156 */
157
158 if ( function_exists( 'vk_blocks_is_pro' ) && vk_blocks_is_pro() ) {
159
160 // 本来 Pro 版でしか読み込まないが、1.36.0.0 は間違って読み込んでしまっており
161 // 無料版 1.36.0 を有効化していると previously declared になるため ! function_exists() を通した上で宣言している.
162 if ( ! function_exists( 'vk_blocks_update_checker' ) ) {
163 /**
164 * Perform update checks on VK Blocks.
165 *
166 * @return void
167 */
168 function vk_blocks_update_checker() {
169
170 // Cope with : WP HTTP Error: cURL error 60: SSL certificate problem: certificate has expired.
171 add_filter( 'https_ssl_verify', '__return_false' );
172
173 $update_checker = Puc_v4_Factory::buildUpdateChecker(
174 'https://vws.vektor-inc.co.jp/updates/?action=get_metadata&slug=vk-blocks-pro',
175 __FILE__, // この処理を他の場所に移動するとここを変更しないといけなくなるので注意.
176 'vk-blocks-pro'
177 );
178
179 $update_checker->addQueryArgFilter( 'vk_blocks_get_license_check_query_arg' );
180
181 // 管理画面 かつ テーマオプションの編集権限がある場合.
182 if ( is_admin() && current_user_can( 'edit_theme_options' ) ) {
183 $network_runnning_pro = false;
184
185 // マルチサイトでOriginal Brand Unitが動いていたら.
186 if ( is_multisite() ) {
187 $network_options = get_site_option( 'active_sitewide_plugins', array() );
188 if ( isset( $network_options['lightning-original-brand-unit/lightning-original-brand-unit.php'] ) ) {
189 $network_runnning_pro = true;
190 }
191 }
192
193 // マルチサイトでOriginal Brand Unitが動いていない && Original Brand Unitが有効になっていない.
194 $active_plugins = get_option( 'active_plugins', array() );
195 if ( ! $network_runnning_pro && ! in_array( 'lightning-original-brand-unit/lightning-original-brand-unit.php', $active_plugins, true ) ) {
196 add_action(
197 'admin_notices',
198 function () use ( $update_checker ) {
199 vk_blocks_the_update_messsage( $update_checker );
200 }
201 );
202 }
203 }
204 }
205 }
206
207 add_action( 'after_setup_theme', 'vk_blocks_update_checker' );
208
209 if ( ! function_exists( 'vk_blocks_the_update_messsage' ) ) {
210 /**
211 * Update alert message
212 *
213 * @param object $update_checker .
214 * @return void
215 */
216 function vk_blocks_the_update_messsage( $update_checker ) {
217 $state = $update_checker->getUpdateState();
218 $update = $state->getUpdate();
219
220 $options = get_option( 'vk_blocks_options' );
221 if ( ! empty( $options['vk_blocks_pro_license_key'] ) ) {
222 $license = esc_html( $options['vk_blocks_pro_license_key'] );
223 } else {
224 $license = '';
225 }
226
227 $notice_title = '';
228
229 // ライセンスキーが未�
230 �力の場合.
231 if ( empty( $license ) && wp_get_theme()->Template !== 'katawara' ) {
232 $notice_title = __( 'License Key has no registered.', 'vk-blocks' );
233 } elseif ( ! empty( $update ) && empty( $update->download_url ) ) {
234
235 // ライセンスが切れている あるいは 無効な場合.
236 // アップデートは存在するがURLが帰ってこなかった場合.
237 $notice_title = __(
238 'The VK Blocks Pro license is invalid.',
239 'vk-blocks'
240 );
241 }
242
243 if ( empty( $notice_title ) ) {
244 return;
245 }
246
247 $link_url = wp_nonce_url(
248 add_query_arg(
249 array(
250 'puc_check_for_updates' => 1,
251 'puc_slug' => $update_checker->slug,
252 ),
253 self_admin_url( 'plugins.php' )
254 ),
255 'puc_check_for_updates'
256 );
257
258 $alert_html = '';
259 $alert_html .= '<div class="error">';
260 $alert_html .= '<h4>VK Blocks Pro : ' . $notice_title . '</h4>';
261 $alert_html .= '<p>' . __(
262 'Enter a valid license key for any of the following products on the settings screen.',
263 'vk-blocks'
264 ) . '</p>';
265 $alert_html .= '<ul>';
266 $alert_html .= '<li><a href="https://vws.vektor-inc.co.jp/product/lightning-g3-pro-pack/?rel=vk-blocks-pro-alert" target="_blank">Lightning G3 Pro Pack</a></li>';
267 $alert_html .= '<li><a href="https://vws.vektor-inc.co.jp/product/lightning-pro-update-license?rel=vk-blocks-pro-alert" target="_blank">Lightning Pro</a></li>';
268 $alert_html .= '</ul>';
269
270 $alert_html .= '<p><a href="' . admin_url( '/options-general.php?page=vk_blocks_options' ) . '" class="button button-primary">' . __( 'Enter the license key', 'vk-blocks' ) . '</a></p>';
271
272 $alert_html .= '<p>';
273 $alert_html .= __( 'If this display does not disappear even after entering a valid license key, re-acquire the update.', 'vk-blocks' );
274 $alert_html .= ' [ <a href="' . $link_url . '">' . __( 'Re-acquisition of updates', 'vk-blocks' ) . '</a> ]';
275 $alert_html .= '</p>';
276
277 $alert_html .= '</div>';
278 echo wp_kses_post( $alert_html );
279 }
280 }
281
282 if ( ! function_exists( 'vk_blocks_get_license_check_query_arg' ) ) {
283 /**
284 * Register update license key
285 *
286 * @param array $query_args : updatechacker array.
287 * @return $query_args
288 */
289 function vk_blocks_get_license_check_query_arg( $query_args ) {
290 $options = get_option( 'vk_blocks_options' );
291 $license = '';
292 if ( ! empty( $options['vk_blocks_pro_license_key'] ) ) {
293 $license = esc_html( $options['vk_blocks_pro_license_key'] );
294 }
295
296 if ( ! empty( $license ) ) {
297 $query_args['vk-blocks-pro-license-key'] = $license;
298 }
299 $query_args['template'] = wp_get_theme()->Template;
300
301 return $query_args;
302 }
303 }
304 }
305