Passed
Push — master ( 6d02eb...4a4aa8 )
by Daniel
02:05 queued 11s
created

check_algolia_input_values()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 12
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 if values are empty and display error notice if not all values have been set
46
		 *
47
		 *  @param string $algolia_application_id Algolia application ID.
48
		 * 	@param string $algolia_api_key Algolia API key.
49
		 * 	@param string $algolia_index_name Algolia index name.
50
		 * 
51
		 */
52
		public static function check_algolia_input_values($algolia_application_id, $algolia_api_key, $algolia_index_name )
53
		{	
54
			if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) {
55
                add_action(
56
                    'admin_notices',
57
                    function () {
58
                        echo '<div class="error notice">
59
							  <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p>
60
							</div>';
61
                    }
62
                );
63
                return;
64
            }
65
        }
66
67
        /**
68
         * Check for required WordPress version.
69
         *
70
         * @return bool
71
         */
72
        public static function algolia_wp_version_check()
73
        {
74
            if (version_compare($GLOBALS['wp_version'], ALGOLIA_MIN_WP_VERSION, '<')) {
75
                return false;
76
            }
77
            return true;
78
        }
79
80
        /**
81
         * Check that we have all of the required PHP extensions installed
82
         *
83
         * @return void
84
         */
85
        public static function check_unmet_requirements()
86
        {
87
            if (! extension_loaded('mbstring')) {
88
                echo '<div class="error notice">
89
					  <p>' . esc_html__('Algolia Woo Indexer requires the "mbstring" PHP extension to be enabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
90
				  </div>';
91
            } elseif (! function_exists('mb_ereg_replace')) {
92
                echo '<div class="error notice">
93
					  <p>' . esc_html__('Algolia Woo Indexer needs "mbregex" NOT to be disabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
94
				  </div>';
95
            }
96
            if (! extension_loaded('curl')) {
97
                echo '<div class="error notice">
98
					  <p>' . esc_html__('Algolia Woo Indexer requires the "cURL" PHP extension to be enabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
99
				  </div>';
100
                return;
101
            }
102
        }
103
	}
104
}
105