@@ -14,24 +14,24 @@ discard block |
||
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 | -if ( ! class_exists( 'Algolia_Woo_Indexer' ) ) { |
|
34 | +if ( ! class_exists('Algolia_Woo_Indexer')) { |
|
35 | 35 | /** |
36 | 36 | * Algolia WooIndexer main class |
37 | 37 | */ |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @see https://developer.wordpress.org/reference/functions/register_setting/ |
83 | 83 | */ |
84 | - if ( is_admin() ) { |
|
84 | + if (is_admin()) { |
|
85 | 85 | $arguments = array( |
86 | 86 | 'type' => 'string', |
87 | 87 | 'sanitize_callback' => 'settings_fields_validate_options', |
88 | 88 | 'default' => null, |
89 | 89 | ); |
90 | - register_setting( 'algolia_woo_options', 'algolia_woo_options', $arguments ); |
|
90 | + register_setting('algolia_woo_options', 'algolia_woo_options', $arguments); |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Make sure we reference the instance of the current class by using self::get_instance() |
@@ -100,42 +100,42 @@ discard block |
||
100 | 100 | */ |
101 | 101 | add_settings_section( |
102 | 102 | 'algolia_woo_indexer_main', |
103 | - esc_html__( 'Algolia Woo Plugin Settings', 'algolia-woo-indexer' ), |
|
104 | - array( $algowooindexer, 'algolia_woo_indexer_section_text' ), |
|
103 | + esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'), |
|
104 | + array($algowooindexer, 'algolia_woo_indexer_section_text'), |
|
105 | 105 | 'algolia_woo_indexer' |
106 | 106 | ); |
107 | 107 | add_settings_field( |
108 | 108 | 'algolia_woo_indexer_application_id', |
109 | - esc_html__( 'Application ID', 'algolia-woo-indexer' ), |
|
110 | - array( $algowooindexer, 'algolia_woo_indexer_application_id_output' ), |
|
109 | + esc_html__('Application ID', 'algolia-woo-indexer'), |
|
110 | + array($algowooindexer, 'algolia_woo_indexer_application_id_output'), |
|
111 | 111 | 'algolia_woo_indexer', |
112 | 112 | 'algolia_woo_indexer_main' |
113 | 113 | ); |
114 | 114 | add_settings_field( |
115 | 115 | 'algolia_woo_indexer_admin_api_key', |
116 | - esc_html__( 'Admin API Key', 'algolia-woo-indexer' ), |
|
117 | - array( $algowooindexer, 'algolia_woo_indexer_admin_api_key_output' ), |
|
116 | + esc_html__('Admin API Key', 'algolia-woo-indexer'), |
|
117 | + array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'), |
|
118 | 118 | 'algolia_woo_indexer', |
119 | 119 | 'algolia_woo_indexer_main' |
120 | 120 | ); |
121 | 121 | add_settings_field( |
122 | 122 | 'algolia_woo_indexer_index_name', |
123 | - esc_html__( 'Index name (will be created if not existing)', 'algolia-woo-indexer' ), |
|
124 | - array( $algowooindexer, 'algolia_woo_indexer_index_name_output' ), |
|
123 | + esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'), |
|
124 | + array($algowooindexer, 'algolia_woo_indexer_index_name_output'), |
|
125 | 125 | 'algolia_woo_indexer', |
126 | 126 | 'algolia_woo_indexer_main' |
127 | 127 | ); |
128 | 128 | add_settings_field( |
129 | 129 | 'algolia_woo_indexer_index_in_stock', |
130 | - esc_html__( 'Only index products in stock', 'algolia-woo-indexer' ), |
|
131 | - array( $algowooindexer, 'algolia_woo_indexer_index_in_stock_output' ), |
|
130 | + esc_html__('Only index products in stock', 'algolia-woo-indexer'), |
|
131 | + array($algowooindexer, 'algolia_woo_indexer_index_in_stock_output'), |
|
132 | 132 | 'algolia_woo_indexer', |
133 | 133 | 'algolia_woo_indexer_main' |
134 | 134 | ); |
135 | 135 | add_settings_field( |
136 | 136 | 'algolia_woo_indexer_automatically_send_new_products', |
137 | - esc_html__( 'Automatically index new products', 'algolia-woo-indexer' ), |
|
138 | - array( $algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output' ), |
|
137 | + esc_html__('Automatically index new products', 'algolia-woo-indexer'), |
|
138 | + array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'), |
|
139 | 139 | 'algolia_woo_indexer', |
140 | 140 | 'algolia_woo_indexer_main' |
141 | 141 | ); |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | * @return void |
151 | 151 | */ |
152 | 152 | public static function algolia_woo_indexer_admin_api_key_output() { |
153 | - $api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
153 | + $api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
154 | 154 | $api_key = is_string($api_key) ? $api_key : "change me"; |
155 | 155 | |
156 | - wp_nonce_field( 'algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name' ); |
|
156 | + wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name'); |
|
157 | 157 | |
158 | 158 | echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]' |
159 | - type='text' value='" . esc_attr( $api_key ) . "' />"; |
|
159 | + type='text' value='" . esc_attr($api_key) . "' />"; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | * @return void |
166 | 166 | */ |
167 | 167 | public static function algolia_woo_indexer_application_id_output() { |
168 | - $application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
168 | + $application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
169 | 169 | $application_id = is_string($application_id) ? $application_id : "change me"; |
170 | 170 | |
171 | 171 | echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]' |
172 | - type='text' value='" . esc_attr( $application_id ) . "' />"; |
|
172 | + type='text' value='" . esc_attr($application_id) . "' />"; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | * @return void |
179 | 179 | */ |
180 | 180 | public static function algolia_woo_indexer_index_name_output() { |
181 | - $index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
181 | + $index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
182 | 182 | $index_name = is_string($index_name) ? $index_name : "change me"; |
183 | 183 | |
184 | 184 | echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]' |
185 | - type='text' value='" . esc_attr( $index_name ) . "' />"; |
|
185 | + type='text' value='" . esc_attr($index_name) . "' />"; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * Sanitization is not really needed as the variable is not directly echoed |
196 | 196 | * But I have still done it to be 100% safe |
197 | 197 | */ |
198 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
199 | - $index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0; |
|
198 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
199 | + $index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0; |
|
200 | 200 | ?> |
201 | 201 | <input id="algolia_woo_indexer_index_in_stock" name="algolia_woo_indexer_index_in_stock[checked]" |
202 | - type="checkbox" <?php checked( 1, $index_in_stock ); ?> /> |
|
202 | + type="checkbox" <?php checked(1, $index_in_stock); ?> /> |
|
203 | 203 | <?php |
204 | 204 | } |
205 | 205 | |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | * Sanitization is not really needed as the variable is not directly echoed |
214 | 214 | * But I have still done it to be 100% safe |
215 | 215 | */ |
216 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
217 | - $automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
216 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
217 | + $automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
218 | 218 | ?> |
219 | 219 | <input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]" |
220 | - type="checkbox" <?php checked( 1, $automatically_send_new_products ); ?> /> |
|
220 | + type="checkbox" <?php checked(1, $automatically_send_new_products); ?> /> |
|
221 | 221 | <?php |
222 | 222 | } |
223 | 223 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @return void |
228 | 228 | */ |
229 | 229 | public static function algolia_woo_indexer_section_text() { |
230 | - echo esc_html__( 'Enter your settings here', 'algolia-woo-indexer' ); |
|
230 | + echo esc_html__('Enter your settings here', 'algolia-woo-indexer'); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public static function maybe_send_products() { |
239 | 239 | |
240 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
240 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
241 | 241 | self::send_products_to_algolia(); |
242 | 242 | } |
243 | 243 | } |
@@ -252,19 +252,19 @@ discard block |
||
252 | 252 | /** |
253 | 253 | * Fetch the option to see if we are going to automatically send new products |
254 | 254 | */ |
255 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
255 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
256 | 256 | |
257 | 257 | /** |
258 | 258 | * Check that we have the minimum versions required and all of the required PHP extensions |
259 | 259 | */ |
260 | 260 | Algolia_Check_Requirements::check_unmet_requirements(); |
261 | 261 | |
262 | - if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check() ) { |
|
262 | + if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check()) { |
|
263 | 263 | add_action( |
264 | 264 | 'admin_notices', |
265 | - function () { |
|
265 | + function() { |
|
266 | 266 | echo '<div class="error notice"> |
267 | - <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> |
|
267 | + <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> |
|
268 | 268 | </div>'; |
269 | 269 | } |
270 | 270 | ); |
@@ -275,33 +275,33 @@ discard block |
||
275 | 275 | /** |
276 | 276 | * Setup translations |
277 | 277 | */ |
278 | - add_action( 'plugins_loaded', array( $ob_class, 'load_textdomain' ) ); |
|
278 | + add_action('plugins_loaded', array($ob_class, 'load_textdomain')); |
|
279 | 279 | |
280 | 280 | /** |
281 | 281 | * Add actions to setup admin menu |
282 | 282 | */ |
283 | - if ( is_admin() ) { |
|
284 | - add_action( 'admin_menu', array( $ob_class, 'admin_menu' ) ); |
|
285 | - add_action( 'admin_init', array( $ob_class, 'setup_settings_sections' ) ); |
|
286 | - add_action( 'admin_init', array( $ob_class, 'update_settings_options' ) ); |
|
287 | - add_action( 'admin_init', array( $ob_class, 'maybe_send_products' ) ); |
|
283 | + if (is_admin()) { |
|
284 | + add_action('admin_menu', array($ob_class, 'admin_menu')); |
|
285 | + add_action('admin_init', array($ob_class, 'setup_settings_sections')); |
|
286 | + add_action('admin_init', array($ob_class, 'update_settings_options')); |
|
287 | + add_action('admin_init', array($ob_class, 'maybe_send_products')); |
|
288 | 288 | |
289 | 289 | /** |
290 | 290 | * Register hook to automatically send new products if the option is set |
291 | 291 | */ |
292 | 292 | |
293 | - if ( '1' === $automatically_send_new_products ) { |
|
294 | - add_action( 'save_post', array( $ob_class, 'send_new_product_to_algolia' ), 10, 3 ); |
|
293 | + if ('1' === $automatically_send_new_products) { |
|
294 | + add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3); |
|
295 | 295 | } |
296 | 296 | |
297 | - self::$plugin_url = admin_url( 'options-general.php?page=algolia-woo-indexer-settings' ); |
|
297 | + self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings'); |
|
298 | 298 | |
299 | - if ( ! is_plugin_active('woocommerce/woocommerce.php') ) { |
|
299 | + if ( ! is_plugin_active('woocommerce/woocommerce.php')) { |
|
300 | 300 | add_action( |
301 | 301 | 'admin_notices', |
302 | - function () { |
|
302 | + function() { |
|
303 | 303 | echo '<div class="error notice"> |
304 | - <p>' . esc_html__( 'WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer' ) . '</p> |
|
304 | + <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p> |
|
305 | 305 | </div>'; |
306 | 306 | } |
307 | 307 | ); |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @return void |
319 | 319 | */ |
320 | - public static function send_new_product_to_algolia( $post_id, $post ) { |
|
320 | + public static function send_new_product_to_algolia($post_id, $post) { |
|
321 | 321 | |
322 | - if ( 'publish' !== $post->post_status || 'product' !== $post->post_type ) { |
|
322 | + if ('publish' !== $post->post_status || 'product' !== $post->post_type) { |
|
323 | 323 | return; |
324 | 324 | } |
325 | - self::send_products_to_algolia( $post_id ); |
|
325 | + self::send_products_to_algolia($post_id); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | /** |
339 | 339 | * Do not proceed if we are going to send products |
340 | 340 | */ |
341 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
341 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
342 | 342 | return; |
343 | 343 | } |
344 | 344 | |
@@ -347,26 +347,26 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @see https://www.php.net/manual/en/function.filter-input.php |
349 | 349 | */ |
350 | - $post_application_id = filter_input( INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
351 | - $post_api_key = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
352 | - $post_index_name = filter_input( INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
353 | - $index_in_stock = filter_input( INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
354 | - $automatically_send_new_products = filter_input( INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
350 | + $post_application_id = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
351 | + $post_api_key = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
352 | + $post_index_name = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
353 | + $index_in_stock = filter_input(INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
354 | + $automatically_send_new_products = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * Properly sanitize text fields before updating data |
358 | 358 | * |
359 | 359 | * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/ |
360 | 360 | */ |
361 | - $filtered_application_id = sanitize_text_field( $post_application_id['id'] ); |
|
362 | - $filtered_api_key = sanitize_text_field( $post_api_key['key'] ); |
|
363 | - $filtered_index_name = sanitize_text_field( $post_index_name['name'] ); |
|
361 | + $filtered_application_id = sanitize_text_field($post_application_id['id']); |
|
362 | + $filtered_api_key = sanitize_text_field($post_api_key['key']); |
|
363 | + $filtered_index_name = sanitize_text_field($post_index_name['name']); |
|
364 | 364 | |
365 | 365 | /** |
366 | 366 | * Sanitizing by setting the value to either 1 or 0 |
367 | 367 | */ |
368 | - $filtered_index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0; |
|
369 | - $filtered_automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
368 | + $filtered_index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0; |
|
369 | + $filtered_automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
370 | 370 | |
371 | 371 | /** |
372 | 372 | * Values have been filtered and sanitized |
@@ -374,35 +374,35 @@ discard block |
||
374 | 374 | * |
375 | 375 | * @see https://developer.wordpress.org/reference/functions/update_option/ |
376 | 376 | */ |
377 | - if ( isset( $filtered_application_id ) && ( ! empty( $filtered_application_id ) ) ) { |
|
377 | + if (isset($filtered_application_id) && ( ! empty($filtered_application_id))) { |
|
378 | 378 | update_option( |
379 | 379 | ALGOWOO_DB_OPTION . '_application_id', |
380 | 380 | $filtered_application_id |
381 | 381 | ); |
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $filtered_api_key ) && ( ! empty( $filtered_api_key ) ) ) { |
|
384 | + if (isset($filtered_api_key) && ( ! empty($filtered_api_key))) { |
|
385 | 385 | update_option( |
386 | 386 | ALGOWOO_DB_OPTION . '_admin_api_key', |
387 | 387 | $filtered_api_key |
388 | 388 | ); |
389 | 389 | } |
390 | 390 | |
391 | - if ( isset( $filtered_index_name ) && ( ! empty( $filtered_index_name ) ) ) { |
|
391 | + if (isset($filtered_index_name) && ( ! empty($filtered_index_name))) { |
|
392 | 392 | update_option( |
393 | 393 | ALGOWOO_DB_OPTION . '_index_name', |
394 | 394 | $filtered_index_name |
395 | 395 | ); |
396 | 396 | } |
397 | 397 | |
398 | - if ( isset( $filtered_index_in_stock ) && ( ! empty( $filtered_index_in_stock ) ) ) { |
|
398 | + if (isset($filtered_index_in_stock) && ( ! empty($filtered_index_in_stock))) { |
|
399 | 399 | update_option( |
400 | 400 | ALGOWOO_DB_OPTION . '_index_in_stock', |
401 | 401 | $filtered_index_in_stock |
402 | 402 | ); |
403 | 403 | } |
404 | 404 | |
405 | - if ( isset( $filtered_automatically_send_new_products ) && ( ! empty( $filtered_automatically_send_new_products ) ) ) { |
|
405 | + if (isset($filtered_automatically_send_new_products) && ( ! empty($filtered_automatically_send_new_products))) { |
|
406 | 406 | update_option( |
407 | 407 | ALGOWOO_DB_OPTION . '_automatically_send_new_products', |
408 | 408 | $filtered_automatically_send_new_products |
@@ -416,33 +416,33 @@ discard block |
||
416 | 416 | * @param Int $id Product to send to Algolia if we send only a single product |
417 | 417 | * @return void |
418 | 418 | */ |
419 | - public static function send_products_to_algolia( $id = '' ) { |
|
419 | + public static function send_products_to_algolia($id = '') { |
|
420 | 420 | /** |
421 | 421 | * Remove classes from plugin URL and autoload Algolia with Composer |
422 | 422 | */ |
423 | 423 | |
424 | - $base_plugin_directory = str_replace( 'classes', '', dirname( __FILE__ ) ); |
|
424 | + $base_plugin_directory = str_replace('classes', '', dirname(__FILE__)); |
|
425 | 425 | require_once $base_plugin_directory . '/vendor/autoload.php'; |
426 | 426 | |
427 | 427 | /** |
428 | 428 | * Fetch the required variables from the Settings API |
429 | 429 | */ |
430 | 430 | |
431 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
432 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
433 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
431 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
432 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
433 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
434 | 434 | |
435 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
435 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
436 | 436 | |
437 | 437 | /** |
438 | 438 | * Display admin notice and return if not all values have been set |
439 | 439 | */ |
440 | - if ( empty( $algolia_application_id ) || empty( $algolia_api_key || empty( $algolia_index_name ) ) ) { |
|
440 | + if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) { |
|
441 | 441 | add_action( |
442 | 442 | 'admin_notices', |
443 | - function () { |
|
443 | + function() { |
|
444 | 444 | echo '<div class="error notice"> |
445 | - <p>' . esc_html__( 'All settings need to be set for the plugin to work.', 'algolia-woo-indexer' ) . '</p> |
|
445 | + <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p> |
|
446 | 446 | </div>'; |
447 | 447 | } |
448 | 448 | ); |
@@ -452,19 +452,19 @@ discard block |
||
452 | 452 | /** |
453 | 453 | * Initiate the Algolia client |
454 | 454 | */ |
455 | - self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create( $algolia_application_id, $algolia_api_key ); |
|
455 | + self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key); |
|
456 | 456 | |
457 | 457 | /** |
458 | 458 | * Check if we can connect, if not, handle the exception, display an error and then return |
459 | 459 | */ |
460 | 460 | try { |
461 | 461 | self::$algolia->listApiKeys(); |
462 | - } catch ( \Algolia\AlgoliaSearch\Exceptions\UnreachableException $error ) { |
|
462 | + } catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) { |
|
463 | 463 | add_action( |
464 | 464 | 'admin_notices', |
465 | - function () { |
|
465 | + function() { |
|
466 | 466 | echo '<div class="error notice"> |
467 | - <p>' . esc_html__( 'An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer' ) . '</p> |
|
467 | + <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p> |
|
468 | 468 | </div>'; |
469 | 469 | } |
470 | 470 | ); |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | /** |
475 | 475 | * Initialize the search index and set the name to the option from the database |
476 | 476 | */ |
477 | - $index = self::$algolia->initIndex( $algolia_index_name ); |
|
477 | + $index = self::$algolia->initIndex($algolia_index_name); |
|
478 | 478 | |
479 | 479 | /** |
480 | 480 | * Setup arguments for sending all products to Algolia |
@@ -490,10 +490,10 @@ discard block |
||
490 | 490 | /** |
491 | 491 | * Setup arguments for sending only a single product |
492 | 492 | */ |
493 | - if ( isset( $id ) && '' !== $id ) { |
|
493 | + if (isset($id) && '' !== $id) { |
|
494 | 494 | $arguments = array( |
495 | 495 | 'status' => 'publish', |
496 | - 'include' => array( $id ), |
|
496 | + 'include' => array($id), |
|
497 | 497 | 'paginate' => false, |
498 | 498 | ); |
499 | 499 | } |
@@ -503,17 +503,17 @@ discard block |
||
503 | 503 | * |
504 | 504 | * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html |
505 | 505 | */ |
506 | - $products = /** @scrutinizer ignore-call */ wc_get_products( $arguments ); |
|
506 | + $products = /** @scrutinizer ignore-call */ wc_get_products($arguments); |
|
507 | 507 | |
508 | - if ( $products ) { |
|
508 | + if ($products) { |
|
509 | 509 | $records = array(); |
510 | 510 | $record = array(); |
511 | 511 | |
512 | - foreach ( $products as $product ) { |
|
512 | + foreach ($products as $product) { |
|
513 | 513 | /** |
514 | 514 | * Check if product is in stock if $index_in_stock is set to 1 |
515 | 515 | */ |
516 | - if ( '1' === $index_in_stock && $product->is_in_stock() ) { |
|
516 | + if ('1' === $index_in_stock && $product->is_in_stock()) { |
|
517 | 517 | /** |
518 | 518 | * Extract image from $product->get_image() |
519 | 519 | */ |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | /** |
536 | 536 | * Do not check if product is in stock if $index_in_stock is set to 0 |
537 | 537 | */ |
538 | - if ( '0' === $index_in_stock ) { |
|
538 | + if ('0' === $index_in_stock) { |
|
539 | 539 | /** |
540 | 540 | * Extract image from $product->get_image() |
541 | 541 | */ |
@@ -563,14 +563,14 @@ discard block |
||
563 | 563 | * Send the information to Algolia and save the result |
564 | 564 | * If result is NullResponse, print an error message |
565 | 565 | */ |
566 | - $result = $index->saveObjects( $records ); |
|
566 | + $result = $index->saveObjects($records); |
|
567 | 567 | |
568 | - if ( 'Algolia\AlgoliaSearch\Response\NullResponse' === get_class( $result ) ) { |
|
568 | + if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) { |
|
569 | 569 | add_action( |
570 | 570 | 'admin_notices', |
571 | - function () { |
|
571 | + function() { |
|
572 | 572 | echo '<div class="error notice is-dismissible"> |
573 | - <p>' . esc_html__( 'No response from the server. Please check your settings and try again ', 'algolia-woo-indexer' ) . '</p> |
|
573 | + <p>' . esc_html__('No response from the server. Please check your settings and try again ', 'algolia-woo-indexer') . '</p> |
|
574 | 574 | </div>'; |
575 | 575 | } |
576 | 576 | ); |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * Display success message |
582 | 582 | */ |
583 | 583 | echo '<div class="notice notice-success is-dismissible"> |
584 | - <p>' . esc_html__( 'Product(s) sent to Algolia.', 'algolia-woo-indexer' ) . '</p> |
|
584 | + <p>' . esc_html__('Product(s) sent to Algolia.', 'algolia-woo-indexer') . '</p> |
|
585 | 585 | </div>'; |
586 | 586 | } |
587 | 587 | |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | * @param string $input Settings text data |
592 | 592 | * @return array |
593 | 593 | */ |
594 | - public static function settings_fields_validate_options( $input ) { |
|
594 | + public static function settings_fields_validate_options($input) { |
|
595 | 595 | $valid = array(); |
596 | 596 | $valid['name'] = preg_replace( |
597 | 597 | '/[^a-zA-Z\s]/', |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @return void |
608 | 608 | */ |
609 | 609 | public static function load_textdomain() { |
610 | - load_plugin_textdomain( 'algolia-woo-indexer', false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
|
610 | + load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/'); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -618,11 +618,11 @@ discard block |
||
618 | 618 | public static function admin_menu() { |
619 | 619 | add_submenu_page( |
620 | 620 | 'options-general.php', |
621 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
622 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
621 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
622 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
623 | 623 | 'manage_options', |
624 | 624 | 'algolia-woo-indexer-settings', |
625 | - array( get_called_class(), 'algolia_woo_indexer_settings' ) |
|
625 | + array(get_called_class(), 'algolia_woo_indexer_settings') |
|
626 | 626 | ); |
627 | 627 | } |
628 | 628 | |
@@ -635,23 +635,23 @@ discard block |
||
635 | 635 | /** |
636 | 636 | * Verify that the user can access the settings page |
637 | 637 | */ |
638 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
639 | - wp_die( esc_html__( 'Action not allowed.', 'algolia_woo_indexer_settings' ) ); |
|
638 | + if ( ! current_user_can('manage_options')) { |
|
639 | + wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings')); |
|
640 | 640 | } |
641 | 641 | ?> |
642 | 642 | <div class="wrap"> |
643 | - <h1><?php esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ); ?></h1> |
|
644 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
643 | + <h1><?php esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'); ?></h1> |
|
644 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
645 | 645 | <?php |
646 | - settings_fields( 'algolia_woo_options' ); |
|
647 | - do_settings_sections( 'algolia_woo_indexer' ); |
|
648 | - submit_button( '', 'primary wide' ); |
|
646 | + settings_fields('algolia_woo_options'); |
|
647 | + do_settings_sections('algolia_woo_indexer'); |
|
648 | + submit_button('', 'primary wide'); |
|
649 | 649 | ?> |
650 | 650 | </form> |
651 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
652 | - <?php wp_nonce_field( 'send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name' ); ?> |
|
651 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
652 | + <?php wp_nonce_field('send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name'); ?> |
|
653 | 653 | <input type="hidden" name="send_products_to_algolia" id="send_products_to_algolia" value="true" /> |
654 | - <?php submit_button( esc_html__( 'Send products to Algolia', 'algolia_woo_indexer_settings' ), 'primary wide', '', false ); ?> |
|
654 | + <?php submit_button(esc_html__('Send products to Algolia', 'algolia_woo_indexer_settings'), 'primary wide', '', false); ?> |
|
655 | 655 | </form> |
656 | 656 | </div> |
657 | 657 | <?php |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | * @return object |
664 | 664 | */ |
665 | 665 | public static function get_instance() { |
666 | - if ( ! self::$instance ) { |
|
666 | + if ( ! self::$instance) { |
|
667 | 667 | self::$instance = new Algolia_Woo_Indexer(); |
668 | 668 | } |
669 | 669 | return self::$instance; |
@@ -679,47 +679,47 @@ discard block |
||
679 | 679 | /** |
680 | 680 | * Set default values for options if not already set |
681 | 681 | */ |
682 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
683 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
684 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
685 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
686 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
682 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
683 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
684 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
685 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
686 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
687 | 687 | |
688 | - if ( empty( $index_in_stock ) ) { |
|
688 | + if (empty($index_in_stock)) { |
|
689 | 689 | add_option( |
690 | 690 | ALGOWOO_DB_OPTION . '_index_in_stock', |
691 | 691 | '0' |
692 | 692 | ); |
693 | 693 | } |
694 | 694 | |
695 | - if ( empty( $automatically_send_new_products ) ) { |
|
695 | + if (empty($automatically_send_new_products)) { |
|
696 | 696 | add_option( |
697 | 697 | ALGOWOO_DB_OPTION . '_automatically_send_new_products', |
698 | 698 | '0' |
699 | 699 | ); |
700 | 700 | } |
701 | 701 | |
702 | - if ( empty( $algolia_application_id ) ) { |
|
702 | + if (empty($algolia_application_id)) { |
|
703 | 703 | add_option( |
704 | 704 | ALGOWOO_DB_OPTION . '_application_id', |
705 | 705 | 'Change me' |
706 | 706 | ); |
707 | 707 | } |
708 | 708 | |
709 | - if ( empty( $algolia_api_key ) ) { |
|
709 | + if (empty($algolia_api_key)) { |
|
710 | 710 | add_option( |
711 | 711 | ALGOWOO_DB_OPTION . '_admin_api_key', |
712 | 712 | 'Change me' |
713 | 713 | ); |
714 | 714 | } |
715 | 715 | |
716 | - if ( empty( $algolia_index_name ) ) { |
|
716 | + if (empty($algolia_index_name)) { |
|
717 | 717 | add_option( |
718 | 718 | ALGOWOO_DB_OPTION . '_index_name', |
719 | 719 | 'Change me' |
720 | 720 | ); |
721 | 721 | } |
722 | - set_transient( self::PLUGIN_TRANSIENT, true ); |
|
722 | + set_transient(self::PLUGIN_TRANSIENT, true); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | * @return void |
729 | 729 | */ |
730 | 730 | public static function deactivate_plugin() { |
731 | - delete_transient( self::PLUGIN_TRANSIENT, true ); |
|
731 | + delete_transient(self::PLUGIN_TRANSIENT, true); |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | } |