Passed
Push — master ( 28fe6c...636ed8 )
by Daniel
04:04 queued 02:03
created
classes/class-algolia-woo-indexer.php 1 patch
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,27 +14,27 @@  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
 
28 28
 /**
29 29
  * Define the plugin version and the database table name
30 30
  */
31
-define( 'ALGOWOO_DB_OPTION', '_algolia_woo_indexer' );
32
-define( 'ALGOWOO_CURRENT_DB_VERSION', '0.3' );
31
+define('ALGOWOO_DB_OPTION', '_algolia_woo_indexer');
32
+define('ALGOWOO_CURRENT_DB_VERSION', '0.3');
33 33
 
34 34
 /**
35 35
  * Define application constants
36 36
  */
37
-define( 'CHANGE_ME', 'change me' );
37
+define('CHANGE_ME', 'change me');
38 38
 
39 39
 /**
40 40
  * Database table names
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 define('ALGOLIA_APPLICATION_ID', '_application_id');
46 46
 define('ALGOLIA_API_KEY', '_admin_api_key');
47 47
 
48
-if ( ! class_exists( 'Algolia_Woo_Indexer' ) ) {
48
+if ( ! class_exists('Algolia_Woo_Indexer')) {
49 49
 	/**
50 50
 	 * Algolia WooIndexer main class
51 51
 	 */
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 			*
96 96
 			* @see https://developer.wordpress.org/reference/functions/register_setting/
97 97
 			*/
98
-			if ( is_admin() ) {
98
+			if (is_admin()) {
99 99
 				$arguments = array(
100 100
 					'type'              => 'string',
101 101
 					'sanitize_callback' => 'settings_fields_validate_options',
102 102
 					'default'           => null,
103 103
 				);
104
-				register_setting( 'algolia_woo_options', 'algolia_woo_options', $arguments );
104
+				register_setting('algolia_woo_options', 'algolia_woo_options', $arguments);
105 105
 
106 106
 				/**
107 107
 				 * Make sure we reference the instance of the current class by using self::get_instance()
@@ -114,42 +114,42 @@  discard block
 block discarded – undo
114 114
 				 */
115 115
 				add_settings_section(
116 116
 					'algolia_woo_indexer_main',
117
-					esc_html__( 'Algolia Woo Plugin Settings', 'algolia-woo-indexer' ),
118
-					array( $algowooindexer, 'algolia_woo_indexer_section_text' ),
117
+					esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'),
118
+					array($algowooindexer, 'algolia_woo_indexer_section_text'),
119 119
 					'algolia_woo_indexer'
120 120
 				);
121 121
 				add_settings_field(
122 122
 					'algolia_woo_indexer_application_id',
123
-					esc_html__( 'Application ID', 'algolia-woo-indexer' ),
124
-					array( $algowooindexer, 'algolia_woo_indexer_application_id_output' ),
123
+					esc_html__('Application ID', 'algolia-woo-indexer'),
124
+					array($algowooindexer, 'algolia_woo_indexer_application_id_output'),
125 125
 					'algolia_woo_indexer',
126 126
 					'algolia_woo_indexer_main'
127 127
 				);
128 128
 				add_settings_field(
129 129
 					'algolia_woo_indexer_admin_api_key',
130
-					esc_html__( 'Admin API Key', 'algolia-woo-indexer' ),
131
-					array( $algowooindexer, 'algolia_woo_indexer_admin_api_key_output' ),
130
+					esc_html__('Admin API Key', 'algolia-woo-indexer'),
131
+					array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'),
132 132
 					'algolia_woo_indexer',
133 133
 					'algolia_woo_indexer_main'
134 134
 				);
135 135
 				add_settings_field(
136 136
 					'algolia_woo_indexer_index_name',
137
-					esc_html__( 'Index name (will be created if not existing)', 'algolia-woo-indexer' ),
138
-					array( $algowooindexer, 'algolia_woo_indexer_index_name_output' ),
137
+					esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'),
138
+					array($algowooindexer, 'algolia_woo_indexer_index_name_output'),
139 139
 					'algolia_woo_indexer',
140 140
 					'algolia_woo_indexer_main'
141 141
 				);
142 142
 				add_settings_field(
143 143
 					'algolia_woo_indexer_index_in_stock',
144
-					esc_html__( 'Only index products in stock', 'algolia-woo-indexer' ),
145
-					array( $algowooindexer, 'algolia_woo_indexer_index_in_stock_output' ),
144
+					esc_html__('Only index products in stock', 'algolia-woo-indexer'),
145
+					array($algowooindexer, 'algolia_woo_indexer_index_in_stock_output'),
146 146
 					'algolia_woo_indexer',
147 147
 					'algolia_woo_indexer_main'
148 148
 				);
149 149
 				add_settings_field(
150 150
 					'algolia_woo_indexer_automatically_send_new_products',
151
-					esc_html__( 'Automatically index new products', 'algolia-woo-indexer' ),
152
-					array( $algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output' ),
151
+					esc_html__('Automatically index new products', 'algolia-woo-indexer'),
152
+					array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'),
153 153
 					'algolia_woo_indexer',
154 154
 					'algolia_woo_indexer_main'
155 155
 				);
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 		 * @return void
165 165
 		 */
166 166
 		public static function algolia_woo_indexer_admin_api_key_output() {
167
-			$api_key = get_option( ALGOWOO_DB_OPTION . ALGOLIA_API_KEY );
167
+			$api_key = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
168 168
 			$api_key = is_string($api_key) ? $api_key : CHANGE_ME;
169 169
 
170
-			wp_nonce_field( 'algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name' );
170
+			wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name');
171 171
 
172 172
 			echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]'
173
-				type='text' value='" . esc_attr( $api_key ) . "' />";
173
+				type='text' value='" . esc_attr($api_key) . "' />";
174 174
 		}
175 175
 
176 176
 		/**
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 		 * @return void
180 180
 		 */
181 181
 		public static function algolia_woo_indexer_application_id_output() {
182
-			$application_id = get_option( ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID );
182
+			$application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID);
183 183
 			$application_id = is_string($application_id) ? $application_id : CHANGE_ME;
184 184
 
185 185
 			echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]'
186
-				type='text' value='" . esc_attr( $application_id ) . "' />";
186
+				type='text' value='" . esc_attr($application_id) . "' />";
187 187
 		}
