Passed
Pull Request — master (#169)
by
unknown
02:05
created
uninstall.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@
 block discarded – undo
9 9
 /*
10 10
 *  If uninstall was not called from WordPress, then exit
11 11
 */
12
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
12
+if ( ! defined('WP_UNINSTALL_PLUGIN')) {
13 13
 	exit;
14 14
 }
15 15
 
16
-define( 'ALGOWOO_DB_OPTION', '_algolia_woo_indexer' );
16
+define('ALGOWOO_DB_OPTION', '_algolia_woo_indexer');
17 17
 
18
-delete_option( ALGOWOO_DB_OPTION . '_application_id' );
19
-delete_option( ALGOWOO_DB_OPTION . '_admin_api_key' );
20
-delete_option( ALGOWOO_DB_OPTION . '_index_name' );
21
-delete_option( ALGOWOO_DB_OPTION . '_index_in_stock' );
22
-delete_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' );
18
+delete_option(ALGOWOO_DB_OPTION . '_application_id');
19
+delete_option(ALGOWOO_DB_OPTION . '_admin_api_key');
20
+delete_option(ALGOWOO_DB_OPTION . '_index_name');
21
+delete_option(ALGOWOO_DB_OPTION . '_index_in_stock');
22
+delete_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products');
Please login to merge, or discard this patch.
classes/class-check-requirements.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Abort if this file is called directly
19 19
  */
20
-if (! defined('ABSPATH')) {
20
+if ( ! defined('ABSPATH')) {
21 21
     exit;
22 22
 }
23 23
 
24
-if (! class_exists('Algolia_Check_Requirements')) {
24
+if ( ! class_exists('Algolia_Check_Requirements')) {
25 25
     /**
26 26
      * Check requirements for Algolia plugin
27 27
      */
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
 		 * 	@param string $algolia_index_name Algolia index name.
50 50
 		 * 
51 51
 		 */
52
-		public static function check_algolia_input_values($algolia_application_id, $algolia_api_key, $algolia_index_name )
52
+		public static function check_algolia_input_values($algolia_application_id, $algolia_api_key, $algolia_index_name)
53 53
 		{	
54 54
 			if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) {
55 55
                 add_action(
56 56
                     'admin_notices',
57
-                    function () {
57
+                    function() {
58 58
                         echo '<div class="error notice">
59 59
 							  <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p>
60 60
 							</div>';
@@ -84,16 +84,16 @@  discard block
 block discarded – undo
84 84
          */
85 85
         public static function check_unmet_requirements()
86 86
         {
87
-            if (! extension_loaded('mbstring')) {
87
+            if ( ! extension_loaded('mbstring')) {
88 88
                 echo '<div class="error notice">
89 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 90
 				  </div>';
91
-            } elseif (! function_exists('mb_ereg_replace')) {
91
+            } elseif ( ! function_exists('mb_ereg_replace')) {
92 92
                 echo '<div class="error notice">
93 93
 					  <p>' . esc_html__('Algolia Woo Indexer needs "mbregex" NOT to be disabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
94 94
 				  </div>';
95 95
             }
96
-            if (! extension_loaded('curl')) {
96
+            if ( ! extension_loaded('curl')) {
97 97
                 echo '<div class="error notice">
98 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 99
 				  </div>';
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -18,28 +18,28 @@  discard block
 block discarded – undo
18 18
  * Abort if this file is called directly
19 19
  */
20 20
 if (! defined('ABSPATH')) {
21
-    exit;
21
+	exit;
22 22
 }
23 23
 
24 24
 if (! class_exists('Algolia_Check_Requirements')) {
25
-    /**
26
-     * Check requirements for Algolia plugin
27
-     */
28
-    class Algolia_Check_Requirements
29
-    {
25
+	/**
26
+	 * Check requirements for Algolia plugin
27
+	 */
28
+	class Algolia_Check_Requirements
29
+	{
30 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
-        }
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 43
 
44 44
 		/**
45 45
 		 * Check if values are empty and display error notice if not all values have been set
@@ -52,52 +52,52 @@  discard block
 block discarded – undo
52 52
 		public static function check_algolia_input_values($algolia_application_id, $algolia_api_key, $algolia_index_name )
53 53
 		{	
54 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">
55
+				add_action(
56
+					'admin_notices',
57
+					function () {
58
+						echo '<div class="error notice">
59 59
 							  <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p>
60 60
 							</div>';
61
-                    }
62
-                );    
63
-            }
64
-        }
61
+					}
62
+				);    
63
+			}
64
+		}
65 65
 
66
-        /**
67
-         * Check for required WordPress version.
68
-         *
69
-         * @return bool
70
-         */
71
-        public static function algolia_wp_version_check()
72
-        {
73
-            if (version_compare($GLOBALS['wp_version'], ALGOLIA_MIN_WP_VERSION, '<')) {
74
-                return false;
75
-            }
76
-            return true;
77
-        }
66
+		/**
67
+		 * Check for required WordPress version.
68
+		 *
69
+		 * @return bool
70
+		 */
71
+		public static function algolia_wp_version_check()
72
+		{
73
+			if (version_compare($GLOBALS['wp_version'], ALGOLIA_MIN_WP_VERSION, '<')) {
74
+				return false;
75
+			}
76
+			return true;
77
+		}
78 78
 
79
-        /**
80
-         * Check that we have all of the required PHP extensions installed
81
-         *
82
-         * @return void
83
-         */
84
-        public static function check_unmet_requirements()
85
-        {
86
-            if (! extension_loaded('mbstring')) {
87
-                echo '<div class="error notice">
79
+		/**
80
+		 * Check that we have all of the required PHP extensions installed
81
+		 *
82
+		 * @return void
83
+		 */
84
+		public static function check_unmet_requirements()
85
+		{
86
+			if (! extension_loaded('mbstring')) {
87
+				echo '<div class="error notice">
88 88
 					  <p>' . esc_html__('Algolia Woo Indexer requires the "mbstring" PHP extension to be enabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
89 89
 				  </div>';
90
-            } elseif (! function_exists('mb_ereg_replace')) {
91
-                echo '<div class="error notice">
90
+			} elseif (! function_exists('mb_ereg_replace')) {
91
+				echo '<div class="error notice">
92 92
 					  <p>' . esc_html__('Algolia Woo Indexer needs "mbregex" NOT to be disabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
93 93
 				  </div>';
94
-            }
95
-            if (! extension_loaded('curl')) {
96
-                echo '<div class="error notice">
94
+			}
95
+			if (! extension_loaded('curl')) {
96
+				echo '<div class="error notice">
97 97
 					  <p>' . esc_html__('Algolia Woo Indexer requires the "cURL" PHP extension to be enabled. Please contact your hosting provider.', 'algolia-woo-indexer') . '</p>
98 98
 				  </div>';
99
-                return;
100
-            }
101
-        }
99
+				return;
100
+			}
101
+		}
102 102
 	}
103 103
 }
Please login to merge, or discard this patch.
algolia-woo-indexer.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,31 +18,31 @@
 block discarded – undo
18 18
 /**
19 19
  * Abort if this file is called directly
20 20
  */
21
-if ( ! defined( 'ABSPATH' ) ) {
21
+if ( ! defined('ABSPATH')) {
22 22
 	exit;
23 23
 }
24 24
 
25 25
 /**
26 26
  * Main class file
27 27
  */
28
-require_once plugin_dir_path( __FILE__ ) . '/classes/class-algolia-woo-indexer.php';
28
+require_once plugin_dir_path(__FILE__) . '/classes/class-algolia-woo-indexer.php';
29 29
 
30 30
 /**
31 31
  * Class for checking plugin requirements
32 32
  */
33
-require_once plugin_dir_path( __FILE__ ) . '/classes/class-check-requirements.php';
33
+require_once plugin_dir_path(__FILE__) . '/classes/class-check-requirements.php';
34 34
 
35 35
 /**
36 36
  * Class for verifying nonces
37 37
  */
38
-require_once plugin_dir_path( __FILE__ ) . '/classes/class-verify-nonces.php';
38
+require_once plugin_dir_path(__FILE__) . '/classes/class-verify-nonces.php';
39 39
 
40 40
 /**
41 41
  * Class for sending products
42 42
  */
43
-require_once plugin_dir_path( __FILE__ ) . '/classes/class-send-products.php';
43
+require_once plugin_dir_path(__FILE__) . '/classes/class-send-products.php';
44 44
 
45 45
 $algowooindexer = \Algowoo\Algolia_Woo_Indexer::get_instance();
46 46
 
47
-register_activation_hook( __FILE__, array( $algowooindexer, 'activate_plugin' ) );
48
-register_deactivation_hook( __FILE__, array( $algowooindexer, 'deactivate_plugin' ) );
47
+register_activation_hook(__FILE__, array($algowooindexer, 'activate_plugin'));
48
+register_deactivation_hook(__FILE__, array($algowooindexer, 'deactivate_plugin'));
Please login to merge, or discard this patch.
classes/class-verify-nonces.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 /**
12 12
  * Abort if this file is called directly
13 13
  */
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
18
-if ( ! class_exists( 'Algolia_Verify_Nonces' ) ) {
18
+if ( ! class_exists('Algolia_Verify_Nonces')) {
19 19
 	/**
20 20
 	 * Verify submitted nonces
21 21
 	 */
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
 			/**
30 30
 			 * Filter incoming nonces and values
31 31
 			 */
32
-			$settings_nonce = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_nonce_name', FILTER_DEFAULT );
32
+			$settings_nonce = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_nonce_name', FILTER_DEFAULT);
33 33
 			
34 34
 			/**
35 35
 			 * Return boolean depending on if the nonce has been set
36 36
 			 */
37
-			return isset( $settings_nonce );
37
+			return isset($settings_nonce);
38 38
 
39 39
 		}
40 40
 
@@ -47,22 +47,22 @@  discard block
 block discarded – undo
47 47
 			/**
48 48
 			 * Filter incoming nonces and values
49 49
 			 */
50
-			$send_products_nonce      = filter_input( INPUT_POST, 'send_products_to_algolia_nonce_name', FILTER_DEFAULT );
51
-			$send_products_to_algolia = filter_input( INPUT_POST, 'send_products_to_algolia', FILTER_DEFAULT );
50
+			$send_products_nonce      = filter_input(INPUT_POST, 'send_products_to_algolia_nonce_name', FILTER_DEFAULT);
51
+			$send_products_to_algolia = filter_input(INPUT_POST, 'send_products_to_algolia', FILTER_DEFAULT);
52 52
 
53 53
 			/**
54 54
 			 * Display error and die if nonce is not verified and does not pass security check
55 55
 			 * Also check if the hidden value field send_products_to_algolia is set
56 56
 			 */
57 57
 
58
-			if ( ! wp_verify_nonce( $send_products_nonce, 'send_products_to_algolia_nonce_action' ) && isset( $send_products_to_algolia ) ) {
59
-				wp_die( esc_html__( 'Action is not allowed.', 'algolia-woo-indexer' ), esc_html__( 'Error!', 'algolia-woo-indexer' ) );
58
+			if ( ! wp_verify_nonce($send_products_nonce, 'send_products_to_algolia_nonce_action') && isset($send_products_to_algolia)) {
59
+				wp_die(esc_html__('Action is not allowed.', 'algolia-woo-indexer'), esc_html__('Error!', 'algolia-woo-indexer'));
60 60
 			}
61 61
 
62 62
 			/**
63 63
 			 * If we have verified the send_products_nonce and the send_products hidden field is set, return true
64 64
 			 */
65
-			if ( wp_verify_nonce( $send_products_nonce, 'send_products_to_algolia_nonce_action' ) && isset( $send_products_to_algolia ) ) {
65
+			if (wp_verify_nonce($send_products_nonce, 'send_products_to_algolia_nonce_action') && isset($send_products_to_algolia)) {
66 66
 				return true;
67 67
 			}
68 68
 		}
Please login to merge, or discard this patch.
classes/class-algolia-woo-indexer.php 2 patches
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -17,671 +17,671 @@  discard block
 block discarded – undo
17 17
  * Abort if this file is called directly
18 18
  */
19 19
 if (!defined('ABSPATH')) {
20
-    exit;
20
+	exit;
21 21
 }
22 22
 
23 23
 /**
24 24
  * Include plugin file if function is_plugin_active does not exist
25 25
  */
26 26
 if (!function_exists('is_plugin_active')) {
27
-    require_once(ABSPATH . '/wp-admin/includes/plugin.php');
27
+	require_once(ABSPATH . '/wp-admin/includes/plugin.php');
28 28
 }
29 29
 
30 30
 if (!class_exists('Algolia_Woo_Indexer')) {
31
-    /**
32
-     * Algolia WooIndexer main class
33
-     */
34
-    // TODO Rename class "Algolia_Woo_Indexer" to match the regular expression ^[A-Z][a-zA-Z0-9]*$.
35
-    class Algolia_Woo_Indexer
36
-    {
37
-        const PLUGIN_NAME      = 'Algolia Woo Indexer';
38
-        const PLUGIN_TRANSIENT = 'algowoo-plugin-notice';
39
-
40
-        /**
41
-         * Class instance
42
-         *
43
-         * @var object
44
-         */
45
-        private static $instance;
46
-
47
-        /**
48
-         * The plugin URL
49
-         *
50
-         * @var string
51
-         */
52
-        private static $plugin_url = '';
53
-
54
-        /**
55
-         * Class constructor
56
-         *
57
-         * @return void
58
-         */
59
-        public function __construct()
60
-        {
61
-            $this->init();
62
-        }
63
-
64
-        /**
65
-         * Setup sections and fields to store and retrieve values from Settings API
66
-         *
67
-         * @return void
68
-         */
69
-        public static function setup_settings_sections()
70
-        {
71
-            /**
72
-             * Setup arguments for settings sections and fields
73
-             *
74
-             * @see https://developer.wordpress.org/reference/functions/register_setting/
75
-             */
76
-            if (is_admin()) {
77
-                $arguments = array(
78
-                    'type'              => 'string',
79
-                    'sanitize_callback' => 'settings_fields_validate_options',
80
-                    'default'           => null,
81
-                );
82
-                register_setting('algolia_woo_options', 'algolia_woo_options', $arguments);
83
-
84
-                /**
85
-                 * Make sure we reference the instance of the current class by using self::get_instance()
86
-                 * This way we can setup the correct callback function for add_settings_section and add_settings_field
87
-                 */
88
-                $algowooindexer = self::get_instance();
89
-
90
-                /**
91
-                 * Add our necessary settings sections and fields
92
-                 */
93
-                add_settings_section(
94
-                    'algolia_woo_indexer_main',
95
-                    esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'),
96
-                    array($algowooindexer, 'algolia_woo_indexer_section_text'),
97
-                    'algolia_woo_indexer'
98
-                );
99
-                add_settings_field(
100
-                    'algolia_woo_indexer_application_id',
101
-                    esc_html__('Application ID', 'algolia-woo-indexer'),
102
-                    array($algowooindexer, 'algolia_woo_indexer_application_id_output'),
103
-                    'algolia_woo_indexer',
104
-                    'algolia_woo_indexer_main'
105
-                );
106
-                add_settings_field(
107
-                    'algolia_woo_indexer_admin_api_key',
108
-                    esc_html__('Admin API Key', 'algolia-woo-indexer'),
109
-                    array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'),
110
-                    'algolia_woo_indexer',
111
-                    'algolia_woo_indexer_main'
112
-                );
113
-                add_settings_field(
114
-                    'algolia_woo_indexer_index_name',
115
-                    esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'),
116
-                    array($algowooindexer, 'algolia_woo_indexer_index_name_output'),
117
-                    'algolia_woo_indexer',
118
-                    'algolia_woo_indexer_main'
119
-                );
120
-                add_settings_field(
121
-                    'algolia_woo_indexer_automatically_send_new_products',
122
-                    esc_html__('Automatically index new products', 'algolia-woo-indexer'),
123
-                    array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'),
124
-                    'algolia_woo_indexer',
125
-                    'algolia_woo_indexer_main'
126
-                );
127
-
128
-                /**
129
-                 * Add sections and fields for the basic fields
130
-                 */
131
-                add_settings_section(
132
-                    'algolia_woo_indexer_fields',
133
-                    esc_html__('Fields indexing settings', 'algolia-woo-indexer'),
134
-                    array($algowooindexer, 'algolia_woo_indexer_fields_section_text'),
135
-                    'algolia_woo_indexer'
136
-                );
137
-                foreach (BASIC_FIELDS as $field) {
138
-                    add_settings_field(
139
-                        'algolia_woo_indexer_field_' . $field,
140
-                        esc_html__($field, 'algolia-woo-indexer'),
141
-                        array($algowooindexer, 'algolia_woo_indexer_field_output'),
142
-                        'algolia_woo_indexer',
143
-                        'algolia_woo_indexer_fields',
144
-                        array(
145
-                            'label_for' => 'algolia_woo_indexer_field_' . $field,
146
-                            'name' => $field
147
-                        )
148
-                    );
149
-                }
150
-
151
-                /**
152
-                 * Add sections and fields for the attributes
153
-                 */
154
-                add_settings_section(
155
-                    'algolia_woo_indexer_attributes',
156
-                    esc_html__('Attributes indexing settings', 'algolia-woo-indexer'),
157
-                    array($algowooindexer, 'algolia_woo_indexer_attributes_section_text'),
158
-                    'algolia_woo_indexer'
159
-                );
160
-
161
-                foreach (ATTRIBUTES_SETTINGS as $key => $description) {
162
-                    add_settings_field(
163
-                        'algolia_woo_indexer_attributes_' . $key,
164
-                        esc_html__($description, 'algolia-woo-indexer'),
165
-                        array($algowooindexer, 'algolia_woo_indexer_attributes_' . $key . '_output'),
166
-                        'algolia_woo_indexer',
167
-                        'algolia_woo_indexer_attributes'
168
-                    );
169
-                }
170
-            }
171
-        }
172
-
173
-        /**
174
-         * Output for admin API key field
175
-         *
176
-         * @see https://developer.wordpress.org/reference/functions/wp_nonce_field/
177
-         *
178
-         * @return void
179
-         */
180
-        public static function algolia_woo_indexer_admin_api_key_output()
181
-        {
182
-            $api_key = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
183
-            $api_key = is_string($api_key) ? $api_key : CHANGE_ME;
184
-
185
-            wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name');
186
-
187
-            echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]'
31
+	/**
32
+	 * Algolia WooIndexer main class
33
+	 */
34
+	// TODO Rename class "Algolia_Woo_Indexer" to match the regular expression ^[A-Z][a-zA-Z0-9]*$.
35
+	class Algolia_Woo_Indexer
36
+	{
37
+		const PLUGIN_NAME      = 'Algolia Woo Indexer';
38
+		const PLUGIN_TRANSIENT = 'algowoo-plugin-notice';
39
+
40
+		/**
41
+		 * Class instance
42
+		 *
43
+		 * @var object
44
+		 */
45
+		private static $instance;
46
+
47
+		/**
48
+		 * The plugin URL
49
+		 *
50
+		 * @var string
51
+		 */
52
+		private static $plugin_url = '';
53
+
54
+		/**
55
+		 * Class constructor
56
+		 *
57
+		 * @return void
58
+		 */
59
+		public function __construct()
60
+		{
61
+			$this->init();
62
+		}
63
+
64
+		/**
65
+		 * Setup sections and fields to store and retrieve values from Settings API
66
+		 *
67
+		 * @return void
68
+		 */
69
+		public static function setup_settings_sections()
70
+		{
71
+			/**
72
+			 * Setup arguments for settings sections and fields
73
+			 *
74
+			 * @see https://developer.wordpress.org/reference/functions/register_setting/
75
+			 */
76
+			if (is_admin()) {
77
+				$arguments = array(
78
+					'type'              => 'string',
79
+					'sanitize_callback' => 'settings_fields_validate_options',
80
+					'default'           => null,
81
+				);
82
+				register_setting('algolia_woo_options', 'algolia_woo_options', $arguments);
83
+
84
+				/**
85
+				 * Make sure we reference the instance of the current class by using self::get_instance()
86
+				 * This way we can setup the correct callback function for add_settings_section and add_settings_field
87
+				 */
88
+				$algowooindexer = self::get_instance();
89
+
90
+				/**
91
+				 * Add our necessary settings sections and fields
92
+				 */
93
+				add_settings_section(
94
+					'algolia_woo_indexer_main',
95
+					esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'),
96
+					array($algowooindexer, 'algolia_woo_indexer_section_text'),
97
+					'algolia_woo_indexer'
98
+				);
99
+				add_settings_field(
100
+					'algolia_woo_indexer_application_id',
101
+					esc_html__('Application ID', 'algolia-woo-indexer'),
102
+					array($algowooindexer, 'algolia_woo_indexer_application_id_output'),
103
+					'algolia_woo_indexer',
104
+					'algolia_woo_indexer_main'
105
+				);
106
+				add_settings_field(
107
+					'algolia_woo_indexer_admin_api_key',
108
+					esc_html__('Admin API Key', 'algolia-woo-indexer'),
109
+					array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'),
110
+					'algolia_woo_indexer',
111
+					'algolia_woo_indexer_main'
112
+				);
113
+				add_settings_field(
114
+					'algolia_woo_indexer_index_name',
115
+					esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'),
116
+					array($algowooindexer, 'algolia_woo_indexer_index_name_output'),
117
+					'algolia_woo_indexer',
118
+					'algolia_woo_indexer_main'
119
+				);
120
+				add_settings_field(
121
+					'algolia_woo_indexer_automatically_send_new_products',
122
+					esc_html__('Automatically index new products', 'algolia-woo-indexer'),
123
+					array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'),
124
+					'algolia_woo_indexer',
125
+					'algolia_woo_indexer_main'
126
+				);
127
+
128
+				/**
129
+				 * Add sections and fields for the basic fields
130
+				 */
131
+				add_settings_section(
132
+					'algolia_woo_indexer_fields',
133
+					esc_html__('Fields indexing settings', 'algolia-woo-indexer'),
134
+					array($algowooindexer, 'algolia_woo_indexer_fields_section_text'),
135
+					'algolia_woo_indexer'
136
+				);
137
+				foreach (BASIC_FIELDS as $field) {
138
+					add_settings_field(
139
+						'algolia_woo_indexer_field_' . $field,
140
+						esc_html__($field, 'algolia-woo-indexer'),
141
+						array($algowooindexer, 'algolia_woo_indexer_field_output'),
142
+						'algolia_woo_indexer',
143
+						'algolia_woo_indexer_fields',
144
+						array(
145
+							'label_for' => 'algolia_woo_indexer_field_' . $field,
146
+							'name' => $field
147
+						)
148
+					);
149
+				}
150
+
151
+				/**
152
+				 * Add sections and fields for the attributes
153
+				 */
154
+				add_settings_section(
155
+					'algolia_woo_indexer_attributes',
156
+					esc_html__('Attributes indexing settings', 'algolia-woo-indexer'),
157
+					array($algowooindexer, 'algolia_woo_indexer_attributes_section_text'),
158
+					'algolia_woo_indexer'
159
+				);
160
+
161
+				foreach (ATTRIBUTES_SETTINGS as $key => $description) {
162
+					add_settings_field(
163
+						'algolia_woo_indexer_attributes_' . $key,
164
+						esc_html__($description, 'algolia-woo-indexer'),
165
+						array($algowooindexer, 'algolia_woo_indexer_attributes_' . $key . '_output'),
166
+						'algolia_woo_indexer',
167
+						'algolia_woo_indexer_attributes'
168
+					);
169
+				}
170
+			}
171
+		}
172
+
173
+		/**
174
+		 * Output for admin API key field
175
+		 *
176
+		 * @see https://developer.wordpress.org/reference/functions/wp_nonce_field/
177
+		 *
178
+		 * @return void
179
+		 */
180
+		public static function algolia_woo_indexer_admin_api_key_output()
181
+		{
182
+			$api_key = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
183
+			$api_key = is_string($api_key) ? $api_key : CHANGE_ME;
184
+
185
+			wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name');
186
+
187
+			echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]'
188 188
 				type='text' value='" . esc_attr($api_key) . "' />";
189
-        }
190
-
191
-        /**
192
-         * Output for application ID field
193
-         *
194
-         * @return void
195
-         */
196
-        public static function algolia_woo_indexer_application_id_output()
197
-        {
198
-            $application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APP_ID);
199
-            $application_id = is_string($application_id) ? $application_id : CHANGE_ME;
200
-
201
-            echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]'
189
+		}
190
+
191
+		/**
192
+		 * Output for application ID field
193
+		 *
194
+		 * @return void
195
+		 */
196
+		public static function algolia_woo_indexer_application_id_output()
197
+		{
198
+			$application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APP_ID);
199
+			$application_id = is_string($application_id) ? $application_id : CHANGE_ME;
200
+
201
+			echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]'
202 202
 				type='text' value='" . esc_attr($application_id) . "' />";
203
-        }
204
-
205
-        /**
206
-         * Output for index name field
207
-         *
208
-         * @return void
209
-         */
210
-        public static function algolia_woo_indexer_index_name_output()
211
-        {
212
-            $index_name = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
213
-            $index_name = is_string($index_name) ? $index_name : CHANGE_ME;
214
-
215
-            echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]'
203
+		}
204
+
205
+		/**
206
+		 * Output for index name field
207
+		 *
208
+		 * @return void
209
+		 */
210
+		public static function algolia_woo_indexer_index_name_output()
211
+		{
212
+			$index_name = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
213
+			$index_name = is_string($index_name) ? $index_name : CHANGE_ME;
214
+
215
+			echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]'
216 216
 				type='text' value='" . esc_attr($index_name) . "' />";
217
-        }
218
-
219
-        /**
220
-         * Output for checkbox to check if we automatically send new products to Algolia
221
-         *
222
-         * @return void
223
-         */
224
-        public static function algolia_woo_indexer_automatically_send_new_products_output()
225
-        {
226
-            /**
227
-             * Sanitization is not really needed as the variable is not directly echoed
228
-             * But I have still done it to be 100% safe
229
-             */
230
-            $auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
231
-            $auto_send = (!empty($auto_send)) ? 1 : 0; ?>
217
+		}
218
+
219
+		/**
220
+		 * Output for checkbox to check if we automatically send new products to Algolia
221
+		 *
222
+		 * @return void
223
+		 */
224
+		public static function algolia_woo_indexer_automatically_send_new_products_output()
225
+		{
226
+			/**
227
+			 * Sanitization is not really needed as the variable is not directly echoed
228
+			 * But I have still done it to be 100% safe
229
+			 */
230
+			$auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
231
+			$auto_send = (!empty($auto_send)) ? 1 : 0; ?>
232 232
             <input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]" type="checkbox" <?php checked(1, $auto_send); ?> />
233 233
         <?php
234
-        }
235
-
236
-        /**
237
-         * Output for fields which data shall be sent to Algolia
238
-         *
239
-         * @return void
240
-         */
241
-        public static function algolia_woo_indexer_field_output($args)
242
-        {
243
-            $value = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $args["name"]);
244
-            $isChecked = (!empty($value)) ? 1 : 0;
245
-        ?>
234
+		}
235
+
236
+		/**
237
+		 * Output for fields which data shall be sent to Algolia
238
+		 *
239
+		 * @return void
240
+		 */
241
+		public static function algolia_woo_indexer_field_output($args)
242
+		{
243
+			$value = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $args["name"]);
244
+			$isChecked = (!empty($value)) ? 1 : 0;
245
+		?>
246 246
             <input id="<?php echo $args["label_for"] ?>" name="<?php echo $args["label_for"] ?>[checked]" type="checkbox" <?php checked(1, $isChecked); ?> />
247 247
         <?php
248
-        }
249
-
250
-        /**
251
-         * Output for attributes if functionality is enabled
252
-         *
253
-         * @return void
254
-         */
255
-        public static function algolia_woo_indexer_attributes_enabled_output()
256
-        {
257
-            $value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
258
-            $isChecked = (!empty($value)) ? 1 : 0;
259
-        ?>
248
+		}
249
+
250
+		/**
251
+		 * Output for attributes if functionality is enabled
252
+		 *
253
+		 * @return void
254
+		 */
255
+		public static function algolia_woo_indexer_attributes_enabled_output()
256
+		{
257
+			$value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
258
+			$isChecked = (!empty($value)) ? 1 : 0;
259
+		?>
260 260
             <input id="algolia_woo_indexer_attributes_enabled" name="algolia_woo_indexer_attributes_enabled[checked]" type="checkbox" <?php checked(1, $isChecked); ?> />
261 261
             <?php
262
-        }
263
-
264
-        /**
265
-         * Output for attributes how to handle visibility setting
266
-         *
267
-         * @return void
268
-         */
269
-        public static function algolia_woo_indexer_attributes_visibility_output()
270
-        {
271
-            $value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY);
272
-            foreach (ATTRIBUTES_VISIBILITY_STATES as $state) {
273
-                $id = 'algolia_woo_indexer_attributes_visibility_' . $state;
274
-            ?>
262
+		}
263
+
264
+		/**
265
+		 * Output for attributes how to handle visibility setting
266
+		 *
267
+		 * @return void
268
+		 */
269
+		public static function algolia_woo_indexer_attributes_visibility_output()
270
+		{
271
+			$value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY);
272
+			foreach (ATTRIBUTES_VISIBILITY_STATES as $state) {
273
+				$id = 'algolia_woo_indexer_attributes_visibility_' . $state;
274
+			?>
275 275
                 <p><input id="<?php echo $id; ?>" name="algolia_woo_indexer_attributes_visibility[value]" type="radio" value="<?php echo $state; ?>" <?php checked($state, $value); ?> /><label for="<?php echo $id; ?>"><?php echo esc_html__($state, 'algolia-woo-indexer'); ?></label></p>
276 276
             <?php
277
-            }
278
-        }
279
-
280
-        /**
281
-         * Output for attributes how to handle variant setting
282
-         *
283
-         * @return void
284
-         */
285
-        public static function algolia_woo_indexer_attributes_variation_output()
286
-        {
287
-            $value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION);
288
-            foreach (ATTRIBUTES_VARIATION_STATES as $state) {
289
-                $id = 'algolia_woo_indexer_attributes_variation_' . $state;
290
-            ?>
277
+			}
278
+		}
279
+
280
+		/**
281
+		 * Output for attributes how to handle variant setting
282
+		 *
283
+		 * @return void
284
+		 */
285
+		public static function algolia_woo_indexer_attributes_variation_output()
286
+		{
287
+			$value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION);
288
+			foreach (ATTRIBUTES_VARIATION_STATES as $state) {
289
+				$id = 'algolia_woo_indexer_attributes_variation_' . $state;
290
+			?>
291 291
                 <p><input id="<?php echo $id; ?>" name="algolia_woo_indexer_attributes_variation[value]" type="radio" value="<?php echo $state; ?>" <?php checked($state, $value); ?> /><label for="<?php echo $id; ?>"><?php echo esc_html__($state, 'algolia-woo-indexer'); ?></label></p>
292 292
             <?php
293
-            }
294
-        }
295
-
296
-        /**
297
-         * Output for attributes list which attributes are whitelisted
298
-         *
299
-         * @return void
300
-         */
301
-        public static function algolia_woo_indexer_attributes_list_output()
302
-        {
303
-            $value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_LIST);
304
-            $selectedIds = explode(",", $value);
305
-            $name = "algolia_woo_indexer_attributes_list[list]";
306
-            $description = __('Here you can whitelist all the attributes. Use the <b>shift</b> or <b>control</b> buttons to select multiple attributes.', 'algolia-woo-indexer');
307
-            self::generic_attributes_select_output($name, $selectedIds, $description);
308
-        }
309
-
310
-        /**
311
-         * Output for attributes list which are using a numeric interpolation
312
-         *
313
-         * @return void
314
-         */
315
-        public static function algolia_woo_indexer_attributes_interp_output()
316
-        {
317
-            $value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
318
-            $selectedIds = explode(",", $value);
319
-            $name = "algolia_woo_indexer_attributes_interp[list]";
320
-            $description = __('If you have some attributes based on number which shall be interpd between the lowest to the highest number, you can select it here. A common usecase for this is if you want to have a <b>range slider</b> in aloglia which works for a certain range. Example: a plant grows between 20 and 25cm tall. for this you enter 20 and 25 as attribute values to your product and it will automatically extend the data to [20,21,22,23,24,25]', 'algolia-woo-indexer');
321
-            self::generic_attributes_select_output($name, $selectedIds, $description);
322
-        }
323
-
324
-        /**
325
-         * Generic Output for attributes list where attributes are whitelisted
326
-         *
327
-         * @return void
328
-         */
329
-        public static function generic_attributes_select_output($name, $selectedIds, $description)
330
-        {
331
-            $attribute_taxonomies = wc_get_attribute_taxonomies();
332
-
333
-            if (!$attribute_taxonomies) {
334
-                echo esc_html__('You don\'t have any attributes defined yet. Go to WooCommerce and add some to use this feature.', 'algolia-woo-indexer');
335
-                return;
336
-            }
337
-            ?>
293
+			}
294
+		}
295
+
296
+		/**
297
+		 * Output for attributes list which attributes are whitelisted
298
+		 *
299
+		 * @return void
300
+		 */
301
+		public static function algolia_woo_indexer_attributes_list_output()
302
+		{
303
+			$value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_LIST);
304
+			$selectedIds = explode(",", $value);
305
+			$name = "algolia_woo_indexer_attributes_list[list]";
306
+			$description = __('Here you can whitelist all the attributes. Use the <b>shift</b> or <b>control</b> buttons to select multiple attributes.', 'algolia-woo-indexer');
307
+			self::generic_attributes_select_output($name, $selectedIds, $description);
308
+		}
309
+
310
+		/**
311
+		 * Output for attributes list which are using a numeric interpolation
312
+		 *
313
+		 * @return void
314
+		 */
315
+		public static function algolia_woo_indexer_attributes_interp_output()
316
+		{
317
+			$value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
318
+			$selectedIds = explode(",", $value);
319
+			$name = "algolia_woo_indexer_attributes_interp[list]";
320
+			$description = __('If you have some attributes based on number which shall be interpd between the lowest to the highest number, you can select it here. A common usecase for this is if you want to have a <b>range slider</b> in aloglia which works for a certain range. Example: a plant grows between 20 and 25cm tall. for this you enter 20 and 25 as attribute values to your product and it will automatically extend the data to [20,21,22,23,24,25]', 'algolia-woo-indexer');
321
+			self::generic_attributes_select_output($name, $selectedIds, $description);
322
+		}
323
+
324
+		/**
325
+		 * Generic Output for attributes list where attributes are whitelisted
326
+		 *
327
+		 * @return void
328
+		 */
329
+		public static function generic_attributes_select_output($name, $selectedIds, $description)
330
+		{
331
+			$attribute_taxonomies = wc_get_attribute_taxonomies();
332
+
333
+			if (!$attribute_taxonomies) {
334
+				echo esc_html__('You don\'t have any attributes defined yet. Go to WooCommerce and add some to use this feature.', 'algolia-woo-indexer');
335
+				return;
336
+			}
337
+			?>
338 338
             <p><?php echo $description; ?></p>
339 339
             <select multiple="multiple" name="<?php echo $name; ?>[]" size="<?php echo count($attribute_taxonomies); ?>">
340 340
                 <?php
341
-                foreach ($attribute_taxonomies as $tax) {
341
+				foreach ($attribute_taxonomies as $tax) {
342 342
 
343
-                    $id = $tax->attribute_id;
344
-                    $label = $tax->attribute_label;
345
-                    $name = $tax->attribute_name;
346
-                    $selected = in_array($id, $selectedIds) ? ' selected="selected" ' : '';
347
-                ?>
343
+					$id = $tax->attribute_id;
344
+					$label = $tax->attribute_label;
345
+					$name = $tax->attribute_name;
346
+					$selected = in_array($id, $selectedIds) ? ' selected="selected" ' : '';
347
+				?>
348 348
                     <option value="<?php echo $id; ?>" <?php echo $selected; ?>>
349 349
                         <?php echo $label . ' (' . $name . ')'; ?>
350 350
                     </option>
351 351
                 <?php
352
-                }
353
-                ?>
352
+				}
353
+				?>
354 354
             </select>
355 355
         <?php
356 356
 
357
-        }
358
-
359
-        /**
360
-         * Section text for plugin settings section text
361
-         *
362
-         * @return void
363
-         */
364
-        public static function algolia_woo_indexer_section_text()
365
-        {
366
-            echo esc_html__('Enter your API settings here.', 'algolia-woo-indexer');
367
-        }
368
-
369
-        /**
370
-         * Section text for basic fields settings section text
371
-         *
372
-         * @return void
373
-         */
374
-        public static function algolia_woo_indexer_fields_section_text()
375
-        {
376
-            echo esc_html__('Choose which basic fields shall be indexed.', 'algolia-woo-indexer');
377
-        }
378
-
379
-        /**
380
-         * Section text for attributes settings section text
381
-         *
382
-         * @return void
383
-         */
384
-        public static function algolia_woo_indexer_attributes_section_text()
385
-        {
386
-            echo esc_html__('Control if and how the attributes shall be indexed.', 'algolia-woo-indexer');
387
-        }
388
-
389
-        /**
390
-         * Check if we are going to send products by verifying send products nonce
391
-         *
392
-         * @return void
393
-         */
394
-        public static function maybe_send_products()
395
-        {
396
-            if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) {
397
-                Algolia_Send_Products::send_products_to_algolia();
398
-            }
399
-        }
400
-
401
-        /**
402
-         * Initialize class, setup settings sections and fields
403
-         *
404
-         * @return void
405
-         */
406
-        public static function init()
407
-        {
408
-            /**
409
-             * Fetch the option to see if we are going to automatically send new products
410
-             */
411
-            $auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
412
-
413
-            /**
414
-             * Check that we have the minimum versions required and all of the required PHP extensions
415
-             */
416
-            Algolia_Check_Requirements::check_unmet_requirements();
417
-
418
-            if (!Algolia_Check_Requirements::algolia_wp_version_check() || !Algolia_Check_Requirements::algolia_php_version_check()) {
419
-                add_action(
420
-                    'admin_notices',
421
-                    function () {
422
-                        echo '<div class="error notice">
357
+		}
358
+
359
+		/**
360
+		 * Section text for plugin settings section text
361
+		 *
362
+		 * @return void
363
+		 */
364
+		public static function algolia_woo_indexer_section_text()
365
+		{
366
+			echo esc_html__('Enter your API settings here.', 'algolia-woo-indexer');
367
+		}
368
+
369
+		/**
370
+		 * Section text for basic fields settings section text
371
+		 *
372
+		 * @return void
373
+		 */
374
+		public static function algolia_woo_indexer_fields_section_text()
375
+		{
376
+			echo esc_html__('Choose which basic fields shall be indexed.', 'algolia-woo-indexer');
377
+		}
378
+
379
+		/**
380
+		 * Section text for attributes settings section text
381
+		 *
382
+		 * @return void
383
+		 */
384
+		public static function algolia_woo_indexer_attributes_section_text()
385
+		{
386
+			echo esc_html__('Control if and how the attributes shall be indexed.', 'algolia-woo-indexer');
387
+		}
388
+
389
+		/**
390
+		 * Check if we are going to send products by verifying send products nonce
391
+		 *
392
+		 * @return void
393
+		 */
394
+		public static function maybe_send_products()
395
+		{
396
+			if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) {
397
+				Algolia_Send_Products::send_products_to_algolia();
398
+			}
399
+		}
400
+
401
+		/**
402
+		 * Initialize class, setup settings sections and fields
403
+		 *
404
+		 * @return void
405
+		 */
406
+		public static function init()
407
+		{
408
+			/**
409
+			 * Fetch the option to see if we are going to automatically send new products
410
+			 */
411
+			$auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
412
+
413
+			/**
414
+			 * Check that we have the minimum versions required and all of the required PHP extensions
415
+			 */
416
+			Algolia_Check_Requirements::check_unmet_requirements();
417
+
418
+			if (!Algolia_Check_Requirements::algolia_wp_version_check() || !Algolia_Check_Requirements::algolia_php_version_check()) {
419
+				add_action(
420
+					'admin_notices',
421
+					function () {
422
+						echo '<div class="error notice">
423 423
                                   <p>' . esc_html__('Please check the server requirements for Algolia Woo Indexer. <br/> It requires minimum PHP version 7.2 and WordPress version 5.0', 'algolia-woo-indexer') . '</p>
424 424
                                 </div>';
425
-                    }
426
-                );
427
-            }
428
-
429
-            $ob_class = get_called_class();
430
-
431
-            /**
432
-             * Setup translations
433
-             */
434
-            add_action('plugins_loaded', array($ob_class, 'load_textdomain'));
435
-
436
-            /**
437
-             * Add actions to setup admin menu
438
-             */
439
-            if (is_admin()) {
440
-                add_action('admin_menu', array($ob_class, 'admin_menu'));
441
-                add_action('admin_init', array($ob_class, 'setup_settings_sections'));
442
-                add_action('admin_init', array($ob_class, 'update_settings_options'));
443
-                add_action('admin_init', array($ob_class, 'maybe_send_products'));
444
-
445
-                /**
446
-                 * Register hook to automatically send new products if the option is set
447
-                 */
448
-
449
-                if ('1' === $auto_send) {
450
-                    add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3);
451
-                }
452
-
453
-                self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings');
454
-
455
-                if (!is_plugin_active('woocommerce/woocommerce.php')) {
456
-                    add_action(
457
-                        'admin_notices',
458
-                        function () {
459
-                            echo '<div class="error notice">
425
+					}
426
+				);
427
+			}
428
+
429
+			$ob_class = get_called_class();
430
+
431
+			/**
432
+			 * Setup translations
433
+			 */
434
+			add_action('plugins_loaded', array($ob_class, 'load_textdomain'));
435
+
436
+			/**
437
+			 * Add actions to setup admin menu
438
+			 */
439
+			if (is_admin()) {
440
+				add_action('admin_menu', array($ob_class, 'admin_menu'));
441
+				add_action('admin_init', array($ob_class, 'setup_settings_sections'));
442
+				add_action('admin_init', array($ob_class, 'update_settings_options'));
443
+				add_action('admin_init', array($ob_class, 'maybe_send_products'));
444
+
445
+				/**
446
+				 * Register hook to automatically send new products if the option is set
447
+				 */
448
+
449
+				if ('1' === $auto_send) {
450
+					add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3);
451
+				}
452
+
453
+				self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings');
454
+
455
+				if (!is_plugin_active('woocommerce/woocommerce.php')) {
456
+					add_action(
457
+						'admin_notices',
458
+						function () {
459
+							echo '<div class="error notice">
460 460
 								  <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p>
461 461
 								</div>';
462
-                        }
463
-                    );
464
-                }
465
-            }
466
-        }
467
-
468
-        /**
469
-         * Send a single product to Algolia once a new product has been published
470
-         *
471
-         * @param int   $post_id ID of the product.
472
-         * @param array $post Post array.
473
-         *
474
-         * @return void
475
-         */
476
-        public static function send_new_product_to_algolia($post_id, $post)
477
-        {
478
-            if ('publish' !== $post->post_status || 'product' !== $post->post_type) {
479
-                return;
480
-            }
481
-            Algolia_Send_Products::send_products_to_algolia($post_id);
482
-        }
483
-
484
-        /**
485
-         * Verify nonces before we update options and settings
486
-         * Also retrieve the value from the send_products_to_algolia hidden field to check if we are sending products to Algolia
487
-         *
488
-         * @return void
489
-         */
490
-        public static function update_settings_options()
491
-        {
492
-            /**
493
-             * Do not proceed if nonce for settings is not set
494
-             */
495
-            if (false === Algolia_Verify_Nonces::verify_settings_nonce()) {
496
-                return;
497
-            }
498
-
499
-            /**
500
-             * Do not proceed if we are going to send products
501
-             */
502
-            if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) {
503
-                return;
504
-            }
505
-
506
-            /**
507
-             * Filter the application id, api key, index name and verify that the input is an array
508
-             *
509
-             * @see https://www.php.net/manual/en/function.filter-input.php
510
-             */
511
-            $post_application_id             = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
512
-            $post_api_key                    = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
513
-            $post_index_name                 = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
514
-            $auto_send                       = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
515
-            $attributes_enabled              = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_enabled', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
516
-            $attributes_visibility           = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_visibility', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
517
-            $attributes_variation            = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_variation', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
518
-            $attributes_list                 = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_list', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
519
-            $attributes_interp               = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_interp', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
520
-
521
-            /**
522
-             * Properly sanitize text fields before updating data
523
-             *
524
-             * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/
525
-             */
526
-            $sanitized = array();
527
-            $sanitized['app_id']                    = sanitize_text_field($post_application_id['id']);
528
-            $sanitized['api_key']                   = sanitize_text_field($post_api_key['key']);
529
-            $sanitized['index_name']                = sanitize_text_field($post_index_name['name']);
530
-            $sanitized['attributes_visibility']     = sanitize_text_field($attributes_visibility['value']);
531
-            $sanitized['attributes_variation']      = sanitize_text_field($attributes_variation['value']);
532
-
533
-            /**
534
-             * sanitize select list of id's by getting integers and them implode seperated with comma
535
-             */
536
-
537
-            $attributes_list_integers = [];
538
-            foreach ($attributes_list['list'] as $id) {
539
-                array_push($attributes_list_integers, (int) $id);
540
-            }
541
-            $sanitized['attributes_list'] = implode(',', $attributes_list_integers);
542
-            $attributes_interp_int = [];
543
-            foreach ($attributes_interp['list'] as $id) {
544
-                array_push($attributes_interp_int, (int) $id);
545
-            }
546
-            $sanitized['attributes_interp'] = implode(',', $attributes_interp_int);
547
-
548
-            /**
549
-             * Sanitizing by setting the value to either 1 or 0
550
-             */
551
-            $sanitized['product'] = (!empty($auto_send)) ? 1 : 0;
552
-            $sanitized['attributes_enabled'] = (!empty($attributes_enabled)) ? 1 : 0;
553
-
554
-            /**
555
-             * Filter the data fields checkboxes and verify that the input is an array and assign it to an associative array
556
-             *
557
-             * @see https://www.php.net/manual/en/function.filter-input.php
558
-             */
559
-            $sanitized['fields'] = array();
560
-            foreach (BASIC_FIELDS as $field) {
561
-                $raw_field = filter_input(INPUT_POST, 'algolia_woo_indexer_field_' . $field, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
562
-                $filtered_field = (!empty($raw_field)) ? 1 : 0;
563
-                $sanitized['fields'][$field] = $filtered_field;
564
-            }
565
-
566
-            /**
567
-             * Values have been filtered and sanitized
568
-             * Check if set and not empty and update the database
569
-             *
570
-             * @see https://developer.wordpress.org/reference/functions/update_option/
571
-             */
572
-            if (isset($sanitized['app_id']) && (!empty($sanitized['app_id']))) {
573
-                update_option(
574
-                    ALGOWOO_DB_OPTION . ALGOLIA_APP_ID,
575
-                    $sanitized['app_id']
576
-                );
577
-            }
578
-
579
-            if (isset($sanitized['api_key']) && (!empty($sanitized['api_key']))) {
580
-                update_option(
581
-                    ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
582
-                    $sanitized['api_key']
583
-                );
584
-            }
585
-
586
-            if (isset($sanitized['index_name']) && (!empty($sanitized['index_name']))) {
587
-                update_option(
588
-                    ALGOWOO_DB_OPTION . INDEX_NAME,
589
-                    $sanitized['index_name']
590
-                );
591
-            }
592
-
593
-            if (isset($sanitized['product'])) {
594
-                update_option(
595
-                    ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS,
596
-                    $sanitized['product']
597
-                );
598
-            }
599
-
600
-            foreach (array_keys(ATTRIBUTES_SETTINGS) as $key) {
601
-                $value = $sanitized['attributes_'.$key];
602
-                if (isset($value)) {
603
-                    $extension = constant('ATTRIBUTES_' . strtoupper($key));
604
-                    update_option(
605
-                        ALGOWOO_DB_OPTION . $extension,
606
-                        $value
607
-                    );
608
-                }
609
-            }
610
-
611
-            if (isset($sanitized['fields']) && (!empty($sanitized['fields']))) {
612
-                foreach ($sanitized['fields'] as $key => $value) {
613
-                    update_option(
614
-                        ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $key,
615
-                        $value
616
-                    );
617
-                }
618
-            }
619
-        }
620
-
621
-        /**
622
-         * Sanitize input in settings fields and filter through regex to accept only a-z and A-Z
623
-         *
624
-         * @param string $input Settings text data
625
-         * @return array
626
-         */
627
-        public static function settings_fields_validate_options($input)
628
-        {
629
-            $valid         = array();
630
-            $valid['name'] = preg_replace(
631
-                '/[^a-zA-Z\s]/',
632
-                '',
633
-                $input['name']
634
-            );
635
-            return $valid;
636
-        }
637
-
638
-        /**
639
-         * Load text domain for translations
640
-         *
641
-         * @return void
642
-         */
643
-        public static function load_textdomain()
644
-        {
645
-            load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/');
646
-        }
647
-
648
-        /**
649
-         * Add the new menu to settings section so that we can configure the plugin
650
-         *
651
-         * @return void
652
-         */
653
-        public static function admin_menu()
654
-        {
655
-            add_submenu_page(
656
-                'options-general.php',
657
-                esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'),
658
-                esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'),
659
-                'manage_options',
660
-                'algolia-woo-indexer-settings',
661
-                array(get_called_class(), 'algolia_woo_indexer_settings')
662
-            );
663
-        }
664
-
665
-        /**
666
-         * Display settings and allow user to modify them
667
-         *
668
-         * @return void
669
-         */
670
-        public static function algolia_woo_indexer_settings()
671
-        {
672
-            /**
673
-             * Verify that the user can access the settings page
674
-             */
675
-            if (!current_user_can('manage_options')) {
676
-                wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings'));
677
-            } ?>
462
+						}
463
+					);
464
+				}
465
+			}
466
+		}
467
+
468
+		/**
469
+		 * Send a single product to Algolia once a new product has been published
470
+		 *
471
+		 * @param int   $post_id ID of the product.
472
+		 * @param array $post Post array.
473
+		 *
474
+		 * @return void
475
+		 */
476
+		public static function send_new_product_to_algolia($post_id, $post)
477
+		{
478
+			if ('publish' !== $post->post_status || 'product' !== $post->post_type) {
479
+				return;
480
+			}
481
+			Algolia_Send_Products::send_products_to_algolia($post_id);
482
+		}
483
+
484
+		/**
485
+		 * Verify nonces before we update options and settings
486
+		 * Also retrieve the value from the send_products_to_algolia hidden field to check if we are sending products to Algolia
487
+		 *
488
+		 * @return void
489
+		 */
490
+		public static function update_settings_options()
491
+		{
492
+			/**
493
+			 * Do not proceed if nonce for settings is not set
494
+			 */
495
+			if (false === Algolia_Verify_Nonces::verify_settings_nonce()) {
496
+				return;
497
+			}
498
+
499
+			/**
500
+			 * Do not proceed if we are going to send products
501
+			 */
502
+			if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) {
503
+				return;
504
+			}
505
+
506
+			/**
507
+			 * Filter the application id, api key, index name and verify that the input is an array
508
+			 *
509
+			 * @see https://www.php.net/manual/en/function.filter-input.php
510
+			 */
511
+			$post_application_id             = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
512
+			$post_api_key                    = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
513
+			$post_index_name                 = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
514
+			$auto_send                       = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
515
+			$attributes_enabled              = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_enabled', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
516
+			$attributes_visibility           = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_visibility', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
517
+			$attributes_variation            = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_variation', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
518
+			$attributes_list                 = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_list', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
519
+			$attributes_interp               = filter_input(INPUT_POST, 'algolia_woo_indexer_attributes_interp', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
520
+
521
+			/**
522
+			 * Properly sanitize text fields before updating data
523
+			 *
524
+			 * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/
525
+			 */
526
+			$sanitized = array();
527
+			$sanitized['app_id']                    = sanitize_text_field($post_application_id['id']);
528
+			$sanitized['api_key']                   = sanitize_text_field($post_api_key['key']);
529
+			$sanitized['index_name']                = sanitize_text_field($post_index_name['name']);
530
+			$sanitized['attributes_visibility']     = sanitize_text_field($attributes_visibility['value']);
531
+			$sanitized['attributes_variation']      = sanitize_text_field($attributes_variation['value']);
532
+
533
+			/**
534
+			 * sanitize select list of id's by getting integers and them implode seperated with comma
535
+			 */
536
+
537
+			$attributes_list_integers = [];
538
+			foreach ($attributes_list['list'] as $id) {
539
+				array_push($attributes_list_integers, (int) $id);
540
+			}
541
+			$sanitized['attributes_list'] = implode(',', $attributes_list_integers);
542
+			$attributes_interp_int = [];
543
+			foreach ($attributes_interp['list'] as $id) {
544
+				array_push($attributes_interp_int, (int) $id);
545
+			}
546
+			$sanitized['attributes_interp'] = implode(',', $attributes_interp_int);
547
+
548
+			/**
549
+			 * Sanitizing by setting the value to either 1 or 0
550
+			 */
551
+			$sanitized['product'] = (!empty($auto_send)) ? 1 : 0;
552
+			$sanitized['attributes_enabled'] = (!empty($attributes_enabled)) ? 1 : 0;
553
+
554
+			/**
555
+			 * Filter the data fields checkboxes and verify that the input is an array and assign it to an associative array
556
+			 *
557
+			 * @see https://www.php.net/manual/en/function.filter-input.php
558
+			 */
559
+			$sanitized['fields'] = array();
560
+			foreach (BASIC_FIELDS as $field) {
561
+				$raw_field = filter_input(INPUT_POST, 'algolia_woo_indexer_field_' . $field, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
562
+				$filtered_field = (!empty($raw_field)) ? 1 : 0;
563
+				$sanitized['fields'][$field] = $filtered_field;
564
+			}
565
+
566
+			/**
567
+			 * Values have been filtered and sanitized
568
+			 * Check if set and not empty and update the database
569
+			 *
570
+			 * @see https://developer.wordpress.org/reference/functions/update_option/
571
+			 */
572
+			if (isset($sanitized['app_id']) && (!empty($sanitized['app_id']))) {
573
+				update_option(
574
+					ALGOWOO_DB_OPTION . ALGOLIA_APP_ID,
575
+					$sanitized['app_id']
576
+				);
577
+			}
578
+
579
+			if (isset($sanitized['api_key']) && (!empty($sanitized['api_key']))) {
580
+				update_option(
581
+					ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
582
+					$sanitized['api_key']
583
+				);
584
+			}
585
+
586
+			if (isset($sanitized['index_name']) && (!empty($sanitized['index_name']))) {
587
+				update_option(
588
+					ALGOWOO_DB_OPTION . INDEX_NAME,
589
+					$sanitized['index_name']
590
+				);
591
+			}
592
+
593
+			if (isset($sanitized['product'])) {
594
+				update_option(
595
+					ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS,
596
+					$sanitized['product']
597
+				);
598
+			}
599
+
600
+			foreach (array_keys(ATTRIBUTES_SETTINGS) as $key) {
601
+				$value = $sanitized['attributes_'.$key];
602
+				if (isset($value)) {
603
+					$extension = constant('ATTRIBUTES_' . strtoupper($key));
604
+					update_option(
605
+						ALGOWOO_DB_OPTION . $extension,
606
+						$value
607
+					);
608
+				}
609
+			}
610
+
611
+			if (isset($sanitized['fields']) && (!empty($sanitized['fields']))) {
612
+				foreach ($sanitized['fields'] as $key => $value) {
613
+					update_option(
614
+						ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $key,
615
+						$value
616
+					);
617
+				}
618
+			}
619
+		}
620
+
621
+		/**
622
+		 * Sanitize input in settings fields and filter through regex to accept only a-z and A-Z
623
+		 *
624
+		 * @param string $input Settings text data
625
+		 * @return array
626
+		 */
627
+		public static function settings_fields_validate_options($input)
628
+		{
629
+			$valid         = array();
630
+			$valid['name'] = preg_replace(
631
+				'/[^a-zA-Z\s]/',
632
+				'',
633
+				$input['name']
634
+			);
635
+			return $valid;
636
+		}
637
+
638
+		/**
639
+		 * Load text domain for translations
640
+		 *
641
+		 * @return void
642
+		 */
643
+		public static function load_textdomain()
644
+		{
645
+			load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/');
646
+		}
647
+
648
+		/**
649
+		 * Add the new menu to settings section so that we can configure the plugin
650
+		 *
651
+		 * @return void
652
+		 */
653
+		public static function admin_menu()
654
+		{
655
+			add_submenu_page(
656
+				'options-general.php',
657
+				esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'),
658
+				esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'),
659
+				'manage_options',
660
+				'algolia-woo-indexer-settings',
661
+				array(get_called_class(), 'algolia_woo_indexer_settings')
662
+			);
663
+		}
664
+
665
+		/**
666
+		 * Display settings and allow user to modify them
667
+		 *
668
+		 * @return void
669
+		 */
670
+		public static function algolia_woo_indexer_settings()
671
+		{
672
+			/**
673
+			 * Verify that the user can access the settings page
674
+			 */
675
+			if (!current_user_can('manage_options')) {
676
+				wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings'));
677
+			} ?>
678 678
             <div class="wrap">
679 679
                 <h1><?php esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'); ?></h1>
680 680
                 <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST">
681 681
                     <?php
682
-                    settings_fields('algolia_woo_options');
683
-                    do_settings_sections('algolia_woo_indexer');
684
-                    submit_button('', 'primary wide'); ?>
682
+					settings_fields('algolia_woo_options');
683
+					do_settings_sections('algolia_woo_indexer');
684
+					submit_button('', 'primary wide'); ?>
685 685
                 </form>
686 686
                 <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST">
687 687
                     <?php wp_nonce_field('send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name'); ?>
@@ -690,128 +690,128 @@  discard block
 block discarded – undo
690 690
                 </form>
691 691
             </div>
692 692
 <?php
693
-        }
694
-
695
-        /**
696
-         * Get active object instance
697
-         *
698
-         * @return object
699
-         */
700
-        public static function get_instance()
701
-        {
702
-            if (!self::$instance) {
703
-                self::$instance = new Algolia_Woo_Indexer();
704
-            }
705
-            return self::$instance;
706
-        }
707
-
708
-        /**
709
-         * The actions to execute when the plugin is activated.
710
-         *
711
-         * @return void
712
-         */
713
-        public static function activate_plugin()
714
-        {
715
-
716
-            /**
717
-             * Set default values for options if not already set
718
-             */
719
-            $auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
720
-            $algolia_application_id          = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APP_ID);
721
-            $algolia_api_key                 = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
722
-            $algolia_index_name              = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
723
-            $attributes_enabled              = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
724
-            $attributes_visibility           = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY);
725
-            $attributes_variation            = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION);
726
-            $attributes_list                 = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_LIST);
727
-            $attributes_interp               = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
728
-
729
-            if (empty($auto_send)) {
730
-                add_option(
731
-                    ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS,
732
-                    '0'
733
-                );
734
-            }
735
-
736
-            if (empty($algolia_application_id)) {
737
-                add_option(
738
-                    ALGOWOO_DB_OPTION . ALGOLIA_APP_ID,
739
-                    'Change me'
740
-                );
741
-            }
742
-
743
-            if (empty($algolia_api_key)) {
744
-                add_option(
745
-                    ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
746
-                    'Change me'
747
-                );
748
-            }
749
-
750
-            if (empty($algolia_index_name)) {
751
-                add_option(
752
-                    ALGOWOO_DB_OPTION . INDEX_NAME,
753
-                    'Change me'
754
-                );
755
-            }
756
-
757
-            if (empty($attributes_enabled)) {
758
-                add_option(
759
-                    ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED,
760
-                    0
761
-                );
762
-            }
763
-
764
-            if (empty($attributes_visibility)) {
765
-                add_option(
766
-                    ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY,
767
-                    ATTRIBUTES_VISIBILITY_STATES[1]
768
-                );
769
-            }
770
-            if (empty($attributes_variation)) {
771
-                add_option(
772
-                    ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION,
773
-                    ATTRIBUTES_VARIATION_STATES[0]
774
-                );
775
-            }
776
-            if (empty($attributes_list)) {
777
-                add_option(
778
-                    ALGOWOO_DB_OPTION . ATTRIBUTES_LIST,
779
-                    ''
780
-                );
781
-            }
782
-            if (empty($attributes_interp)) {
783
-                add_option(
784
-                    ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP,
785
-                    ''
786
-                );
787
-            }
788
-
789
-            /**
790
-             * Set default values for index fields if not already set
791
-             */
792
-            foreach (BASIC_FIELDS as $field) {
793
-                $value = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $field);
794
-                if (empty($value)) {
795
-                    update_option(
796
-                        ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $field,
797
-                        '1'
798
-                    );
799
-                }
800
-            }
801
-
802
-
803
-
804
-            set_transient(self::PLUGIN_TRANSIENT, true);
805
-        }
806
-
807
-        /**
808
-         * The actions to execute when the plugin is deactivated.
809
-         *
810
-         * @return void
811
-         */
812
-        public static function deactivate_plugin()
813
-        {
814
-            delete_transient(self::PLUGIN_TRANSIENT);
815
-        }
816
-    }
693
+		}
694
+
695
+		/**
696
+		 * Get active object instance
697
+		 *
698
+		 * @return object
699
+		 */
700
+		public static function get_instance()
701
+		{
702
+			if (!self::$instance) {
703
+				self::$instance = new Algolia_Woo_Indexer();
704
+			}
705
+			return self::$instance;
706
+		}
707
+
708
+		/**
709
+		 * The actions to execute when the plugin is activated.
710
+		 *
711
+		 * @return void
712
+		 */
713
+		public static function activate_plugin()
714
+		{
715
+
716
+			/**
717
+			 * Set default values for options if not already set
718
+			 */
719
+			$auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
720
+			$algolia_application_id          = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APP_ID);
721
+			$algolia_api_key                 = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
722
+			$algolia_index_name              = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
723
+			$attributes_enabled              = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
724
+			$attributes_visibility           = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY);
725
+			$attributes_variation            = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION);
726
+			$attributes_list                 = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_LIST);
727
+			$attributes_interp               = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
728
+
729
+			if (empty($auto_send)) {
730
+				add_option(
731
+					ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS,
732
+					'0'
733
+				);
734
+			}
735
+
736
+			if (empty($algolia_application_id)) {
737
+				add_option(
738
+					ALGOWOO_DB_OPTION . ALGOLIA_APP_ID,
739
+					'Change me'
740
+				);
741
+			}
742
+
743
+			if (empty($algolia_api_key)) {
744
+				add_option(
745
+					ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
746
+					'Change me'
747
+				);
748
+			}
749
+
750
+			if (empty($algolia_index_name)) {
751
+				add_option(
752
+					ALGOWOO_DB_OPTION . INDEX_NAME,
753
+					'Change me'
754
+				);
755
+			}
756
+
757
+			if (empty($attributes_enabled)) {
758
+				add_option(
759
+					ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED,
760
+					0
761
+				);
762
+			}
763
+
764
+			if (empty($attributes_visibility)) {
765
+				add_option(
766
+					ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY,
767
+					ATTRIBUTES_VISIBILITY_STATES[1]
768
+				);
769
+			}
770
+			if (empty($attributes_variation)) {
771
+				add_option(
772
+					ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION,
773
+					ATTRIBUTES_VARIATION_STATES[0]
774
+				);
775
+			}
776
+			if (empty($attributes_list)) {
777
+				add_option(
778
+					ALGOWOO_DB_OPTION . ATTRIBUTES_LIST,
779
+					''
780
+				);
781
+			}
782
+			if (empty($attributes_interp)) {
783
+				add_option(
784
+					ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP,
785
+					''
786
+				);
787
+			}
788
+
789
+			/**
790
+			 * Set default values for index fields if not already set
791
+			 */
792
+			foreach (BASIC_FIELDS as $field) {
793
+				$value = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $field);
794
+				if (empty($value)) {
795
+					update_option(
796
+						ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $field,
797
+						'1'
798
+					);
799
+				}
800
+			}
801
+
802
+
803
+
804
+			set_transient(self::PLUGIN_TRANSIENT, true);
805
+		}
806
+
807
+		/**
808
+		 * The actions to execute when the plugin is deactivated.
809
+		 *
810
+		 * @return void
811
+		 */
812
+		public static function deactivate_plugin()
813
+		{
814
+			delete_transient(self::PLUGIN_TRANSIENT);
815
+		}
816
+	}
817 817
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,18 +16,18 @@  discard block
 block discarded – undo
