PluginProbe ʕ •ᴥ•ʔ
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping / 6.12.0
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping v6.12.0
6.12.1 6.12.0 6.11.0 6.10.0 6.9.1 6.9.0 6.8.1 6.8.0 6.7.4 6.7.3 6.7.2 6.7.0 4.21.7 4.22.0 4.22.1 4.23.0 4.23.1 4.23.2 4.23.3 4.24.0 4.24.1 4.24.10 4.24.11 4.24.12 4.24.13 4.24.14 4.24.15 4.24.16 4.24.17 4.24.18 4.24.19 4.24.2 4.24.4 4.24.6 4.24.7 4.24.8 4.24.9 4.25.0 4.25.1 4.25.2 4.25.4 4.25.5 4.25.6 4.25.7 4.25.8 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 4.8.0 4.8.1 4.8.3 4.8.4 4.8.5 4.9.0 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.2.0 5.3.0 5.3.1 5.3.3 5.3.4 5.3.5 6.0.0 6.1.0 6.1.1 6.1.2 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.3.0 trunk 6.4.0 1.4 6.4.1 1.4.1 6.4.2 1.5 6.4.3 1.6 6.4.5 1.6.1 6.5.0 1.6.2 6.5.1 1.7 6.5.2 1.8 6.5.3 1.9 6.5.4 1.9.1 6.5.5 1.9.10 6.5.6 1.9.11 6.5.7 1.9.12 6.5.8 1.9.2 6.6.0 1.9.3 6.6.1 1.9.4 6.6.2 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.1 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.6 3.0.7 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.11.4 3.12.0 3.13.0 3.14.0 3.14.1 3.14.2 3.14.3 3.14.4 3.15.0 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.2.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.8.0 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.9 4.0.0 4.0.1 4.0.10 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.11.0 4.11.1 4.11.2 4.11.3 4.11.4 4.11.5 4.11.6 4.11.7 4.11.8 4.11.9 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.14.0 4.14.1 4.14.2 4.15.0 4.16.0 4.16.1 4.16.2 4.17.0 4.18.0 4.18.1 4.18.2 4.18.3 4.18.4 4.18.5 4.18.6 4.19.0 4.19.1 4.2.0 4.20.0 4.20.1 4.20.2 4.20.3 4.21.0 4.21.1 4.21.2 4.21.3 4.21.4 4.21.5
flexible-shipping / vendor_prefixed / wpdesk / wp-basic-requirements / src / Basic_Requirement_Checker.php
flexible-shipping / vendor_prefixed / wpdesk / wp-basic-requirements / src Last commit date
Basic_Requirement_Checker.php 1 week ago Basic_Requirement_Checker_Factory.php 1 week ago Basic_Requirement_Checker_With_Update_Disable.php 1 week ago Requirement_Checker.php 1 week ago Requirement_Checker_Factory.php 1 week ago
Basic_Requirement_Checker.php
631 lines
1 <?php
2
3 namespace FSVendor;
4
5 if (!\interface_exists('FSVendor\WPDesk_Requirement_Checker')) {
6 require_once __DIR__ . '/Requirement_Checker.php';
7 }
8 if (!\class_exists('FSVendor\WPDesk_Basic_Requirement_Checker')) {
9 /**
10 * Checks requirements for plugin
11 * have to be compatible with PHP 5.3.x
12 */
13 class WPDesk_Basic_Requirement_Checker implements WPDesk_Requirement_Checker
14 {
15 const EXTENSION_NAME_OPENSSL = 'openssl';
16 const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices';
17 const HOOK_PLUGIN_DEACTIVATED_ACTION = 'deactivated_plugin';
18 const HOOK_PLUGIN_ACTIVATED_ACTION = 'activated_plugin';
19 const PLUGIN_INFO_KEY_NICE_NAME = 'nice_name';
20 const PLUGIN_INFO_KEY_NAME = 'name';
21 const PLUGIN_INFO_VERSION = 'version';
22 const PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION = '0.0';
23 const PLUGIN_INFO_APPEND_PLUGIN_DATA = 'required_version';
24 const PLUGIN_INFO_TRANSIENT_NAME = 'wpdesk_requirements_plugins_data';
25 const CACHE_TIME = 16;
26 const EXPIRATION_TIME = 'expiration_time';
27 const PLUGINS = 'plugins';
28 /** @var string */
29 protected $plugin_name;
30 /** @var string */
31 private $plugin_file;
32 /** @var string */
33 private $min_php_version;
34 /** @var string */
35 private $min_wp_version;
36 /** @var string|null */
37 private $min_wc_version = null;
38 /** @var int|null */
39 private $min_openssl_version = null;
40 /** @var array */
41 protected $plugin_require;
42 /** @var array */
43 protected $class_require;
44 /** @var bool */
45 protected $should_check_plugin_versions = \false;
46 /** @var array */
47 private $module_require;
48 /** @var array */
49 private $setting_require;
50 /** @var array */
51 protected $notices;
52 /** @var @string */
53 private $text_domain;
54 /**
55 * @var mixed|true
56 */
57 private $use_transients;
58 /**
59 * @param string $plugin_file
60 * @param string $plugin_name
61 * @param string $text_domain
62 * @param string $php_version
63 * @param string $wp_version
64 * @param bool $use_transients
65 */
66 public function __construct($plugin_file, $plugin_name, $text_domain, $php_version, $wp_version, $use_transients = \true)
67 {
68 $this->plugin_file = $plugin_file;
69 $this->plugin_name = $plugin_name;
70 $this->text_domain = $text_domain;
71 $this->use_transients = $use_transients;
72 $this->set_min_php_require($php_version);
73 $this->set_min_wp_require($wp_version);
74 $this->plugin_require = array();
75 $this->module_require = array();
76 $this->setting_require = array();
77 $this->notices = array();
78 $this->class_require = array();
79 }
80 /**
81 * @param string $version
82 *
83 * @return $this
84 */
85 public function set_min_php_require($version)
86 {
87 $this->min_php_version = $version;
88 return $this;
89 }
90 /**
91 * @param string $version
92 *
93 * @return $this
94 */
95 public function set_min_wp_require($version)
96 {
97 $this->min_wp_version = $version;
98 return $this;
99 }
100 /**
101 * @param string $version
102 *
103 * @return $this
104 */
105 public function set_min_wc_require($version)
106 {
107 $this->min_wc_version = $version;
108 return $this;
109 }
110 /**
111 * @param $version
112 *
113 * @return $this
114 */
115 public function set_min_openssl_require($version)
116 {
117 $this->min_openssl_version = $version;
118 return $this;
119 }
120 /**
121 * @param string $plugin_name Name in wp format dir/file.php
122 * @param string $nice_plugin_name Nice plugin name for better looks in notice
123 * @param string $plugin_require_version required plugin minimum version
124 *
125 * @return $this
126 */
127 public function add_plugin_require($plugin_name, $nice_plugin_name = null, $plugin_require_version = null)
128 {
129 if ($plugin_require_version) {
130 $this->should_check_plugin_versions = \true;
131 }
132 $this->plugin_require[$plugin_name] = array(self::PLUGIN_INFO_KEY_NAME => $plugin_name, self::PLUGIN_INFO_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name, self::PLUGIN_INFO_VERSION => $plugin_require_version === null ? self::PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION : $plugin_require_version);
133 return $this;
134 }
135 /**
136 * Add plugin to require list. Plugin is from repository so we can ask for installation.
137 *
138 * @param string $plugin_name Name in wp format dir/file.php
139 * @param string $version Required version of the plugin.
140 * @param string $nice_plugin_name Nice plugin name for better looks in notice
141 *
142 * @return $this
143 */
144 public function add_plugin_repository_require($plugin_name, $version, $nice_plugin_name = null)
145 {
146 $this->plugin_require[$plugin_name] = array(self::PLUGIN_INFO_KEY_NAME => $plugin_name, self::PLUGIN_INFO_VERSION => $version, 'repository_url' => 'http://downloads.wordpress.org/plugin/' . \dirname($plugin_name) . '.latest-stable.zip', self::PLUGIN_INFO_KEY_NICE_NAME => $nice_plugin_name === null ? $plugin_name : $nice_plugin_name);
147 return $this;
148 }
149 /**
150 * Add a class to require list.
151 *
152 * @param string $class_name Name of the class.
153 * @param string $plugin_nice_name Nice plugin name for better looks in notice.
154 *
155 * @return $this
156 *
157 */
158 public function add_class_require($class_name, $plugin_nice_name)
159 {
160 $this->class_require[$class_name] = $plugin_nice_name;
161 return $this;
162 }
163 /**
164 * @param string $module_name
165 * @param string $nice_name Nice module name for better looks in notice
166 *
167 * @return $this
168 */
169 public function add_php_module_require($module_name, $nice_name = null)
170 {
171 if ($nice_name === null) {
172 $this->module_require[$module_name] = $module_name;
173 } else {
174 $this->module_require[$module_name] = $nice_name;
175 }
176 return $this;
177 }
178 /**
179 * @param string $setting
180 * @param mixed $value
181 *
182 * @return $this
183 */
184 public function add_php_setting_require($setting, $value)
185 {
186 $this->setting_require[$setting] = $value;
187 return $this;
188 }
189 /**
190 * Returns true if are requirements are met.
191 *
192 * @return bool
193 */
194 public function are_requirements_met()
195 {
196 $this->notices = $this->prepare_requirement_notices();
197 return \count($this->notices) === 0;
198 }
199 /**
200 * @return array
201 */
202 private function prepare_requirement_notices()
203 {
204 $notices = array();
205 if (!self::is_php_at_least($this->min_php_version)) {
206 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run on PHP versions older than %s. Please contact your host and ask them to upgrade.', 'flexible-shipping'), \esc_html($this->plugin_name), $this->min_php_version));
207 }
208 if (!self::is_wp_at_least($this->min_wp_version)) {
209 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run on WordPress versions older than %s. Please update WordPress.', 'flexible-shipping'), \esc_html($this->plugin_name), $this->min_wp_version));
210 }
211 if ($this->min_wc_version !== null && $this->can_check_plugin_version() && !self::is_wc_at_least($this->min_wc_version)) {
212 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run on WooCommerce versions older than %s. Please update WooCommerce.', 'flexible-shipping'), \esc_html($this->plugin_name), $this->min_wc_version));
213 }
214 if ($this->min_openssl_version !== null && !self::is_open_ssl_at_least($this->min_openssl_version)) {
215 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run without OpenSSL module version at least %s. Please update OpenSSL module.', 'flexible-shipping'), \esc_html($this->plugin_name), '0x' . \dechex($this->min_openssl_version)));
216 }
217 $notices = $this->append_plugin_require_notices($notices);
218 $notices = $this->append_module_require_notices($notices);
219 $notices = $this->append_settings_require_notices($notices);
220 $notices = $this->append_class_require_notices($notices);
221 if ($this->should_check_plugin_versions) {
222 $notices = $this->check_minimum_require_plugins_version_and_append_notices($notices);
223 }
224 return $notices;
225 }
226 /**
227 * @param $min_version
228 *
229 * @return mixed
230 */
231 public static function is_php_at_least($min_version)
232 {
233 return \version_compare(\PHP_VERSION, $min_version, '>=');
234 }
235 /**
236 * Prepares message in html format
237 *
238 * @param string $message
239 *
240 * @return string
241 */
242 protected function prepare_notice_message($message)
243 {
244 return '<div class="error"><p>' . $message . '</p></div>';
245 }
246 public function get_text_domain()
247 {
248 return $this->text_domain;
249 }
250 /**
251 * @param string $min_version
252 *
253 * @return bool
254 */
255 public static function is_wp_at_least($min_version)
256 {
257 $wp_version = \get_bloginfo('version');
258 if ($wp_version === null || $wp_version === '') {
259 return \false;
260 }
261 return \version_compare($wp_version, $min_version, '>=');
262 }
263 /**
264 * Are plugins loaded so we can check the version
265 *
266 * @return bool
267 */
268 private function can_check_plugin_version()
269 {
270 return \did_action('plugins_loaded') > 0;
271 }
272 /**
273 * Checks if plugin is active and have designated version. Needs to be enabled in deferred way.
274 *
275 * @param string $min_version
276 *
277 * @return bool
278 */
279 public static function is_wc_at_least($min_version)
280 {
281 if (!\defined('WC_VERSION') || \WC_VERSION === null || \WC_VERSION === '') {
282 return \false;
283 }
284 return \version_compare(\WC_VERSION, $min_version, '>=');
285 }
286 /**
287 * Checks if ssl version is valid
288 *
289 * @param int $required_version Version in hex. Version 9.6 is 0x000906000
290 *
291 * @return bool
292 * @see https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_VERSION_NUMBER.html
293 *
294 */
295 public static function is_open_ssl_at_least($required_version)
296 {
297 return \defined('OPENSSL_VERSION_NUMBER') && \OPENSSL_VERSION_NUMBER > (int) $required_version;
298 }
299 /**
300 * @param $notices array
301 *
302 * @return array
303 */
304 private function check_minimum_require_plugins_version_and_append_notices($notices)
305 {
306 $required_plugins = $this->retrieve_required_plugins_data();
307 if (\count($required_plugins) > 0) {
308 foreach ($required_plugins as $plugin) {
309 if (isset($plugin['Version']) && $plugin['Version'] !== null && $plugin['Version'] !== '' && \version_compare($plugin['Version'], $plugin[self::PLUGIN_INFO_APPEND_PLUGIN_DATA], '<')) {
310 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%1$s&#8221; plugin requires at least %2$s version of %3$s to work correctly. Please update it to its latest release.', 'flexible-shipping'), \esc_html($this->plugin_name), $plugin[self::PLUGIN_INFO_APPEND_PLUGIN_DATA], $plugin['Name']));
311 }
312 }
313 }
314 return $notices;
315 }
316 /**
317 * Check the plugins directory and retrieve all plugin files with plugin data.
318 *
319 * @param bool $use_transients
320 *
321 * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', ...], ]
322 */
323 private static function retrieve_plugins_data_in_transient($use_transients = \true)
324 {
325 $current_time = \time();
326 $plugins = self::get_plugins_data_from_cache($use_transients, $current_time);
327 if ($plugins === \false) {
328 static $never_executed = \true;
329 if ($never_executed) {
330 $never_executed = \false;
331 /** Required when WC starts later and these data should be in cache */
332 \add_filter('extra_plugin_headers', function ($headers = array()) {
333 $headers[] = 'WC tested up to';
334 $headers[] = 'WC requires at least';
335 $headers[] = 'Woo';
336 return \array_unique($headers);
337 });
338 }
339 if (!\function_exists('get_plugins') && !\function_exists('FSVendor\get_plugins')) {
340 require_once \ABSPATH . '/wp-admin/includes/plugin.php';
341 }
342 $plugins = \function_exists('get_plugins') ? \get_plugins() : array();
343 self::update_plugins_data_in_cache($plugins, $use_transients, $current_time);
344 }
345 return $plugins;
346 }
347 /**
348 * @param bool $use_transients
349 * @param int $current_time
350 *
351 * @return array|false
352 */
353 private static function get_plugins_data_from_cache($use_transients, $current_time)
354 {
355 if ($use_transients) {
356 return \get_transient(self::PLUGIN_INFO_TRANSIENT_NAME);
357 } else {
358 $plugins_option_value = \get_option(self::PLUGIN_INFO_TRANSIENT_NAME);
359 if (\is_array($plugins_option_value) && isset($plugins_option_value[self::EXPIRATION_TIME], $plugins_option_value[self::PLUGINS]) && (int) $plugins_option_value[self::EXPIRATION_TIME] > $current_time) {
360 return $plugins_option_value[self::PLUGINS];
361 }
362 }
363 return \false;
364 }
365 /**
366 * @param array $plugins
367 * @param bool $use_transients
368 * @param int $current_time
369 */
370 private static function update_plugins_data_in_cache($plugins, $use_transients, $current_time)
371 {
372 if ($use_transients) {
373 \set_transient(self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, self::CACHE_TIME);
374 } else {
375 \update_option(self::PLUGIN_INFO_TRANSIENT_NAME, array(self::EXPIRATION_TIME => $current_time + self::CACHE_TIME, self::PLUGINS => $plugins));
376 }
377 }
378 /**
379 * Check the plugins directory and retrieve all required plugin files with plugin data.
380 *
381 * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', 'required_version' => '1.0.2']... ]
382 */
383 private function retrieve_required_plugins_data()
384 {
385 $require_plugins = array();
386 $plugins = self::retrieve_plugins_data_in_transient($this->use_transients);
387 if (\is_array($plugins)) {
388 if (\count($plugins) > 0) {
389 if (!empty($this->plugin_require)) {
390 foreach ($this->plugin_require as $plugin) {
391 $plugin_file_name = $plugin[self::PLUGIN_INFO_KEY_NAME];
392 $plugin_version = $plugin[self::PLUGIN_INFO_VERSION];
393 if (self::is_wp_plugin_active($plugin_file_name)) {
394 $require_plugins[$plugin_file_name] = $plugins[$plugin_file_name];
395 $require_plugins[$plugin_file_name][self::PLUGIN_INFO_APPEND_PLUGIN_DATA] = $plugin_version;
396 }
397 }
398 }
399 }
400 }
401 return $require_plugins;
402 }
403 /**
404 * @param array $notices
405 *
406 * @return array
407 */
408 private function append_plugin_require_notices($notices)
409 {
410 if (\count($this->plugin_require) > 0) {
411 foreach ($this->plugin_require as $plugin_name => $plugin_info) {
412 $notice = null;
413 if (isset($plugin_info['repository_url'])) {
414 $notice = $this->prepare_plugin_repository_require_notice($plugin_info);
415 } elseif (!self::is_wp_plugin_active($plugin_name)) {
416 $notice = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run without %s active. Please install and activate %s plugin.', 'flexible-shipping'), \esc_html($this->plugin_name), \esc_html(\basename($plugin_info[self::PLUGIN_INFO_KEY_NICE_NAME])), \esc_html(\basename($plugin_info[self::PLUGIN_INFO_KEY_NICE_NAME]))));
417 }
418 if ($notice !== null) {
419 $notices[] = $notice;
420 }
421 }
422 }
423 return $notices;
424 }
425 /**
426 * @param array $notices
427 *
428 * @return array
429 */
430 private function append_class_require_notices($notices)
431 {
432 foreach ($this->class_require as $class_name => $plugin_nice_name) {
433 if (\class_exists($class_name)) {
434 continue;
435 }
436 $notices[] = $this->prepare_notice_message(\sprintf('The &#8220;%s&#8221; plugin cannot run without %s active. Please install and activate %s plugin.', \esc_html($this->plugin_name), \esc_html($plugin_nice_name), \esc_html($plugin_nice_name)));
437 }
438 return $notices;
439 }
440 /**
441 * Prepares WP install url and injects info about plugin to the WP update engine.
442 *
443 * @param array $plugin_info
444 *
445 * @return string
446 */
447 private function prepare_plugin_repository_install_url($plugin_info)
448 {
449 $slug = \basename(\explode('/', $plugin_info[self::PLUGIN_INFO_KEY_NAME])[0]);
450 $install_url = \self_admin_url('update.php?action=install-plugin&plugin=' . $slug);
451 if (\function_exists('wp_nonce_url') && \function_exists('wp_create_nonce')) {
452 $install_url = \wp_nonce_url($install_url, 'install-plugin_' . $slug);
453 }
454 return $install_url;
455 }
456 /**
457 * @param array $plugin_info Internal required plugin info data.
458 *
459 * @return string|null Return null if no notice is needed.
460 */
461 private function prepare_plugin_repository_require_notice($plugin_info)
462 {
463 $name = $plugin_info[self::PLUGIN_INFO_KEY_NAME];
464 $nice_name = $plugin_info[self::PLUGIN_INFO_KEY_NICE_NAME];
465 if (!self::is_wp_plugin_active($name)) {
466 if (!self::is_wp_plugin_installed($name, $this->use_transients)) {
467 $install_url = $this->prepare_plugin_repository_install_url($plugin_info);
468 return $this->prepare_notice_message(\sprintf(\wp_kses(\__('The &#8220;%s&#8221; plugin requires free %s plugin. <a href="%s">Install %s</a>', 'flexible-shipping'), array('a' => array('href' => array()))), $this->plugin_name, $nice_name, \esc_url($install_url), $nice_name));
469 }
470 $activate_url = 'plugins.php?action=activate&plugin=' . \urlencode($plugin_info[self::PLUGIN_INFO_KEY_NAME]) . '&plugin_status=all&paged=1&s';
471 if (\function_exists('wp_create_nonce')) {
472 $activate_url .= '&_wpnonce=' . \urlencode(\wp_create_nonce('activate-plugin_' . $name));
473 }
474 return $this->prepare_notice_message(\sprintf(\wp_kses(\__('The &#8220;%s&#8221; plugin requires activating %s plugin. <a href="%s">Activate %s</a>', 'flexible-shipping'), array('a' => array('href' => array()))), $this->plugin_name, $nice_name, \esc_url(\admin_url($activate_url)), $nice_name));
475 }
476 return null;
477 }
478 /**
479 * Checks if plugin is active. Needs to be used in deferred way.
480 *
481 * @param string $plugin_file
482 *
483 * @return bool
484 */
485 public static function is_wp_plugin_active($plugin_file)
486 {
487 $active_plugins = (array) \get_option('active_plugins', array());
488 if (\is_multisite()) {
489 $active_plugins = \array_merge($active_plugins, \get_site_option('active_sitewide_plugins', array()));
490 }
491 return \in_array($plugin_file, $active_plugins) || \array_key_exists($plugin_file, $active_plugins);
492 }
493 /**
494 * Checks if plugin is installed. Needs to be enabled in deferred way.
495 *
496 * @param string $plugin_file
497 * @param bool $use_transients
498 *
499 * @return bool
500 */
501 public static function is_wp_plugin_installed($plugin_file, $use_transients = \false)
502 {
503 $plugins_data = self::retrieve_plugins_data_in_transient($use_transients);
504 return \array_key_exists($plugin_file, (array) $plugins_data);
505 }
506 /**
507 * @param array $notices
508 *
509 * @return array
510 */
511 private function append_module_require_notices($notices)
512 {
513 if (\count($this->module_require) > 0) {
514 foreach ($this->module_require as $module_name => $nice_module_name) {
515 if (!self::is_module_active($module_name)) {
516 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run without %s PHP module installed. Please contact your host and ask them to install %s.', 'flexible-shipping'), \esc_html($this->plugin_name), \esc_html(\basename($nice_module_name)), \esc_html(\basename($nice_module_name))));
517 }
518 }
519 }
520 return $notices;
521 }
522 /**
523 * @param string $name
524 *
525 * @return bool
526 */
527 public static function is_module_active($name)
528 {
529 return \extension_loaded($name);
530 }
531 /**
532 * @param array $notices
533 *
534 * @return array
535 */
536 private function append_settings_require_notices($notices)
537 {
538 if (\count($this->setting_require) > 0) {
539 foreach ($this->setting_require as $setting => $value) {
540 if (!self::is_setting_set($setting, $value)) {
541 $notices[] = $this->prepare_notice_message(\sprintf(\__('The &#8220;%s&#8221; plugin cannot run without %s PHP setting set to %s. Please contact your host and ask them to set %s.', 'flexible-shipping'), \esc_html($this->plugin_name), \esc_html(\basename($setting)), \esc_html(\basename($value)), \esc_html(\basename($setting))));
542 }
543 }
544 }
545 return $notices;
546 }
547 /**
548 * @param string $name
549 * @param mixed $value
550 *
551 * @return bool
552 */
553 public static function is_setting_set($name, $value)
554 {
555 return \ini_get($name) === (string) $value;
556 }
557 /**
558 * @return void
559 *
560 * @deprecated use render_notices or disable_plugin
561 */
562 public function disable_plugin_render_notice()
563 {
564 \add_action(self::HOOK_ADMIN_NOTICES_ACTION, array($this, 'handle_render_notices_action'));
565 }
566 /**
567 * Renders requirement notices in admin panel
568 *
569 * @return void
570 */
571 public function render_notices()
572 {
573 \add_action(self::HOOK_ADMIN_NOTICES_ACTION, array($this, 'handle_render_notices_action'));
574 }
575 /**
576 * Renders requirement notices in admin panel
577 *
578 * @return void
579 */
580 public function disable_plugin()
581 {
582 \add_action(self::HOOK_ADMIN_NOTICES_ACTION, array($this, 'handle_deactivate_action'));
583 }
584 /**
585 * @return void
586 * @internal Do not use as public. Public only for wp action.
587 *
588 */
589 public function handle_deactivate_action()
590 {
591 if (isset($this->plugin_file)) {
592 \deactivate_plugins(\plugin_basename($this->plugin_file));
593 $this->clear_plugin_info_data();
594 }
595 }
596 /**
597 * Triggers the transient delete after plugin deactivated
598 *
599 * @return void
600 */
601 public function transient_delete_on_plugin_version_changed()
602 {
603 \add_action(self::HOOK_PLUGIN_DEACTIVATED_ACTION, array($this, 'clear_plugin_info_data'));
604 \add_action(self::HOOK_PLUGIN_ACTIVATED_ACTION, array($this, 'clear_plugin_info_data'));
605 }
606 /**
607 * Handles the transient delete
608 *
609 * @return void
610 */
611 public function clear_plugin_info_data()
612 {
613 \delete_transient(self::PLUGIN_INFO_TRANSIENT_NAME);
614 \delete_option(self::PLUGIN_INFO_TRANSIENT_NAME);
615 }
616 /**
617 * Should be called as WordPress action
618 *
619 * @return void
620 * @internal Do not use as public. Public only for wp action.
621 *
622 */
623 public function handle_render_notices_action()
624 {
625 foreach ($this->notices as $notice) {
626 echo \wp_kses_post($notice);
627 }
628 }
629 }
630 }
631