188 188
 
189 189
 		/**
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 		 * @return void
193 193
 		 */
194 194
 		public static function algolia_woo_indexer_index_name_output() {
195
-			$index_name = get_option( ALGOWOO_DB_OPTION . INDEX_NAME );
195
+			$index_name = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
196 196
 			$index_name = is_string($index_name) ? $index_name : CHANGE_ME;
197 197
 
198 198
 			echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]'
199
-				type='text' value='" . esc_attr( $index_name ) . "' />";
199
+				type='text' value='" . esc_attr($index_name) . "' />";
200 200
 		}
201 201
 
202 202
 		/**
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 			 * Sanitization is not really needed as the variable is not directly echoed
210 210
 			 * But I have still done it to be 100% safe
211 211
 			 */
212
-			$index_in_stock = get_option( ALGOWOO_DB_OPTION . INDEX_IN_STOCK );
213
-			$index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0;
212
+			$index_in_stock = get_option(ALGOWOO_DB_OPTION . INDEX_IN_STOCK);
213
+			$index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0;
214 214
 			?>
215 215
 			<input id="algolia_woo_indexer_index_in_stock" name="algolia_woo_indexer_index_in_stock[checked]"
216
-			type="checkbox" <?php checked( 1, $index_in_stock ); ?> />
216
+			type="checkbox" <?php checked(1, $index_in_stock); ?> />
217 217
 			<?php
218 218
 		}
219 219
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 			 * Sanitization is not really needed as the variable is not directly echoed
228 228
 			 * But I have still done it to be 100% safe
229 229
 			 */
230
-			$automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS );
231
-			$automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0;
230
+			$automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
231
+			$automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0;
232 232
 			?>
233 233
 			<input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]"
234
-			type="checkbox" <?php checked( 1, $automatically_send_new_products ); ?> />
234
+			type="checkbox" <?php checked(1, $automatically_send_new_products); ?> />
235 235
 			<?php
236 236
 		}
237 237
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		 * @return void
242 242
 		 */