16 16
 /**
17 17
  * Abort if this file is called directly
18 18
  */
19
-if (!defined('ABSPATH')) {
19
+if ( ! defined('ABSPATH')) {
20 20
     exit;
21 21
 }
22 22
 
23 23
 /**
24 24
  * Include plugin file if function is_plugin_active does not exist
25 25
  */
26
-if (!function_exists('is_plugin_active')) {
26
+if ( ! function_exists('is_plugin_active')) {
27 27
     require_once(ABSPATH . '/wp-admin/includes/plugin.php');
28 28
 }
29 29
 
30
-if (!class_exists('Algolia_Woo_Indexer')) {
30
+if ( ! class_exists('Algolia_Woo_Indexer')) {
31 31
     /**
32 32
      * Algolia WooIndexer main class
33 33
      */
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
              * But I have still done it to be 100% safe
229 229
              */
230 230
             $auto_send = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
231
-            $auto_send = (!empty($auto_send)) ? 1 : 0; ?>
231
+            $auto_send = ( ! empty($auto_send)) ? 1 : 0; ?>
232 232
             <input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]" type="checkbox" <?php checked(1, $auto_send); ?> />
233 233
         <?php
234 234
         }
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         public static function algolia_woo_indexer_field_output($args)
242 242
         {
243 243
             $value = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $args["name"]);
244
-            $isChecked = (!empty($value)) ? 1 : 0;
244
+            $isChecked = ( ! empty($value)) ? 1 : 0;
245 245
         ?>
246 246
             <input id="<?php echo $args["label_for"] ?>" name="<?php echo $args["label_for"] ?>[checked]" type="checkbox" <?php checked(1, $isChecked); ?> />
247 247
         <?php
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         public static function algolia_woo_indexer_attributes_enabled_output()
256 256
         {
257 257
             $value = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
258
-            $isChecked = (!empty($value)) ? 1 : 0;
258
+            $isChecked = ( ! empty($value)) ? 1 : 0;
259 259
         ?>
260 260
             <input id="algolia_woo_indexer_attributes_enabled" name="algolia_woo_indexer_attributes_enabled[checked]" type="checkbox" <?php checked(1, $isChecked); ?> />
261 261
             <?php
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
         {
331 331
             $attribute_taxonomies = wc_get_attribute_taxonomies();
332 332
 
333
-            if (!$attribute_taxonomies) {
333
+            if ( ! $attribute_taxonomies) {
334 334
                 echo esc_html__('You don\'t have any attributes defined yet. Go to WooCommerce and add some to use this feature.', 'algolia-woo-indexer');
335 335
                 return;
336 336
             }
@@ -415,10 +415,10 @@  discard block
 block discarded – undo
415 415
              */
416 416
             Algolia_Check_Requirements::check_unmet_requirements();
417 417
 
418
-            if (!Algolia_Check_Requirements::algolia_wp_version_check() || !Algolia_Check_Requirements::algolia_php_version_check()) {
418
+            if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check()) {
419 419
                 add_action(
420 420
                     'admin_notices',
421
-                    function () {
421
+                    function() {
422 422
                         echo '<div class="error notice">
423 423
                                   <p>' . esc_html__('Please check the server requirements for Algolia Woo Indexer. <br/> It requires minimum PHP version 7.2 and WordPress version 5.0', 'algolia-woo-indexer') . '</p>
424 424
                                 </div>';
@@ -452,10 +452,10 @@  discard block
 block discarded – undo
452 452
 
453 453
                 self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings');
454 454
 
455
-                if (!is_plugin_active('woocommerce/woocommerce.php')) {
455
+                if ( ! is_plugin_active('woocommerce/woocommerce.php')) {
456 456
                     add_action(
457 457
                         'admin_notices',
458
-                        function () {
458
+                        function() {
459 459
                             echo '<div class="error notice">
460 460
 								  <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p>
461 461
 								</div>';
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
             /**
549 549
              * Sanitizing by setting the value to either 1 or 0
550 550
              */
551
-            $sanitized['product'] = (!empty($auto_send)) ? 1 : 0;
552
-            $sanitized['attributes_enabled'] = (!empty($attributes_enabled)) ? 1 : 0;
551
+            $sanitized['product'] = ( ! empty($auto_send)) ? 1 : 0;
552
+            $sanitized['attributes_enabled'] = ( ! empty($attributes_enabled)) ? 1 : 0;
553 553
 
554 554
             /**
555 555
              * Filter the data fields checkboxes and verify that the input is an array and assign it to an associative array
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
             $sanitized['fields'] = array();
560 560
             foreach (BASIC_FIELDS as $field) {
561 561
                 $raw_field = filter_input(INPUT_POST, 'algolia_woo_indexer_field_' . $field, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
562
-                $filtered_field = (!empty($raw_field)) ? 1 : 0;
562
+                $filtered_field = ( ! empty($raw_field)) ? 1 : 0;
563 563
                 $sanitized['fields'][$field] = $filtered_field;
564 564
             }
565 565
 
@@ -569,21 +569,21 @@  discard block
 block discarded – undo
569 569
              *
570 570
              * @see https://developer.wordpress.org/reference/functions/update_option/
571 571
              */
572
-            if (isset($sanitized['app_id']) && (!empty($sanitized['app_id']))) {
572
+            if (isset($sanitized['app_id']) && ( ! empty($sanitized['app_id']))) {
573 573
                 update_option(
574 574
                     ALGOWOO_DB_OPTION . ALGOLIA_APP_ID,
575 575
                     $sanitized['app_id']
576 576
                 );
577 577
             }
578 578
 
579
-            if (isset($sanitized['api_key']) && (!empty($sanitized['api_key']))) {
579
+            if (isset($sanitized['api_key']) && ( ! empty($sanitized['api_key']))) {
580 580
                 update_option(
581 581
                     ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
582 582
                     $sanitized['api_key']
583 583
                 );
584 584
             }
585 585
 
586
-            if (isset($sanitized['index_name']) && (!empty($sanitized['index_name']))) {
586
+            if (isset($sanitized['index_name']) && ( ! empty($sanitized['index_name']))) {
587 587
                 update_option(
588 588
                     ALGOWOO_DB_OPTION . INDEX_NAME,
589 589
                     $sanitized['index_name']
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
             }
599 599
 
600 600
             foreach (array_keys(ATTRIBUTES_SETTINGS) as $key) {
601
-                $value = $sanitized['attributes_'.$key];
601
+                $value = $sanitized['attributes_' . $key];
602 602
                 if (isset($value)) {
603 603
                     $extension = constant('ATTRIBUTES_' . strtoupper($key));
604 604
                     update_option(
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
                 }
609 609
             }
610 610
 
611
-            if (isset($sanitized['fields']) && (!empty($sanitized['fields']))) {
611
+            if (isset($sanitized['fields']) && ( ! empty($sanitized['fields']))) {
612 612
                 foreach ($sanitized['fields'] as $key => $value) {
613 613
                     update_option(
614 614
                         ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $key,
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
             /**
673 673
              * Verify that the user can access the settings page
674 674
              */
675
-            if (!current_user_can('manage_options')) {
675
+            if ( ! current_user_can('manage_options')) {
676 676
                 wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings'));
677 677
             } ?>
678 678
             <div class="wrap">
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
          */
700 700
         public static function get_instance()
701 701
         {
702
-            if (!self::$instance) {
702
+            if ( ! self::$instance) {
703 703
                 self::$instance = new Algolia_Woo_Indexer();
704 704
             }
705 705
             return self::$instance;
Please login to merge, or discard this patch.
classes/class-send-products.php 2 patches
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
  * Abort if this file is called directly
16 16
  */
17 17
 if (!defined('ABSPATH')) {
18
-    exit;
18
+	exit;
19 19
 }
20 20
 
21 21
 /**
22 22
  * Include plugin file if function is_plugin_active does not exist
23 23
  */
24 24
 if (!function_exists('is_plugin_active')) {
25
-    require_once(ABSPATH . '/wp-admin/includes/plugin.php');
25
+	require_once(ABSPATH . '/wp-admin/includes/plugin.php');
26 26
 }
27 27
 
28 28
 /**
@@ -40,19 +40,19 @@  discard block
 block discarded – undo
40 40
  * Define list of fields available to index
41 41
  */
42 42
 define('BASIC_FIELDS', array(
43
-    'product_name',
44
-    'permalink',
45
-    'tags',
46
-    'categories',
47
-    'short_description',
48
-    'long_description',
49
-    'excerpt',
50
-    'product_image',
51
-    'regular_price',
52
-    'sale_price',
53
-    'on_sale',
54
-    "stock_quantity",
55
-    "stock_status"
43
+	'product_name',
44
+	'permalink',
45
+	'tags',
46
+	'categories',
47
+	'short_description',
48
+	'long_description',
49
+	'excerpt',
50
+	'product_image',
51
+	'regular_price',
52
+	'sale_price',
53
+	'on_sale',
54
+	"stock_quantity",
55
+	"stock_status"
56 56
 ));
57 57
 
58 58
 /**
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
  * constants for attributes
69 69
  */
70 70
 define('ATTRIBUTES_SETTINGS', array(
71
-    'enabled' => 'Enable indexing of attributes',
72
-    'visibility' => 'Visibility',
73
-    'variation' => 'Used for variations',
74
-    'list' => 'Valid Attributes',
75
-    'interp' => 'Numeric Interpolation'
71
+	'enabled' => 'Enable indexing of attributes',
72
+	'visibility' => 'Visibility',
73
+	'variation' => 'Used for variations',
74
+	'list' => 'Valid Attributes',
75
+	'interp' => 'Numeric Interpolation'
76 76
 ));
77 77
 define('ATTRIBUTES_ENABLED', '_attributes_enabled');
78 78
 define('ATTRIBUTES_VISIBILITY', '_attributes_visibility');
@@ -84,400 +84,400 @@  discard block
 block discarded – undo
84 84
 
85 85
 
86 86
 if (!class_exists('Algolia_Send_Products')) {
87
-    /**
88
-     * Algolia WooIndexer main class
89
-     */
90
-    // TODO Rename class "Algolia_Send_Products" to match the regular expression ^[A-Z][a-zA-Z0-9]*$.
91
-    class Algolia_Send_Products
92
-    {
93
-        const PLUGIN_NAME      = 'Algolia Woo Indexer';
94
-        const PLUGIN_TRANSIENT = 'algowoo-plugin-notice';
95
-
96
-        /**
97
-         * The Algolia instance
98
-         *
99
-         * @var \Algolia\AlgoliaSearch\SearchClient
100
-         */
101
-        private static $algolia = null;
102
-
103
-        /**
104
-         * Check if we can connect to Algolia, if not, handle the exception, display an error and then return
105
-         */
106
-        public static function can_connect_to_algolia()
107
-        {
108
-            try {
109
-                self::$algolia->listApiKeys();
110
-            } catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) {
111
-                add_action(
112
-                    'admin_notices',
113
-                    function () {
114
-                        echo '<div class="error notice">
87
+	/**
88
+	 * Algolia WooIndexer main class
89
+	 */
90
+	// TODO Rename class "Algolia_Send_Products" to match the regular expression ^[A-Z][a-zA-Z0-9]*$.
91
+	class Algolia_Send_Products
92
+	{
93
+		const PLUGIN_NAME      = 'Algolia Woo Indexer';
94
+		const PLUGIN_TRANSIENT = 'algowoo-plugin-notice';
95
+
96
+		/**
97
+		 * The Algolia instance
98
+		 *
99
+		 * @var \Algolia\AlgoliaSearch\SearchClient
100
+		 */
101
+		private static $algolia = null;
102
+
103
+		/**
104
+		 * Check if we can connect to Algolia, if not, handle the exception, display an error and then return
105
+		 */
106
+		public static function can_connect_to_algolia()
107
+		{
108
+			try {
109
+				self::$algolia->listApiKeys();
110
+			} catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) {
111
+				add_action(
112
+					'admin_notices',
113
+					function () {
114
+						echo '<div class="error notice">
115 115
                             <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p>
116 116
 						</div>';
117
-                    }
118
-                );
119
-                return;
120
-            }
121
-        }
122
-
123
-        /**
124
-         * check if the field is enabled and shall be sent
125
-         *
126
-         * @param  mixed $field name of field to be checked according to BASIC_FIELDS 
127
-         * @return boolean true if enable, false is not enabled
128
-         */
129
-        public static function is_basic_field_enabled($field)
130
-        {
131
-            $fieldValue = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $field);
132
-            return $fieldValue;
133
-        }
134
-
135
-        /**
136
-         * helper function to add a field to a record while checking their state
137
-         *
138
-         * @param  array $record existing record where the field and value shall be added to 
139
-         * @param  string $field name of field to be checked according to BASIC_FIELDS 
140
-         * @param  mixed $value data to be added to the record array named to $field
141
-         * @param  boolean $skip_basic_field_validation set to true if it is not a basic field to skip validation 
142
-         * @return array $record previous passed $record with added field data
143
-         */
144
-        public static function add_to_record($record, $field, $value, $skip_basic_field_validation = false)
145
-        {
146
-            /**
147
-             *  only if enabled or validation skipped and not empty
148
-             */
149
-            if ((!self::is_basic_field_enabled($field) && !$skip_basic_field_validation) || empty($value)) {
150
-                return $record;
151
-            }
152
-
153
-            $record[$field] = $value;
154
-            return $record;
155
-        }
156
-
157
-        /**
158
-         * Get sale price or regular price based on product type
159
-         *
160
-         * @param  mixed $product Product to check   
161
-         * @return array ['sale_price' => $sale_price,'regular_price' => $regular_price] Array with regular price and sale price
162
-         */
163
-        public static function get_product_type_price($product)
164
-        {
165
-            $sale_price = 0;
166
-            $regular_price = 0;
167
-            if ($product->is_type('simple')) {
168
-                $sale_price     =  $product->get_sale_price();
169
-                $regular_price  =  $product->get_regular_price();
170
-            } elseif ($product->is_type('variable')) {
171
-                $sale_price     =  $product->get_variation_sale_price('min', true);
172
-                $regular_price  =  $product->get_variation_regular_price('max', true);
173
-            }
174
-            return array(
175
-                'sale_price' => $sale_price,
176
-                'regular_price' => $regular_price
177
-            );
178
-        }
179
-
180
-
181
-        /**
182
-         * Checks if stock management is enabled and if so, returns quantity and status
183
-         *
184
-         * @param  mixed $product Product to check   
185
-         * @return array ['stock_quantity' => $stock_quantity,'stock_status' => $stock_status] Array with quantity and status. if stock management is disabled, false will be returned,
186
-         */
187
-        public static function get_product_stock_data($product)
188
-        {
189
-            if ($product->get_manage_stock()) {
190
-                return array(
191
-                    'stock_quantity' => $product->get_stock_quantity(),
192
-                    'stock_status' => $product->get_stock_status()
193
-                );
194
-            }
195
-            return false;
196
-        }
197
-
198
-        /**
199
-         * Get product tags
200
-         *
201
-         * @param  mixed $product Product to check   
202
-         * @return array ['tag1', 'tag2', ...] simple array with associated tags
203
-         */
204
-        public static function get_product_tags($product)
205
-        {
206
-            $tags = get_the_terms($product->get_id(), 'product_tag');
207
-            $term_array = array();
208
-            if (is_array($tags)) {
209
-                foreach ($tags as $tag) {
210
-                    $name = get_term($tag)->name;
211
-                    array_push($term_array, $name);
212
-                }
213
-            }
214
-            return $term_array;
215
-        }
216
-
217
-        /**
218
-         * Get product categories
219
-         *
220
-         * @param  mixed $product Product to check   
221
-         * @return array ['tag1', 'tag2', ...] simple array with associated categories
222
-         */
223
-        public static function get_product_categories($product)
224
-        {
225
-            $categories = get_the_terms($product->get_id(), 'product_cat');
226
-            $term_array = array();
227
-            foreach ($categories as $category) {
228
-                $name = get_term($category)->name;
229
-                $slug = get_term($category)->slug;
230
-                array_push($term_array, array(
231
-                    "name" => $name,
232
-                    "slug" => $slug
233
-                ));
234
-            }
235
-            return $term_array;
236
-        }
237
-
238
-        /**
239
-         * Get attributes from product
240
-         *
241
-         * @param  mixed $product Product to check   
242
-         * @return array ['pa_name' => ['value1', 'value2']] Array with key set to the product attribute internal name and values as array. returns false if not attributes found.
243
-         */
244
-        public static function get_product_attributes($product)
245
-        {
246
-            /**
247
-             * ensure that attrobutes are actually enabled
248
-             */
249
-            $attributes_enabled = (int) get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
250
-            if ($attributes_enabled !== 1) {
251
-                return false;
252
-            }
253
-
254
-            /**
255
-             * gather data and settings
256
-             */
257
-            $rawAttributes = $product->get_attributes("edit");
258
-            $setting_visibility = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY);
259
-            $setting_variation = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION);
260
-            $setting_ids = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_LIST);
261
-            $setting_ids = explode(",", $setting_ids);
262
-            $setting_ids_interp = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
263
-            $setting_ids_interp = explode(",", $setting_ids_interp);
264
-
265
-            if (!$rawAttributes) {
266
-                return false;
267
-            }
268
-
269
-            $attributes = [];
270
-            foreach ($rawAttributes as $attribute) {
271
-
272
-                $visibility = $attribute["visible"];
273
-                $variation = $attribute["variation"];
274
-                $id = $attribute->get_id();
275
-                /**
276
-                 * skip variable related attributes,
277
-                 * ensure that taxonomy is whitelisted and
278
-                 * ensure that the visibility and variation is respected
279
-                 */
280
-                if (
281
-                    $attribute->get_variation() ||
282
-                    !in_array($id, $setting_ids) ||
283
-                    ($setting_visibility ===  "visible" && $visibility === false) ||
284
-                    ($setting_visibility ===  "hidden" && $visibility === true) ||
285
-                    ($setting_variation ===  "used" && $variation === false) ||
286
-                    ($setting_variation ===  "notused" && $variation === true)
287
-                ) {
288
-                    continue;
289
-                }
290
-
291
-
292
-                $name = $attribute->get_name();
293
-                if ($attribute->is_taxonomy()) {
294
-                    $terms = wp_get_post_terms($product->get_id(), $name, 'all');
295
-                    $tax_terms = array();
296
-
297
-                    switch (in_array($id, $setting_ids_interp)) {
298
-                            /**
299
-                         * numeric interpolation
300
-                         */
301
-                        case true:
302
-                            $integers = array();
303
-                            foreach ($terms as $term) {
304
-                                array_push($integers, (int) $term->name);
305
-                            }
306
-                            if (count($integers) > 0) {
307
-                                for ($i = min($integers); $i <= max($integers); $i++) {
308
-                                    array_push($tax_terms, $i);
309
-                                }
310
-                            }
311
-                            break;
312
-                            /**
313
-                             * normal mixed content case 
314
-                             */
315
-                        default:
316
-                            foreach ($terms as $term) {
317
-                                $single_term = esc_html($term->name);
318
-                                array_push($tax_terms, $single_term);
319
-                            }
320
-                    }
321
-                }
322
-                $attributes[$name] = $tax_terms;
323
-            }
324
-            return $attributes;
325
-        }
326
-
327
-        /**
328
-         * Send WooCommerce products to Algolia
329
-         *
330
-         * @param Int $id Product to send to Algolia if we send only a single product
331
-         * @return void
332
-         */
333
-        public static function send_products_to_algolia($id = '')
334
-        {
335
-            /**
336
-             * Remove classes from plugin URL and autoload Algolia with Composer
337
-             */
338
-
339
-            $base_plugin_directory = str_replace('classes', '', dirname(__FILE__));
340
-            require_once $base_plugin_directory . '/vendor/autoload.php';
341
-
342
-            /**
343
-             * Fetch the required variables from the Settings API
344
-             */
345
-
346
-            $algolia_application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APP_ID);
347
-            $algolia_application_id = is_string($algolia_application_id) ? $algolia_application_id : CHANGE_ME;
348
-
349
-            $algolia_api_key        = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
350
-            $algolia_api_key        = is_string($algolia_api_key) ? $algolia_api_key : CHANGE_ME;
351
-
352
-            $algolia_index_name     = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
353
-            $algolia_index_name        = is_string($algolia_index_name) ? $algolia_index_name : CHANGE_ME;
354
-
355
-            /**
356
-             * Display admin notice and return if not all values have been set
357
-             */
358
-
359
-            Algolia_Check_Requirements::check_algolia_input_values($algolia_application_id, $algolia_api_key, $algolia_index_name);
360
-
361
-            /**
362
-             * Initiate the Algolia client
363
-             */
364
-            self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key);
365
-
366
-            /**
367
-             * Check if we can connect, if not, handle the exception, display an error and then return
368
-             */
369
-            self::can_connect_to_algolia();
370
-
371
-            /**
372
-             * Initialize the search index and set the name to the option from the database
373
-             */
374
-            $index = self::$algolia->initIndex($algolia_index_name);
375
-
376
-            /**
377
-             * Setup arguments for sending all products to Algolia
378
-             *
379
-             * Limit => -1 means we send all products
380
-             */
381
-            $arguments = array(
382
-                'status'   => 'publish',
383
-                'limit'    => -1,
384
-                'paginate' => false,
385
-            );
386
-
387
-            /**
388
-             * Setup arguments for sending only a single product
389
-             */
390
-            if (isset($id) && '' !== $id) {
391
-                $arguments = array(
392
-                    'status'   => 'publish',
393
-                    'include'  => array($id),
394
-                    'paginate' => false,
395
-                );
396
-            }
397
-
398
-            /**
399
-             * Fetch all products from WooCommerce
400
-             *
401
-             * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html
402
-             */
403
-            $products =
404
-                /** @scrutinizer ignore-call */
405
-                wc_get_products($arguments);
406
-
407
-            if (empty($products)) {
408
-                return;
409
-            }
410
-            $records = array();
411
-            $record  = array();
412
-
413
-            foreach ($products as $product) {
414
-                /**
415
-                 * Set sale price or regular price based on product type
416
-                 */
417
-                $product_type_price = self::get_product_type_price($product);
418
-                $sale_price = $product_type_price['sale_price'];
419
-                $regular_price = $product_type_price['regular_price'];
420
-
421
-
422
-
423
-
424
-                /**
425
-                 * always add objectID (mandatory field for algolia)
426
-                 */
427
-                $record['objectID'] = $product->get_id();
428
-
429
-                /**
430
-                 * Extract image from $product->get_image()
431
-                 */
432
-                if (self::is_basic_field_enabled("product_image")) {
433
-                    preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $product->get_image(), $result);
434
-                    $record["product_image"] = array_pop($result);
435
-                }
436
-
437
-                $record = self::add_to_record($record, 'product_name', $product->get_name());
438
-                $record = self::add_to_record($record, 'short_description', $product->get_short_description());
439
-                $record = self::add_to_record($record, 'long_description', $product->get_description());
440
-                $record = self::add_to_record($record, 'excerpt', get_the_excerpt($product->get_id()));
441
-                $record = self::add_to_record($record, 'regular_price', $regular_price);
442
-                $record = self::add_to_record($record, 'sale_price', $sale_price);
443
-                $record = self::add_to_record($record, 'on_sale', $product->is_on_sale());
444
-                $record = self::add_to_record($record, 'permalink', $product->get_permalink());
445
-                $record = self::add_to_record($record, 'categories', self::get_product_categories($product));
446
-                $record = self::add_to_record($record, 'tags', self::get_product_tags($product));
447
-                $record = self::add_to_record($record, 'attributes', self::get_product_attributes($product), true);
448
-
449
-
450
-
451
-                /**
452
-                 * Add stock information if stock management is on
453
-                 */
454
-                $stock_data = self::get_product_stock_data($product);
455
-                if (is_array($stock_data)) {
456
-                    $record = self::add_to_record($record, 'stock_quantity', $stock_data['stock_quantity']);
457
-                    $record = self::add_to_record($record, 'stock_status', $stock_data['stock_status']);
458
-                }
459
-
460
-                $records[] = $record;
461
-            }
462
-
463
-            wp_reset_postdata();
464
-
465
-            /**
466
-             * Send the information to Algolia and save the result
467
-             * If result is NullResponse, print an error message
468
-             */
469
-            $result = $index->saveObjects($records);
470
-
471
-            if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) {
472
-                wp_die(esc_html__('No response from the server. Please check your settings and try again', 'algolia_woo_indexer_settings'));
473
-            }
474
-
475
-            /**
476
-             * Display success message
477
-             */
478
-            echo '<div class="notice notice-success is-dismissible">
117
+					}
118
+				);
119
+				return;
120
+			}
121
+		}
122
+
123
+		/**
124
+		 * check if the field is enabled and shall be sent
125
+		 *
126
+		 * @param  mixed $field name of field to be checked according to BASIC_FIELDS 
127
+		 * @return boolean true if enable, false is not enabled
128
+		 */
129
+		public static function is_basic_field_enabled($field)
130
+		{
131
+			$fieldValue = get_option(ALGOWOO_DB_OPTION . BASIC_FIELD_PREFIX . $field);
132
+			return $fieldValue;
133
+		}
134
+
135
+		/**
136
+		 * helper function to add a field to a record while checking their state
137
+		 *
138
+		 * @param  array $record existing record where the field and value shall be added to 
139
+		 * @param  string $field name of field to be checked according to BASIC_FIELDS 
140
+		 * @param  mixed $value data to be added to the record array named to $field
141
+		 * @param  boolean $skip_basic_field_validation set to true if it is not a basic field to skip validation 
142
+		 * @return array $record previous passed $record with added field data
143
+		 */
144
+		public static function add_to_record($record, $field, $value, $skip_basic_field_validation = false)
145
+		{
146
+			/**
147
+			 *  only if enabled or validation skipped and not empty
148
+			 */
149
+			if ((!self::is_basic_field_enabled($field) && !$skip_basic_field_validation) || empty($value)) {
150
+				return $record;
151
+			}
152
+
153
+			$record[$field] = $value;
154
+			return $record;
155
+		}
156
+
157
+		/**
158
+		 * Get sale price or regular price based on product type
159
+		 *
160
+		 * @param  mixed $product Product to check   
161
+		 * @return array ['sale_price' => $sale_price,'regular_price' => $regular_price] Array with regular price and sale price
162
+		 */
163
+		public static function get_product_type_price($product)
164
+		{
165
+			$sale_price = 0;
166
+			$regular_price = 0;
167
+			if ($product->is_type('simple')) {
168
+				$sale_price     =  $product->get_sale_price();
169
+				$regular_price  =  $product->get_regular_price();
170
+			} elseif ($product->is_type('variable')) {
171
+				$sale_price     =  $product->get_variation_sale_price('min', true);
172
+				$regular_price  =  $product->get_variation_regular_price('max', true);
173
+			}
174
+			return array(
175
+				'sale_price' => $sale_price,
176
+				'regular_price' => $regular_price
177
+			);
178
+		}
179
+
180
+
181
+		/**
182
+		 * Checks if stock management is enabled and if so, returns quantity and status
183
+		 *
184
+		 * @param  mixed $product Product to check   
185
+		 * @return array ['stock_quantity' => $stock_quantity,'stock_status' => $stock_status] Array with quantity and status. if stock management is disabled, false will be returned,
186
+		 */
187
+		public static function get_product_stock_data($product)
188
+		{
189
+			if ($product->get_manage_stock()) {
190
+				return array(
191
+					'stock_quantity' => $product->get_stock_quantity(),
192
+					'stock_status' => $product->get_stock_status()
193
+				);
194
+			}
195
+			return false;
196
+		}
197
+
198
+		/**
199
+		 * Get product tags
200
+		 *
201
+		 * @param  mixed $product Product to check   
202
+		 * @return array ['tag1', 'tag2', ...] simple array with associated tags
203
+		 */
204
+		public static function get_product_tags($product)
205
+		{
206
+			$tags = get_the_terms($product->get_id(), 'product_tag');
207
+			$term_array = array();
208
+			if (is_array($tags)) {
209
+				foreach ($tags as $tag) {
210
+					$name = get_term($tag)->name;
211
+					array_push($term_array, $name);
212
+				}
213
+			}
214
+			return $term_array;
215
+		}
216
+
217
+		/**
218
+		 * Get product categories
219
+		 *
220
+		 * @param  mixed $product Product to check   
221
+		 * @return array ['tag1', 'tag2', ...] simple array with associated categories
222
+		 */
223
+		public static function get_product_categories($product)
224
+		{
225
+			$categories = get_the_terms($product->get_id(), 'product_cat');
226
+			$term_array = array();
227
+			foreach ($categories as $category) {
228
+				$name = get_term($category)->name;
229
+				$slug = get_term($category)->slug;
230
+				array_push($term_array, array(
231
+					"name" => $name,
232
+					"slug" => $slug
233
+				));
234
+			}
235
+			return $term_array;
236
+		}
237
+
238
+		/**
239
+		 * Get attributes from product
240
+		 *
241
+		 * @param  mixed $product Product to check   
242
+		 * @return array ['pa_name' => ['value1', 'value2']] Array with key set to the product attribute internal name and values as array. returns false if not attributes found.
243
+		 */
244
+		public static function get_product_attributes($product)
245
+		{
246
+			/**
247
+			 * ensure that attrobutes are actually enabled
248
+			 */
249
+			$attributes_enabled = (int) get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_ENABLED);
250
+			if ($attributes_enabled !== 1) {
251
+				return false;
252
+			}
253
+
254
+			/**
255
+			 * gather data and settings
256
+			 */
257
+			$rawAttributes = $product->get_attributes("edit");
258
+			$setting_visibility = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VISIBILITY);
259
+			$setting_variation = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_VARIATION);
260
+			$setting_ids = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_LIST);
261
+			$setting_ids = explode(",", $setting_ids);
262
+			$setting_ids_interp = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
263
+			$setting_ids_interp = explode(",", $setting_ids_interp);
264
+
265
+			if (!$rawAttributes) {
266
+				return false;
267
+			}
268
+
269
+			$attributes = [];
270
+			foreach ($rawAttributes as $attribute) {
271
+
272
+				$visibility = $attribute["visible"];
273
+				$variation = $attribute["variation"];
274
+				$id = $attribute->get_id();
275
+				/**
276
+				 * skip variable related attributes,
277
+				 * ensure that taxonomy is whitelisted and
278
+				 * ensure that the visibility and variation is respected
279
+				 */
280
+				if (
281
+					$attribute->get_variation() ||
282
+					!in_array($id, $setting_ids) ||
283
+					($setting_visibility ===  "visible" && $visibility === false) ||
284
+					($setting_visibility ===  "hidden" && $visibility === true) ||
285
+					($setting_variation ===  "used" && $variation === false) ||
286
+					($setting_variation ===  "notused" && $variation === true)
287
+				) {
288
+					continue;
289
+				}
290
+
291
+
292
+				$name = $attribute->get_name();
293
+				if ($attribute->is_taxonomy()) {
294
+					$terms = wp_get_post_terms($product->get_id(), $name, 'all');
295
+					$tax_terms = array();
296
+
297
+					switch (in_array($id, $setting_ids_interp)) {
298
+							/**
299
+							 * numeric interpolation
300
+							 */
301
+						case true:
302
+							$integers = array();
303
+							foreach ($terms as $term) {
304
+								array_push($integers, (int) $term->name);
305
+							}
306
+							if (count($integers) > 0) {
307
+								for ($i = min($integers); $i <= max($integers); $i++) {
308
+									array_push($tax_terms, $i);
309
+								}
310
+							}
311
+							break;
312
+							/**
313
+							 * normal mixed content case 
314
+							 */
315
+						default:
316
+							foreach ($terms as $term) {
317
+								$single_term = esc_html($term->name);
318
+								array_push($tax_terms, $single_term);
319
+							}
320
+					}
321
+				}
322
+				$attributes[$name] = $tax_terms;
323
+			}
324
+			return $attributes;
325
+		}
326
+
327
+		/**
328
+		 * Send WooCommerce products to Algolia
329
+		 *
330
+		 * @param Int $id Product to send to Algolia if we send only a single product
331
+		 * @return void
332
+		 */
333
+		public static function send_products_to_algolia($id = '')
334
+		{
335
+			/**
336
+			 * Remove classes from plugin URL and autoload Algolia with Composer
337
+			 */
338
+
339
+			$base_plugin_directory = str_replace('classes', '', dirname(__FILE__));
340
+			require_once $base_plugin_directory . '/vendor/autoload.php';
341
+
342
+			/**
343
+			 * Fetch the required variables from the Settings API
344
+			 */
345
+
346
+			$algolia_application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APP_ID);
347
+			$algolia_application_id = is_string($algolia_application_id) ? $algolia_application_id : CHANGE_ME;
348
+
349
+			$algolia_api_key        = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
350
+			$algolia_api_key        = is_string($algolia_api_key) ? $algolia_api_key : CHANGE_ME;
351
+
352
+			$algolia_index_name     = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
353
+			$algolia_index_name        = is_string($algolia_index_name) ? $algolia_index_name : CHANGE_ME;
354
+
355
+			/**
356
+			 * Display admin notice and return if not all values have been set
357
+			 */
358
+
359
+			Algolia_Check_Requirements::check_algolia_input_values($algolia_application_id, $algolia_api_key, $algolia_index_name);
360
+
361
+			/**
362
+			 * Initiate the Algolia client
363
+			 */
364
+			self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key);
365
+
366
+			/**
367
+			 * Check if we can connect, if not, handle the exception, display an error and then return
368
+			 */
369
+			self::can_connect_to_algolia();
370
+
371
+			/**
372
+			 * Initialize the search index and set the name to the option from the database
373
+			 */
374
+			$index = self::$algolia->initIndex($algolia_index_name);
375
+
376
+			/**
377
+			 * Setup arguments for sending all products to Algolia
378
+			 *
379
+			 * Limit => -1 means we send all products
380
+			 */
381
+			$arguments = array(
382
+				'status'   => 'publish',
383
+				'limit'    => -1,
384
+				'paginate' => false,
385
+			);
386
+
387
+			/**
388
+			 * Setup arguments for sending only a single product
389
+			 */
390
+			if (isset($id) && '' !== $id) {
391
+				$arguments = array(
392
+					'status'   => 'publish',
393
+					'include'  => array($id),
394
+					'paginate' => false,
395
+				);
396
+			}
397
+
398
+			/**
399
+			 * Fetch all products from WooCommerce
400
+			 *
401
+			 * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html
402
+			 */
403
+			$products =
404
+				/** @scrutinizer ignore-call */
405
+				wc_get_products($arguments);
406
+
407
+			if (empty($products)) {
408
+				return;
409
+			}
410
+			$records = array();
411
+			$record  = array();
412
+
413
+			foreach ($products as $product) {
414
+				/**
415
+				 * Set sale price or regular price based on product type
416
+				 */
417
+				$product_type_price = self::get_product_type_price($product);
418
+				$sale_price = $product_type_price['sale_price'];
419
+				$regular_price = $product_type_price['regular_price'];
420
+
421
+
422
+
423
+
424
+				/**
425
+				 * always add objectID (mandatory field for algolia)
426
+				 */
427
+				$record['objectID'] = $product->get_id();
428
+
429
+				/**
430
+				 * Extract image from $product->get_image()
431
+				 */
432
+				if (self::is_basic_field_enabled("product_image")) {
433
+					preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $product->get_image(), $result);
434
+					$record["product_image"] = array_pop($result);
435
+				}
436
+
437
+				$record = self::add_to_record($record, 'product_name', $product->get_name());
438
+				$record = self::add_to_record($record, 'short_description', $product->get_short_description());
439
+				$record = self::add_to_record($record, 'long_description', $product->get_description());
440
+				$record = self::add_to_record($record, 'excerpt', get_the_excerpt($product->get_id()));
441
+				$record = self::add_to_record($record, 'regular_price', $regular_price);
442
+				$record = self::add_to_record($record, 'sale_price', $sale_price);
443
+				$record = self::add_to_record($record, 'on_sale', $product->is_on_sale());
444
+				$record = self::add_to_record($record, 'permalink', $product->get_permalink());
445
+				$record = self::add_to_record($record, 'categories', self::get_product_categories($product));
446
+				$record = self::add_to_record($record, 'tags', self::get_product_tags($product));
447
+				$record = self::add_to_record($record, 'attributes', self::get_product_attributes($product), true);
448
+
449
+
450
+
451
+				/**
452
+				 * Add stock information if stock management is on
453
+				 */
454
+				$stock_data = self::get_product_stock_data($product);
455
+				if (is_array($stock_data)) {
456
+					$record = self::add_to_record($record, 'stock_quantity', $stock_data['stock_quantity']);
457
+					$record = self::add_to_record($record, 'stock_status', $stock_data['stock_status']);
458
+				}
459
+
460
+				$records[] = $record;
461
+			}
462
+
463
+			wp_reset_postdata();
464
+
465
+			/**
466
+			 * Send the information to Algolia and save the result
467
+			 * If result is NullResponse, print an error message
468
+			 */
469
+			$result = $index->saveObjects($records);
470
+
471
+			if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) {
472
+				wp_die(esc_html__('No response from the server. Please check your settings and try again', 'algolia_woo_indexer_settings'));
473
+			}
474
+
475
+			/**
476
+			 * Display success message
477
+			 */
478
+			echo '<div class="notice notice-success is-dismissible">
479 479
 					 	<p>' . esc_html__('Product(s) sent to Algolia.', 'algolia-woo-indexer') . '</p>
480 480
 				  		</div>';
481
-        }
482
-    }
481
+		}
482
+	}
483 483
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 /**
15 15
  * Abort if this file is called directly
16 16
  */
17
-if (!defined('ABSPATH')) {
17
+if ( ! defined('ABSPATH')) {
18 18
     exit;
19 19
 }
20 20
 
21 21
 /**
22 22
  * Include plugin file if function is_plugin_active does not exist
23 23
  */
24
-if (!function_exists('is_plugin_active')) {
24
+if ( ! function_exists('is_plugin_active')) {
25 25
     require_once(ABSPATH . '/wp-admin/includes/plugin.php');
26 26
 }
27 27
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 define('ATTRIBUTES_INTERP', '_attributes_interp');
84 84
 
85 85
 
86
-if (!class_exists('Algolia_Send_Products')) {
86
+if ( ! class_exists('Algolia_Send_Products')) {
87 87
     /**
88 88
      * Algolia WooIndexer main class
89 89
      */
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
             } catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) {
111 111
                 add_action(
112 112
                     'admin_notices',
113
-                    function () {
113
+                    function() {
114 114
                         echo '<div class="error notice">
115 115
                             <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p>
116 116
 						</div>';
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
             /**
147 147
              *  only if enabled or validation skipped and not empty
148 148
              */
149
-            if ((!self::is_basic_field_enabled($field) && !$skip_basic_field_validation) || empty($value)) {
149
+            if (( ! self::is_basic_field_enabled($field) && ! $skip_basic_field_validation) || empty($value)) {
150 150
                 return $record;
151 151
             }
152 152
 
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
             $sale_price = 0;
166 166
             $regular_price = 0;
167 167
             if ($product->is_type('simple')) {
168
-                $sale_price     =  $product->get_sale_price();
169
-                $regular_price  =  $product->get_regular_price();
168
+                $sale_price     = $product->get_sale_price();
169
+                $regular_price  = $product->get_regular_price();
170 170
             } elseif ($product->is_type('variable')) {
171
-                $sale_price     =  $product->get_variation_sale_price('min', true);
172
-                $regular_price  =  $product->get_variation_regular_price('max', true);
171
+                $sale_price     = $product->get_variation_sale_price('min', true);
172
+                $regular_price  = $product->get_variation_regular_price('max', true);
173 173
             }
174 174
             return array(
175 175
                 'sale_price' => $sale_price,
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             $setting_ids_interp = get_option(ALGOWOO_DB_OPTION . ATTRIBUTES_INTERP);
263 263
             $setting_ids_interp = explode(",", $setting_ids_interp);
264 264
 
265
-            if (!$rawAttributes) {
265
+            if ( ! $rawAttributes) {
266 266
                 return false;
267 267
             }
268 268
 
@@ -279,11 +279,11 @@  discard block
 block discarded – undo
279 279
                  */
280 280
                 if (
281 281
                     $attribute->get_variation() ||
282
-                    !in_array($id, $setting_ids) ||
283
-                    ($setting_visibility ===  "visible" && $visibility === false) ||
284
-                    ($setting_visibility ===  "hidden" && $visibility === true) ||
285
-                    ($setting_variation ===  "used" && $variation === false) ||
286
-                    ($setting_variation ===  "notused" && $variation === true)
282
+                    ! in_array($id, $setting_ids) ||
283
+                    ($setting_visibility === "visible" && $visibility === false) ||
284
+                    ($setting_visibility === "hidden" && $visibility === true) ||
285
+                    ($setting_variation === "used" && $variation === false) ||
286
+                    ($setting_variation === "notused" && $variation === true)
287 287
                 ) {
288 288
                     continue;
289 289
                 }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             $algolia_api_key        = is_string($algolia_api_key) ? $algolia_api_key : CHANGE_ME;
351 351
 
352 352
             $algolia_index_name     = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
353
-            $algolia_index_name        = is_string($algolia_index_name) ? $algolia_index_name : CHANGE_ME;
353
+            $algolia_index_name = is_string($algolia_index_name) ? $algolia_index_name : CHANGE_ME;
354 354
 
355 355
             /**
356 356
              * Display admin notice and return if not all values have been set
Please login to merge, or discard this patch.