Passed
Push — master ( b3b37d...017091 )
by Daniel
03:43 queued 01:46
created

Algolia_Check_Requirements::is_woocommerce_plugin_active()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * Class for checking plugin requirements
4
 * Like checking PHP version, WordPress version and so on
5
 *
6
 * @package algolia-woo-indexer
7
 */
8
9
namespace Algowoo;
10
11
/**
12
 * Define minimum required versions of PHP and WordPress
13
 */
14
define('ALGOLIA_MIN_PHP_VERSION', '7.2');
15
define('ALGOLIA_MIN_WP_VERSION', '5.4');
16
17
/**
18
 * Abort if this file is called directly
19
 */
20
if (! defined('ABSPATH')) {
21
    exit;
22
}
23
24
if (! class_exists('Algolia_Check_Requirements')) {
25
    /**
26
     * Check requirements for Algolia plugin
27
     */
28
    class Algolia_Check_Requirements
29
    {
30
31
        /**
32
         * Check for required PHP version.
33
         *
34
         * @return bool
35
         */
36
        public static function algolia_php_version_check()
37
        {
38
            if (version_compare(PHP_VERSION, ALGOLIA_MIN_PHP_VERSION, '<')) {
39
                return false;
40
            }
41
            return true;
42
        }
43
44
        /**
45
         * Check for required WordPress version.
46
         *
47
         * @return bool
48
         */
49
        public static function algolia_wp_version_check()
50
        {
51
            if (version_compare($GLOBALS['wp_version'], ALGOLIA_MIN_WP_VERSION, '<')) {
52
                return false;
53
            }
54
            return true;
55
        }
56
57
        /**
58
         * Check that we have all of the required PHP extensions installed
59
         *
60
         * @return void
61
         */
62
        public static function check_unmet_requirements()
63
        {
64
            if (! extension_loaded('mbstring')) {
65
                echo '<div class="error notice">
66
					  <p>' . esc_html__('Algolia Woo Indexer requires the "mbstring" PHP extension to be enabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
67
				  </div>';
68
            } elseif (! function_exists('mb_ereg_replace')) {
69
                echo '<div class="error notice">
70
					  <p>' . esc_html__('Algolia Woo Indexer needs "mbregex" NOT to be disabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
71
				  </div>';
72
            }
73
            if (! extension_loaded('curl')) {
74
                echo '<div class="error notice">
75
					  <p>' . esc_html__('Algolia Woo Indexer requires the "cURL" PHP extension to be enabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
76
				  </div>';
77
                return;
78
            }
79
        }
80
	}
81
}
82