243 243
 		public static function algolia_woo_indexer_section_text() {
244
-			echo esc_html__( 'Enter your settings here', 'algolia-woo-indexer' );
244
+			echo esc_html__('Enter your settings here', 'algolia-woo-indexer');
245 245
 		}
246 246
 
247 247
 		/**
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		 */
252 252
 		public static function maybe_send_products() {
253 253
 
254
-			if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) {
254
+			if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) {
255 255
 				self::send_products_to_algolia();	
256 256
 			}
257 257
 		}
@@ -266,19 +266,19 @@  discard block
 block discarded – undo
266 266
 			/**
267 267
 			 * Fetch the option to see if we are going to automatically send new products
268 268
 			 */
269
-			$automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS );
269
+			$automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
270 270
 
271 271
 			/**
272 272
 			 * Check that we have the minimum versions required and all of the required PHP extensions
273 273
 			 */
274 274
 			Algolia_Check_Requirements::check_unmet_requirements();
275 275
 
276
-			if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check() ) {
276
+			if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check()) {
277 277
 				add_action(
278 278
 					'admin_notices',
279
-					function () {
279
+					function() {
280 280
 						echo '<div class="error notice">
281
-                                  <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>
281
+                                  <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>
282 282
                                 </div>';
283 283
 					}
284 284
 				);
@@ -289,33 +289,33 @@  discard block
 block discarded – undo
289 289
 			/**
290 290
 			 * Setup translations
291 291
 			 */
292
-			add_action( 'plugins_loaded', array( $ob_class, 'load_textdomain' ) );
292
+			add_action('plugins_loaded', array($ob_class, 'load_textdomain'));
293 293
 
294 294
 			/**
295 295
 			 * Add actions to setup admin menu
296 296
 			 */
297
-			if ( is_admin() ) {
298
-				add_action( 'admin_menu', array( $ob_class, 'admin_menu' ) );
299
-				add_action( 'admin_init', array( $ob_class, 'setup_settings_sections' ) );
300
-				add_action( 'admin_init', array( $ob_class, 'update_settings_options' ) );
301
-				add_action( 'admin_init', array( $ob_class, 'maybe_send_products' ) );
297
+			if (is_admin()) {
298
+				add_action('admin_menu', array($ob_class, 'admin_menu'));
299
+				add_action('admin_init', array($ob_class, 'setup_settings_sections'));
300
+				add_action('admin_init', array($ob_class, 'update_settings_options'));
301
+				add_action('admin_init', array($ob_class, 'maybe_send_products'));
302 302
 
303 303
 				/**
304 304
 				 * Register hook to automatically send new products if the option is set
305 305
 				 */
306 306
 
307
-				if ( '1' === $automatically_send_new_products ) {
308
-					add_action( 'save_post', array( $ob_class, 'send_new_product_to_algolia' ), 10, 3 );
307
+				if ('1' === $automatically_send_new_products) {
308
+					add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3);
309 309
 				}
310 310
 
311
-				self::$plugin_url = admin_url( 'options-general.php?page=algolia-woo-indexer-settings' );
311
+				self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings');
312 312
 
313
-				if ( ! is_plugin_active('woocommerce/woocommerce.php') ) {
313
+				if ( ! is_plugin_active('woocommerce/woocommerce.php')) {
314 314
 					add_action(
315 315
 						'admin_notices',
316
-						function () {
316
+						function() {
317 317
 							echo '<div class="error notice">
318
-								  <p>' . esc_html__( 'WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer' ) . '</p>
318
+								  <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p>
319 319
 								</div>';
320 320
 						}
321 321
 					);
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
 		 *
332 332
 		 * @return void
333 333
 		 */
334
-		public static function send_new_product_to_algolia( $post_id, $post ) {
334
+		public static function send_new_product_to_algolia($post_id, $post) {
335 335
 
336
-			if ( 'publish' !== $post->post_status || 'product' !== $post->post_type ) {
336
+			if ('publish' !== $post->post_status || 'product' !== $post->post_type) {
337 337
 				return;
338 338
 			}
339
-			self::send_products_to_algolia( $post_id );
339
+			self::send_products_to_algolia($post_id);
340 340
 		}
341 341
 
342 342
 		/**
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 			/**
353 353
 			 * Do not proceed if we are going to send products
354 354
 			 */
355
-			if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) {
355
+			if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) {
356 356
 				return;
357 357
 			}
358 358
 
@@ -361,26 +361,26 @@  discard block
 block discarded – undo
361 361
 			 *
362 362
 			 * @see https://www.php.net/manual/en/function.filter-input.php
363 363
 			 */
364
-			$post_application_id             = filter_input( INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
365
-			$post_api_key                    = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
366
-			$post_index_name                 = filter_input( INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
367
-			$index_in_stock                  = filter_input( INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
368
-			$automatically_send_new_products = filter_input( INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
364
+			$post_application_id             = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
365
+			$post_api_key                    = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
366
+			$post_index_name                 = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
367
+			$index_in_stock                  = filter_input(INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
368
+			$automatically_send_new_products = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
369 369
 
370 370
 			/**
371 371
 			 * Properly sanitize text fields before updating data
372 372
 			 *
373 373
 			 * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/
374 374
 			 */
375
-			$filtered_application_id = sanitize_text_field( $post_application_id['id'] );
376
-			$filtered_api_key        = sanitize_text_field( $post_api_key['key'] );
377
-			$filtered_index_name     = sanitize_text_field( $post_index_name['name'] );
375
+			$filtered_application_id = sanitize_text_field($post_application_id['id']);
376
+			$filtered_api_key        = sanitize_text_field($post_api_key['key']);
377
+			$filtered_index_name     = sanitize_text_field($post_index_name['name']);
378 378
 
379 379
 			/**
380 380
 			 * Sanitizing by setting the value to either 1 or 0
381 381
 			 */
382
-			$filtered_index_in_stock                  = ( ! empty( $index_in_stock ) ) ? 1 : 0;
383
-			$filtered_automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0;
382
+			$filtered_index_in_stock                  = ( ! empty($index_in_stock)) ? 1 : 0;
383
+			$filtered_automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0;
384 384
 
385 385
 			/**
386 386
 			 * Values have been filtered and sanitized
@@ -388,35 +388,35 @@  discard block
 block discarded – undo
388 388
 			 *
389 389
 			 * @see https://developer.wordpress.org/reference/functions/update_option/
390 390
 			 */
391
-			if ( isset( $filtered_application_id ) && ( ! empty( $filtered_application_id ) ) ) {
391
+			if (isset($filtered_application_id) && ( ! empty($filtered_application_id))) {
392 392
 				update_option(
393 393
 					ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID,
394 394
 					$filtered_application_id
395 395
 				);
396 396
 			}
397 397
 
398
-			if ( isset( $filtered_api_key ) && ( ! empty( $filtered_api_key ) ) ) {
398
+			if (isset($filtered_api_key) && ( ! empty($filtered_api_key))) {
399 399
 				update_option(
400 400
 					ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
401 401
 					$filtered_api_key
402 402
 				);
403 403
 			}
404 404
 
405
-			if ( isset( $filtered_index_name ) && ( ! empty( $filtered_index_name ) ) ) {
405
+			if (isset($filtered_index_name) && ( ! empty($filtered_index_name))) {
406 406
 				update_option(
407 407
 					ALGOWOO_DB_OPTION . INDEX_NAME,
408 408
 					$filtered_index_name
409 409
 				);
410 410
 			}
411 411
 
412
-			if ( isset( $filtered_index_in_stock ) && ( ! empty( $filtered_index_in_stock ) ) ) {
412
+			if (isset($filtered_index_in_stock) && ( ! empty($filtered_index_in_stock))) {
413 413
 				update_option(
414 414
 					ALGOWOO_DB_OPTION . INDEX_IN_STOCK,
415 415
 					$filtered_index_in_stock
416 416
 				);
417 417
 			}
418 418
 
419
-			if ( isset( $filtered_automatically_send_new_products ) && ( ! empty( $filtered_automatically_send_new_products ) ) ) {
419
+			if (isset($filtered_automatically_send_new_products) && ( ! empty($filtered_automatically_send_new_products))) {
420 420
 				update_option(
421 421
 					ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS,
422 422
 					$filtered_automatically_send_new_products
@@ -430,33 +430,33 @@  discard block
 block discarded – undo
430 430
 		 * @param Int $id Product to send to Algolia if we send only a single product
431 431
 		 * @return void
432 432
 		 */
433
-		public static function send_products_to_algolia( $id = '' ) {
433
+		public static function send_products_to_algolia($id = '') {
434 434
 			/**
435 435
 			 * Remove classes from plugin URL and autoload Algolia with Composer
436 436
 			 */
437 437
 
438
-			$base_plugin_directory = str_replace( 'classes', '', dirname( __FILE__ ) );
438
+			$base_plugin_directory = str_replace('classes', '', dirname(__FILE__));
439 439
 			require_once $base_plugin_directory . '/vendor/autoload.php';
440 440
 
441 441
 			/**
442 442
 			 * Fetch the required variables from the Settings API
443 443
 			 */
444 444
 
445
-			$algolia_application_id = get_option( ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID );
446
-			$algolia_api_key        = get_option( ALGOWOO_DB_OPTION . ALGOLIA_API_KEY );
447
-			$algolia_index_name     = get_option( ALGOWOO_DB_OPTION . INDEX_NAME );
445
+			$algolia_application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID);
446
+			$algolia_api_key        = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
447
+			$algolia_index_name     = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
448 448
 
449
-			$index_in_stock = get_option( ALGOWOO_DB_OPTION . INDEX_IN_STOCK );
449
+			$index_in_stock = get_option(ALGOWOO_DB_OPTION . INDEX_IN_STOCK);
450 450
 
451 451
 			/**
452 452
 			 * Display admin notice and return if not all values have been set
453 453
 			 */
454
-			if ( empty( $algolia_application_id ) || empty( $algolia_api_key || empty( $algolia_index_name ) ) ) {
454
+			if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) {
455 455
 				add_action(
456 456
 					'admin_notices',
457
-					function () {
457
+					function() {
458 458
 						echo '<div class="error notice">
459
-							  <p>' . esc_html__( 'All settings need to be set for the plugin to work.', 'algolia-woo-indexer' ) . '</p>
459
+							  <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p>
460 460
 							</div>';
461 461
 					}
462 462
 				);
@@ -466,19 +466,19 @@  discard block
 block discarded – undo
466 466
 			/**
467 467
 			 * Initiate the Algolia client
468 468
 			 */
469
-			self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create( $algolia_application_id, $algolia_api_key );
469
+			self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key);
470 470
 
471 471
 			/**
472 472
 			 * Check if we can connect, if not, handle the exception, display an error and then return
473 473
 			 */
474 474
 			try {
475 475
 				self::$algolia->listApiKeys();
476
-			} catch ( \Algolia\AlgoliaSearch\Exceptions\UnreachableException $error ) {
476
+			} catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) {
477 477
 				add_action(
478 478
 					'admin_notices',
479
-					function () {
479
+					function() {
480 480
 						echo '<div class="error notice">
481
-							  <p>' . esc_html__( 'An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer' ) . '</p>
481
+							  <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p>
482 482
 							</div>';
483 483
 					}
484 484
 				);
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 			/**
489 489
 			 * Initialize the search index and set the name to the option from the database
490 490
 			 */
491
-			$index = self::$algolia->initIndex( $algolia_index_name );
491
+			$index = self::$algolia->initIndex($algolia_index_name);
492 492
 
493 493
 			/**
494 494
 			 * Setup arguments for sending all products to Algolia
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
 			/**
505 505
 			* Setup arguments for sending only a single product
506 506
 			*/
507
-			if ( isset( $id ) && '' !== $id ) {
507
+			if (isset($id) && '' !== $id) {
508 508
 				$arguments = array(
509 509
 					'status'   => 'publish',
510
-					'include'  => array( $id ),
510
+					'include'  => array($id),
511 511
 					'paginate' => false,
512 512
 				);
513 513
 			}
@@ -517,17 +517,17 @@  discard block
 block discarded – undo
517 517
 			 *
518 518
 			 * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html
519 519
 			 */
520
-			$products = /** @scrutinizer ignore-call */ wc_get_products( $arguments );
520
+			$products = /** @scrutinizer ignore-call */ wc_get_products($arguments);
521 521
 
522
-			if ( $products ) {
522
+			if ($products) {
523 523
 				$records = array();
524 524
 				$record  = array();
525 525
 
526
-				foreach ( $products as $product ) {
526
+				foreach ($products as $product) {
527 527
 					/**
528 528
 					 * Check if product is in stock if $index_in_stock is set to 1
529 529
 					 */
530
-					if ( '1' === $index_in_stock && $product->is_in_stock() ) {
530
+					if ('1' === $index_in_stock && $product->is_in_stock()) {
531 531
 						/**
532 532
 						 * Extract image from $product->get_image()
533 533
 						 */
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 					/**
550 550
 					 * Do not check if product is in stock if $index_in_stock is set to 0
551 551
 					 */
552
-					if ( '0' === $index_in_stock ) {
552
+					if ('0' === $index_in_stock) {
553 553
 						/**
554 554
 						 * Extract image from $product->get_image()
555 555
 						 */
@@ -577,14 +577,14 @@  discard block
 block discarded – undo
577 577
 			 * Send the information to Algolia and save the result
578 578
 			 * If result is NullResponse, print an error message
579 579
 			 */
580
-			$result = $index->saveObjects( $records );
580
+			$result = $index->saveObjects($records);
581 581
 
582
-			if ( 'Algolia\AlgoliaSearch\Response\NullResponse' === get_class( $result ) ) {
582
+			if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) {
583 583
 				add_action(
584 584
 					'admin_notices',
585
-					function () {
585
+					function() {
586 586
 						echo '<div class="error notice is-dismissible">
587
-							  <p>' . esc_html__( 'No response from the server. Please check your settings and try again ', 'algolia-woo-indexer' ) . '</p>
587
+							  <p>' . esc_html__('No response from the server. Please check your settings and try again ', 'algolia-woo-indexer') . '</p>
588 588
 							</div>';
589 589
 					}
590 590
 				);
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 			 * Display success message
596 596
 			 */
597 597
 			echo '<div class="notice notice-success is-dismissible">
598
-					 	<p>' . esc_html__( 'Product(s) sent to Algolia.', 'algolia-woo-indexer' ) . '</p>
598
+					 	<p>' . esc_html__('Product(s) sent to Algolia.', 'algolia-woo-indexer') . '</p>
599 599
 				  		</div>';
600 600
 		}
601 601
 
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 		 * @param string $input Settings text data
606 606
 		 * @return array
607 607
 		 */
608
-		public static function settings_fields_validate_options( $input ) {
608
+		public static function settings_fields_validate_options($input) {
609 609
 			$valid         = array();
610 610
 			$valid['name'] = preg_replace(
611 611
 				'/[^a-zA-Z\s]/',
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 		 * @return void
622 622
 		 */
623 623
 		public static function load_textdomain() {
624
-			load_plugin_textdomain( 'algolia-woo-indexer', false, basename( dirname( __FILE__ ) ) . '/languages/' );
624
+			load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/');
625 625
 		}
626 626
 
627 627
 		/**
@@ -632,11 +632,11 @@  discard block
 block discarded – undo
632 632
 		public static function admin_menu() {
633 633
 			add_submenu_page(
634 634
 				'options-general.php',
635
-				esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ),
636
-				esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ),
635
+				esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'),
636
+				esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'),
637 637
 				'manage_options',
638 638
 				'algolia-woo-indexer-settings',
639
-				array( get_called_class(), 'algolia_woo_indexer_settings' )
639
+				array(get_called_class(), 'algolia_woo_indexer_settings')
640 640
 			);
641 641
 		}
642 642
 
@@ -649,23 +649,23 @@  discard block
 block discarded – undo
649 649
 			/**
650 650
 			* Verify that the user can access the settings page
651 651
 			*/
652
-			if ( ! current_user_can( 'manage_options' ) ) {
653
-				wp_die( esc_html__( 'Action not allowed.', 'algolia_woo_indexer_settings' ) );
652
+			if ( ! current_user_can('manage_options')) {
653
+				wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings'));
654 654
 			}
655 655
 			?>
656 656
 			<div class="wrap">
657
-				<h1><?php esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ); ?></h1>
658
-				<form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST">
657
+				<h1><?php esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'); ?></h1>
658
+				<form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST">
659 659
 			<?php
660
-			settings_fields( 'algolia_woo_options' );
661
-			do_settings_sections( 'algolia_woo_indexer' );
662
-			submit_button( '', 'primary wide' );
660
+			settings_fields('algolia_woo_options');
661
+			do_settings_sections('algolia_woo_indexer');
662
+			submit_button('', 'primary wide');
663 663
 			?>
664 664
 				</form>
665
-				<form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST">
666
-					<?php wp_nonce_field( 'send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name' ); ?>
665
+				<form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST">
666
+					<?php wp_nonce_field('send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name'); ?>
667 667
 					<input type="hidden" name="send_products_to_algolia" id="send_products_to_algolia" value="true" />
668
-					<?php submit_button( esc_html__( 'Send products to Algolia', 'algolia_woo_indexer_settings' ), 'primary wide', '', false ); ?>
668
+					<?php submit_button(esc_html__('Send products to Algolia', 'algolia_woo_indexer_settings'), 'primary wide', '', false); ?>
669 669
 				</form>
670 670
 			</div>
671 671
 			<?php
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
 		 * @return object
678 678
 		 */
679 679
 		public static function get_instance() {
680
-			if ( ! self::$instance ) {
680
+			if ( ! self::$instance) {
681 681
 				self::$instance = new Algolia_Woo_Indexer();
682 682
 			}
683 683
 			return self::$instance;
@@ -693,47 +693,47 @@  discard block
 block discarded – undo
693 693
 			/**
694 694
 			 * Set default values for options if not already set
695 695
 			 */
696
-			$index_in_stock                  = get_option( ALGOWOO_DB_OPTION . INDEX_IN_STOCK );
697
-			$automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS );
698
-			$algolia_application_id          = get_option( ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID );
699
-			$algolia_api_key                 = get_option( ALGOWOO_DB_OPTION . ALGOLIA_API_KEY );
700
-			$algolia_index_name              = get_option( ALGOWOO_DB_OPTION . INDEX_NAME );
696
+			$index_in_stock                  = get_option(ALGOWOO_DB_OPTION . INDEX_IN_STOCK);
697
+			$automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS);
698
+			$algolia_application_id          = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID);
699
+			$algolia_api_key                 = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY);
700
+			$algolia_index_name              = get_option(ALGOWOO_DB_OPTION . INDEX_NAME);
701 701
 
702
-			if ( empty( $index_in_stock ) ) {
702
+			if (empty($index_in_stock)) {
703 703
 				add_option(
704 704
 					ALGOWOO_DB_OPTION . INDEX_IN_STOCK,
705 705
 					'0'
706 706
 				);
707 707
 			}
708 708
 
709
-			if ( empty( $automatically_send_new_products ) ) {
709
+			if (empty($automatically_send_new_products)) {
710 710
 				add_option(
711 711
 					ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS,
712 712
 					'0'
713 713
 				);
714 714
 			}
715 715
 
716
-			if ( empty( $algolia_application_id ) ) {
716
+			if (empty($algolia_application_id)) {
717 717
 				add_option(
718 718
 					ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID,
719 719
 					'Change me'
720 720
 				);
721 721
 			}
722 722
 
723
-			if ( empty( $algolia_api_key ) ) {
723
+			if (empty($algolia_api_key)) {
724 724
 				add_option(
725 725
 					ALGOWOO_DB_OPTION . ALGOLIA_API_KEY,
726 726
 					'Change me'
727 727
 				);
728 728
 			}
729 729
 
730
-			if ( empty( $algolia_index_name ) ) {
730
+			if (empty($algolia_index_name)) {
731 731
 				add_option(
732 732
 					ALGOWOO_DB_OPTION . INDEX_NAME,
733 733
 					'Change me'
734 734
 				);
735 735
 			}
736
-			set_transient( self::PLUGIN_TRANSIENT, true );
736
+			set_transient(self::PLUGIN_TRANSIENT, true);
737 737
 		}
738 738
 
739 739
 		/**
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 		 * @return void
743 743
 		 */
744 744
 		public static function deactivate_plugin() {
745
-			delete_transient( self::PLUGIN_TRANSIENT, true );
745
+			delete_transient(self::PLUGIN_TRANSIENT, true);
746 746
 		}
747 747
 	}
748 748
 }
Please login to merge, or discard this patch.