PluginProbe
VK Blocks / 1.33.2.1
VK Blocks v1.33.2.1
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.33.2.1, at vk-blocks.php

280 lines 8.5 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.33.2.1
7 * Stable tag: 1.33.2.1
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 // Composer のファイルを読み込み ( composer install --no-dev ).
22 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
23 // Set plugin dir path.
24 define( 'VK_BLOCKS_DIR_PATH', plugin_dir_path( __FILE__ ) );
25 // Set Plugin Dir URL.
26 define( 'VK_BLOCKS_DIR_URL', plugin_dir_url( __FILE__ ) );
27
28 /*
29 無料版の VK Blocks の無効化が正常に動作しなかった場合に無料版の関数が�
30 �に定義され
31 重複 -> Fatal error になるため function_exists は フォールバックとして付与している
32 */
33 if ( ! function_exists( 'vk_blocks_get_version' ) ) {
34 /**
35 * Get Plugin Version
36 *
37 * @return string
38 */
39 function vk_blocks_get_version() {
40 $data = get_file_data( __FILE__, array( 'version' => 'Version' ) );
41 return $data['version'];
42 }
43 }
44 if ( ! function_exists( 'vk_blocks_deactivate_plugin' ) ) {
45 /**
46 * Plugin deactive function
47 *
48 * @param string $plugin_path Plugin path to disable.
49 * @return void
50 */
51 function vk_blocks_deactivate_plugin( $plugin_path ) {
52 include_once ABSPATH . 'wp-admin/includes/plugin.php';
53 if ( is_plugin_active( $plugin_path ) ) {
54 $active_plugins = get_option( 'active_plugins' );
55 // delete active plugin.
56 $active_plugins = array_diff( $active_plugins, array( $plugin_path ) );
57 // re index active plugin.
58 $active_plugins = array_values( $active_plugins );
59 update_option( 'active_plugins', $active_plugins );
60 }
61 }
62 }
63
64 /**
65 * Deactive VK Blocks ( Free )
66 *
67 * 関数名�
68 �れると無料版 VK Blocks の宣言と被ってエラーになるので一時的な回避処理で無名関数を利用している
69 */
70 add_action(
71 'admin_init',
72 function() {
73 $plugin_base_dir = dirname( __FILE__ );
74 include_once ABSPATH . 'wp-admin/includes/plugin.php';
75 if ( is_plugin_active( 'vk-blocks-pro/vk-blocks.php' ) ) {
76 // Deactive Plugin VK Blocks ( free ).
77 if ( function_exists( 'vk_blocks_deactivate_plugin' ) ) {
78 vk_blocks_deactivate_plugin( 'vk-blocks/vk-blocks.php' );
79 }
80 }
81 // Deactive ExUnit included VK Blocks.
82 $options = get_option( 'vkExUnit_common_options' );
83 if ( ! empty( $options['active_vk-blocks'] ) ) {
84 $options['active_vk-blocks'] = false;
85 update_option( 'vkExUnit_common_options', $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 9999
96 );
97
98 if ( is_admin() && ! is_network_admin() ) {
99 $vk_blocks_options = get_option( 'vkExUnit_common_options' );
100 if ( ! empty( $vk_blocks_options['active_vk-blocks'] ) ) {
101 $vk_blocks_options['active_vk-blocks'] = false;
102 update_option( 'vkExUnit_common_options', $vk_blocks_options );
103
104 add_action(
105 'admin_notices',
106 function() {
107 echo '<div class="updated notice"><p>';
108 echo esc_html( __( 'Disabled Blocks module on VK All in One Expansion Unit. Because VK-Blocks Plugin running.', 'vk-blocks' ) );
109 echo '</p></div>';
110 }
111 );
112 }
113 }
114
115 /**
116 * Load VK Blocks
117 */
118 require_once plugin_dir_path( __FILE__ ) . 'inc/vk-blocks-config.php';
119
120 /**
121 * Check Free or Pro
122 *
123 * @return bool
124 */
125 function vk_blocks_is_pro() {
126 $return = false;
127 // 注意 : strpos() は合致した開始位置を返すので、最初に合致すると、
128 // "合致している"にも関わらず返り値は"0"を返してしまうため !== false で処理している.
129 if ( strpos( plugin_dir_path( __FILE__ ), 'vk-blocks-pro' ) !== false ) {
130 $return = true;
131 }
132 return $return;
133 }
134
135 /****************************************************************************************
136 * Load updater ( Pro version only )
137 */
138
139 if ( vk_blocks_is_pro() ) {
140 add_action( 'after_setup_theme', 'vk_blocks_update_checker' );
141 }
142
143 /**
144 * Perform update checks on VK Blocks.
145 *
146 * @return void
147 */
148 function vk_blocks_update_checker() {
149
150 // Cope with : WP HTTP Error: cURL error 60: SSL certificate problem: certificate has expired.
151 add_filter( 'https_ssl_verify', '__return_false' );
152
153 $update_checker = Puc_v4_Factory::buildUpdateChecker(
154 'https://vws.vektor-inc.co.jp/updates/?action=get_metadata&slug=vk-blocks-pro',
155 __FILE__, // この処理を他の場所に移動するとここを変更しないといけなくなるので注意.
156 'vk-blocks-pro'
157 );
158
159 $update_checker->addQueryArgFilter( 'vk_blocks_get_license_check_query_arg' );
160
161 // 管理画面 かつ テーマオプションの編集権限がある場合.
162 if ( is_admin() && current_user_can( 'edit_theme_options' ) ) {
163 $network_runnning_pro = false;
164
165 // マルチサイトでOriginal Brand Unitが動いていたら.
166 if ( is_multisite() ) {
167 $network_options = get_site_option( 'active_sitewide_plugins', array() );
168 if ( isset( $network_options['lightning-original-brand-unit/lightning-original-brand-unit.php'] ) ) {
169 $network_runnning_pro = true;
170 }
171 }
172
173 // マルチサイトでOriginal Brand Unitが動いていない && Original Brand Unitが有効になっていない.
174 $active_plugins = get_option( 'active_plugins', array() );
175 if ( ! $network_runnning_pro && ! in_array( 'lightning-original-brand-unit/lightning-original-brand-unit.php', $active_plugins, true ) ) {
176 add_action(
177 'admin_notices',
178 function () use ( $update_checker ) {
179 vk_blocks_the_update_messsage( $update_checker );
180 }
181 );
182 }
183 }
184 }
185
186 /**
187 * Update alert message
188 *
189 * @param object $update_checker .
190 * @return void
191 */
192 function vk_blocks_the_update_messsage( $update_checker ) {
193 $state = $update_checker->getUpdateState();
194 $update = $state->getUpdate();
195
196 $options = get_option( 'vk_blocks_options' );
197 if ( ! empty( $options['vk_blocks_pro_license_key'] ) ) {
198 $license = esc_html( $options['vk_blocks_pro_license_key'] );
199 } else {
200 $license = '';
201 }
202
203 $notice_title = '';
204
205 // ライセンスキーが未�
206 �力の場合.
207 if ( empty( $license ) && wp_get_theme()->Template !== 'katawara' ) {
208 $notice_title = __( 'License Key has no registered.', 'vk-blocks' );
209 } elseif ( ! empty( $update ) && empty( $update->download_url ) ) {
210
211 // ライセンスが切れている あるいは 無効な場合.
212 // アップデートは存在するがURLが帰ってこなかった場合.
213 $notice_title = __(
214 'The VK Blocks Pro license is invalid.',
215 'vk-blocks'
216 );
217 }
218
219 if ( empty( $notice_title ) ) {
220 return;
221 }
222
223 $link_url = wp_nonce_url(
224 add_query_arg(
225 array(
226 'puc_check_for_updates' => 1,
227 'puc_slug' => $update_checker->slug,
228 ),
229 self_admin_url( 'plugins.php' )
230 ),
231 'puc_check_for_updates'
232 );
233
234 $alert_html = '';
235 $alert_html .= '<div class="error">';
236 $alert_html .= '<h4>' . $notice_title . '</h4>';
237 $alert_html .= '<p>' . __(
238 'Enter a valid license key for any of the following products on the settings screen.',
239 'vk-blocks'
240 ) . '</p>';
241 $alert_html .= '<ul>';
242 $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>';
243 $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>';
244 $alert_html .= '</ul>';
245
246 $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>';
247
248 $alert_html .= '<p>' . sprintf(
249 /* translators: %s: 再読み込みURL */
250 __(
251 'Even after valid license key registration you still seeing this message, <a href="%s">please click here to reload</a>.',
252 'vk-blocks'
253 ),
254 $link_url
255 ) . '</p>';
256 $alert_html .= '</div>';
257 echo wp_kses_post( $alert_html );
258 }
259
260 /**
261 * Register update license key
262 *
263 * @param array $query_args : updatechacker array.
264 * @return $query_args
265 */
266 function vk_blocks_get_license_check_query_arg( $query_args ) {
267 $options = get_option( 'vk_blocks_options' );
268 $license = '';
269 if ( ! empty( $options['vk_blocks_pro_license_key'] ) ) {
270 $license = esc_html( $options['vk_blocks_pro_license_key'] );
271 }
272
273 if ( ! empty( $license ) ) {
274 $query_args['vk-blocks-pro-license-key'] = $license;
275 }
276 $query_args['template'] = wp_get_theme()->Template;
277
278 return $query_args;
279 }
280