@@ -14,17 +14,17 @@ 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 | * Define the plugin version and the database table name |
23 | 23 | */ |
24 | -define( 'ALGOWOO_DB_OPTION', '_algolia_woo_indexer' ); |
|
25 | -define( 'ALGOWOO_CURRENT_DB_VERSION', '0.3' ); |
|
24 | +define('ALGOWOO_DB_OPTION', '_algolia_woo_indexer'); |
|
25 | +define('ALGOWOO_CURRENT_DB_VERSION', '0.3'); |
|
26 | 26 | |
27 | -if ( ! class_exists( 'Algolia_Woo_Indexer' ) ) { |
|
27 | +if ( ! class_exists('Algolia_Woo_Indexer')) { |
|
28 | 28 | /** |
29 | 29 | * Algolia WooIndexer main class |
30 | 30 | */ |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @see https://developer.wordpress.org/reference/functions/register_setting/ |
76 | 76 | */ |
77 | - if ( is_admin() ) { |
|
77 | + if (is_admin()) { |
|
78 | 78 | $arguments = array( |
79 | 79 | 'type' => 'string', |
80 | 80 | 'sanitize_callback' => 'settings_fields_validate_options', |
81 | 81 | 'default' => null, |
82 | 82 | ); |
83 | - register_setting( 'algolia_woo_options', 'algolia_woo_options', $arguments ); |
|
83 | + register_setting('algolia_woo_options', 'algolia_woo_options', $arguments); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Make sure we reference the instance of the current class by using self::get_instance() |
@@ -93,42 +93,42 @@ discard block |
||
93 | 93 | */ |
94 | 94 | add_settings_section( |
95 | 95 | 'algolia_woo_indexer_main', |
96 | - esc_html__( 'Algolia Woo Plugin Settings', 'algolia-woo-indexer' ), |
|
97 | - array( $algowooindexer, 'algolia_woo_indexer_section_text' ), |
|
96 | + esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'), |
|
97 | + array($algowooindexer, 'algolia_woo_indexer_section_text'), |
|
98 | 98 | 'algolia_woo_indexer' |
99 | 99 | ); |
100 | 100 | add_settings_field( |
101 | 101 | 'algolia_woo_indexer_application_id', |
102 | - esc_html__( 'Application ID', 'algolia-woo-indexer' ), |
|
103 | - array( $algowooindexer, 'algolia_woo_indexer_application_id_output' ), |
|
102 | + esc_html__('Application ID', 'algolia-woo-indexer'), |
|
103 | + array($algowooindexer, 'algolia_woo_indexer_application_id_output'), |
|
104 | 104 | 'algolia_woo_indexer', |
105 | 105 | 'algolia_woo_indexer_main' |
106 | 106 | ); |
107 | 107 | add_settings_field( |
108 | 108 | 'algolia_woo_indexer_admin_api_key', |
109 | - esc_html__( 'Admin API Key', 'algolia-woo-indexer' ), |
|
110 | - array( $algowooindexer, 'algolia_woo_indexer_admin_api_key_output' ), |
|
109 | + esc_html__('Admin API Key', 'algolia-woo-indexer'), |
|
110 | + array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'), |
|
111 | 111 | 'algolia_woo_indexer', |
112 | 112 | 'algolia_woo_indexer_main' |
113 | 113 | ); |
114 | 114 | add_settings_field( |
115 | 115 | 'algolia_woo_indexer_index_name', |
116 | - esc_html__( 'Index name (will be created if not existing)', 'algolia-woo-indexer' ), |
|
117 | - array( $algowooindexer, 'algolia_woo_indexer_index_name_output' ), |
|
116 | + esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'), |
|
117 | + array($algowooindexer, 'algolia_woo_indexer_index_name_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_in_stock', |
123 | - esc_html__( 'Only index products in stock', 'algolia-woo-indexer' ), |
|
124 | - array( $algowooindexer, 'algolia_woo_indexer_index_in_stock_output' ), |
|
123 | + esc_html__('Only index products in stock', 'algolia-woo-indexer'), |
|
124 | + array($algowooindexer, 'algolia_woo_indexer_index_in_stock_output'), |
|
125 | 125 | 'algolia_woo_indexer', |
126 | 126 | 'algolia_woo_indexer_main' |
127 | 127 | ); |
128 | 128 | add_settings_field( |
129 | 129 | 'algolia_woo_indexer_automatically_send_new_products', |
130 | - esc_html__( 'Automatically index new products', 'algolia-woo-indexer' ), |
|
131 | - array( $algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output' ), |
|
130 | + esc_html__('Automatically index new products', 'algolia-woo-indexer'), |
|
131 | + array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'), |
|
132 | 132 | 'algolia_woo_indexer', |
133 | 133 | 'algolia_woo_indexer_main' |
134 | 134 | ); |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | * @return void |
144 | 144 | */ |
145 | 145 | public static function algolia_woo_indexer_admin_api_key_output() { |
146 | - $api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
146 | + $api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
147 | 147 | |
148 | - wp_nonce_field( 'algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name' ); |
|
148 | + wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name'); |
|
149 | 149 | |
150 | 150 | echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]' |
151 | - type='text' value='" . esc_attr( $api_key ) . "' />"; |
|
151 | + type='text' value='" . esc_attr($api_key) . "' />"; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | * @return void |
158 | 158 | */ |
159 | 159 | public static function algolia_woo_indexer_application_id_output() { |
160 | - $application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
160 | + $application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
161 | 161 | |
162 | 162 | echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]' |
163 | - type='text' value='" . esc_attr( $application_id ) . "' />"; |
|
163 | + type='text' value='" . esc_attr($application_id) . "' />"; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | * @return void |
170 | 170 | */ |
171 | 171 | public static function algolia_woo_indexer_index_name_output() { |
172 | - $index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
172 | + $index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
173 | 173 | |
174 | 174 | echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]' |
175 | - type='text' value='" . esc_attr( $index_name ) . "' />"; |
|
175 | + type='text' value='" . esc_attr($index_name) . "' />"; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * Sanitization is not really needed as the variable is not directly echoed |
186 | 186 | * But I have still done it to be 100% safe |
187 | 187 | */ |
188 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
189 | - $index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0; |
|
188 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
189 | + $index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0; |
|
190 | 190 | ?> |
191 | 191 | <input id="algolia_woo_indexer_index_in_stock" name="algolia_woo_indexer_index_in_stock[checked]" |
192 | - type="checkbox" <?php checked( 1, $index_in_stock ); ?> /> |
|
192 | + type="checkbox" <?php checked(1, $index_in_stock); ?> /> |
|
193 | 193 | <?php |
194 | 194 | } |
195 | 195 | |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | * Sanitization is not really needed as the variable is not directly echoed |
204 | 204 | * But I have still done it to be 100% safe |
205 | 205 | */ |
206 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
207 | - $automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
206 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
207 | + $automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
208 | 208 | ?> |
209 | 209 | <input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]" |
210 | - type="checkbox" <?php checked( 1, $automatically_send_new_products ); ?> /> |
|
210 | + type="checkbox" <?php checked(1, $automatically_send_new_products); ?> /> |
|
211 | 211 | <?php |
212 | 212 | } |
213 | 213 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @return void |
218 | 218 | */ |
219 | 219 | public static function algolia_woo_indexer_section_text() { |
220 | - echo esc_html__( 'Enter your settings here', 'algolia-woo-indexer' ); |
|
220 | + echo esc_html__('Enter your settings here', 'algolia-woo-indexer'); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public static function maybe_send_products() { |
229 | 229 | |
230 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
230 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
231 | 231 | self::send_products_to_algolia(); |
232 | 232 | return; |
233 | 233 | } |
@@ -243,19 +243,19 @@ discard block |
||
243 | 243 | /** |
244 | 244 | * Fetch the option to see if we are going to automatically send new products |
245 | 245 | */ |
246 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
246 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Check that we have the minimum versions required and all of the required PHP extensions |
250 | 250 | */ |
251 | 251 | Algolia_Check_Requirements::check_unmet_requirements(); |
252 | 252 | |
253 | - if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check() ) { |
|
253 | + if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check()) { |
|
254 | 254 | add_action( |
255 | 255 | 'admin_notices', |
256 | - function () { |
|
256 | + function() { |
|
257 | 257 | echo '<div class="error notice"> |
258 | - <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> |
|
258 | + <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> |
|
259 | 259 | </div>'; |
260 | 260 | } |
261 | 261 | ); |
@@ -266,33 +266,33 @@ discard block |
||
266 | 266 | /** |
267 | 267 | * Setup translations |
268 | 268 | */ |
269 | - add_action( 'plugins_loaded', array( $ob_class, 'load_textdomain' ) ); |
|
269 | + add_action('plugins_loaded', array($ob_class, 'load_textdomain')); |
|
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Add actions to setup admin menu |
273 | 273 | */ |
274 | - if ( is_admin() ) { |
|
275 | - add_action( 'admin_menu', array( $ob_class, 'admin_menu' ) ); |
|
276 | - add_action( 'admin_init', array( $ob_class, 'setup_settings_sections' ) ); |
|
277 | - add_action( 'admin_init', array( $ob_class, 'update_settings_options' ) ); |
|
278 | - add_action( 'admin_init', array( $ob_class, 'maybe_send_products' ) ); |
|
274 | + if (is_admin()) { |
|
275 | + add_action('admin_menu', array($ob_class, 'admin_menu')); |
|
276 | + add_action('admin_init', array($ob_class, 'setup_settings_sections')); |
|
277 | + add_action('admin_init', array($ob_class, 'update_settings_options')); |
|
278 | + add_action('admin_init', array($ob_class, 'maybe_send_products')); |
|
279 | 279 | |
280 | 280 | /** |
281 | 281 | * Register hook to automatically send new products if the option is set |
282 | 282 | */ |
283 | 283 | |
284 | - if ( '1' === $automatically_send_new_products ) { |
|
285 | - add_action( 'save_post', array( $ob_class, 'send_new_product_to_algolia' ), 10, 3 ); |
|
284 | + if ('1' === $automatically_send_new_products) { |
|
285 | + add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3); |
|
286 | 286 | } |
287 | 287 | |
288 | - self::$plugin_url = admin_url( 'options-general.php?page=algolia-woo-indexer-settings' ); |
|
288 | + self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings'); |
|
289 | 289 | |
290 | - if ( ! Algolia_Check_Requirements::is_woocommerce_plugin_active() ) { |
|
290 | + if ( ! Algolia_Check_Requirements::is_woocommerce_plugin_active()) { |
|
291 | 291 | add_action( |
292 | 292 | 'admin_notices', |
293 | - function () { |
|
293 | + function() { |
|
294 | 294 | echo '<div class="error notice"> |
295 | - <p>' . esc_html__( 'WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer' ) . '</p> |
|
295 | + <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p> |
|
296 | 296 | </div>'; |
297 | 297 | } |
298 | 298 | ); |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return void |
310 | 310 | */ |
311 | - public static function send_new_product_to_algolia( $post_id, $post ) { |
|
311 | + public static function send_new_product_to_algolia($post_id, $post) { |
|
312 | 312 | |
313 | - if ( 'publish' !== $post->post_status || 'product' !== $post->post_type ) { |
|
313 | + if ('publish' !== $post->post_status || 'product' !== $post->post_type) { |
|
314 | 314 | return; |
315 | 315 | } |
316 | - self::send_products_to_algolia( $post_id ); |
|
316 | + self::send_products_to_algolia($post_id); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | /** |
330 | 330 | * Do not proceed if we are going to send products |
331 | 331 | */ |
332 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
332 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
333 | 333 | return; |
334 | 334 | } |
335 | 335 | |
@@ -338,26 +338,26 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @see https://www.php.net/manual/en/function.filter-input.php |
340 | 340 | */ |
341 | - $post_application_id = filter_input( INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
342 | - $post_api_key = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
343 | - $post_index_name = filter_input( INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
344 | - $index_in_stock = filter_input( INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
345 | - $automatically_send_new_products = filter_input( INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
341 | + $post_application_id = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
342 | + $post_api_key = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
343 | + $post_index_name = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
344 | + $index_in_stock = filter_input(INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
345 | + $automatically_send_new_products = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
346 | 346 | |
347 | 347 | /** |
348 | 348 | * Properly sanitize text fields before updating data |
349 | 349 | * |
350 | 350 | * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/ |
351 | 351 | */ |
352 | - $filtered_application_id = sanitize_text_field( $post_application_id['id'] ); |
|
353 | - $filtered_api_key = sanitize_text_field( $post_api_key['key'] ); |
|
354 | - $filtered_index_name = sanitize_text_field( $post_index_name['name'] ); |
|
352 | + $filtered_application_id = sanitize_text_field($post_application_id['id']); |
|
353 | + $filtered_api_key = sanitize_text_field($post_api_key['key']); |
|
354 | + $filtered_index_name = sanitize_text_field($post_index_name['name']); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * Sanitizing by setting the value to either 1 or 0 |
358 | 358 | */ |
359 | - $filtered_index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0; |
|
360 | - $filtered_automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
359 | + $filtered_index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0; |
|
360 | + $filtered_automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
361 | 361 | |
362 | 362 | /** |
363 | 363 | * Values have been filtered and sanitized |
@@ -365,35 +365,35 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @see https://developer.wordpress.org/reference/functions/update_option/ |
367 | 367 | */ |
368 | - if ( isset( $filtered_application_id ) && ( ! empty( $filtered_application_id ) ) ) { |
|
368 | + if (isset($filtered_application_id) && ( ! empty($filtered_application_id))) { |
|
369 | 369 | update_option( |
370 | 370 | ALGOWOO_DB_OPTION . '_application_id', |
371 | 371 | $filtered_application_id |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | |
375 | - if ( isset( $filtered_api_key ) && ( ! empty( $filtered_api_key ) ) ) { |
|
375 | + if (isset($filtered_api_key) && ( ! empty($filtered_api_key))) { |
|
376 | 376 | update_option( |
377 | 377 | ALGOWOO_DB_OPTION . '_admin_api_key', |
378 | 378 | $filtered_api_key |
379 | 379 | ); |
380 | 380 | } |
381 | 381 | |
382 | - if ( isset( $filtered_index_name ) && ( ! empty( $filtered_index_name ) ) ) { |
|
382 | + if (isset($filtered_index_name) && ( ! empty($filtered_index_name))) { |
|
383 | 383 | update_option( |
384 | 384 | ALGOWOO_DB_OPTION . '_index_name', |
385 | 385 | $filtered_index_name |
386 | 386 | ); |
387 | 387 | } |
388 | 388 | |
389 | - if ( isset( $filtered_index_in_stock ) && ( ! empty( $filtered_index_in_stock ) ) ) { |
|
389 | + if (isset($filtered_index_in_stock) && ( ! empty($filtered_index_in_stock))) { |
|
390 | 390 | update_option( |
391 | 391 | ALGOWOO_DB_OPTION . '_index_in_stock', |
392 | 392 | $filtered_index_in_stock |
393 | 393 | ); |
394 | 394 | } |
395 | 395 | |
396 | - if ( isset( $filtered_automatically_send_new_products ) && ( ! empty( $filtered_automatically_send_new_products ) ) ) { |
|
396 | + if (isset($filtered_automatically_send_new_products) && ( ! empty($filtered_automatically_send_new_products))) { |
|
397 | 397 | update_option( |
398 | 398 | ALGOWOO_DB_OPTION . '_automatically_send_new_products', |
399 | 399 | $filtered_automatically_send_new_products |
@@ -407,33 +407,33 @@ discard block |
||
407 | 407 | * @param Int $id Product to send to Algolia if we send only a single product |
408 | 408 | * @return void |
409 | 409 | */ |
410 | - public static function send_products_to_algolia( $id = '' ) { |
|
410 | + public static function send_products_to_algolia($id = '') { |
|
411 | 411 | /** |
412 | 412 | * Remove classes from plugin URL and autoload Algolia with Composer |
413 | 413 | */ |
414 | 414 | |
415 | - $base_plugin_directory = str_replace( 'classes', '', dirname( __FILE__ ) ); |
|
415 | + $base_plugin_directory = str_replace('classes', '', dirname(__FILE__)); |
|
416 | 416 | require_once $base_plugin_directory . '/vendor/autoload.php'; |
417 | 417 | |
418 | 418 | /** |
419 | 419 | * Fetch the required variables from the Settings API |
420 | 420 | */ |
421 | 421 | |
422 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
423 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
424 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
422 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
423 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
424 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
425 | 425 | |
426 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
426 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
427 | 427 | |
428 | 428 | /** |
429 | 429 | * Display admin notice and return if not all values have been set |
430 | 430 | */ |
431 | - if ( empty( $algolia_application_id ) || empty( $algolia_api_key || empty( $algolia_index_name ) ) ) { |
|
431 | + if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) { |
|
432 | 432 | add_action( |
433 | 433 | 'admin_notices', |
434 | - function () { |
|
434 | + function() { |
|
435 | 435 | echo '<div class="error notice"> |
436 | - <p>' . esc_html__( 'All settings need to be set for the plugin to work.', 'algolia-woo-indexer' ) . '</p> |
|
436 | + <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p> |
|
437 | 437 | </div>'; |
438 | 438 | } |
439 | 439 | ); |
@@ -443,19 +443,19 @@ discard block |
||
443 | 443 | /** |
444 | 444 | * Initiate the Algolia client |
445 | 445 | */ |
446 | - self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create( $algolia_application_id, $algolia_api_key ); |
|
446 | + self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key); |
|
447 | 447 | |
448 | 448 | /** |
449 | 449 | * Check if we can connect, if not, handle the exception, display an error and then return |
450 | 450 | */ |
451 | 451 | try { |
452 | 452 | self::$algolia->listApiKeys(); |
453 | - } catch ( \Algolia\AlgoliaSearch\Exceptions\UnreachableException $error ) { |
|
453 | + } catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) { |
|
454 | 454 | add_action( |
455 | 455 | 'admin_notices', |
456 | - function () { |
|
456 | + function() { |
|
457 | 457 | echo '<div class="error notice"> |
458 | - <p>' . esc_html__( 'An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer' ) . '</p> |
|
458 | + <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p> |
|
459 | 459 | </div>'; |
460 | 460 | } |
461 | 461 | ); |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | /** |
466 | 466 | * Initialize the search index and set the name to the option from the database |
467 | 467 | */ |
468 | - $index = self::$algolia->initIndex( $algolia_index_name ); |
|
468 | + $index = self::$algolia->initIndex($algolia_index_name); |
|
469 | 469 | |
470 | 470 | /** |
471 | 471 | * Setup arguments for sending all products to Algolia |
@@ -481,10 +481,10 @@ discard block |
||
481 | 481 | /** |
482 | 482 | * Setup arguments for sending only a single product |
483 | 483 | */ |
484 | - if ( isset( $id ) && '' !== $id ) { |
|
484 | + if (isset($id) && '' !== $id) { |
|
485 | 485 | $arguments = array( |
486 | 486 | 'status' => 'publish', |
487 | - 'include' => array( $id ), |
|
487 | + 'include' => array($id), |
|
488 | 488 | 'paginate' => false, |
489 | 489 | ); |
490 | 490 | } |
@@ -494,17 +494,17 @@ discard block |
||
494 | 494 | * |
495 | 495 | * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html |
496 | 496 | */ |
497 | - $products = wc_get_products( $arguments ); |
|
497 | + $products = wc_get_products($arguments); |
|
498 | 498 | |
499 | - if ( $products ) { |
|
499 | + if ($products) { |
|
500 | 500 | $records = array(); |
501 | 501 | $record = array(); |
502 | 502 | |
503 | - foreach ( $products as $product ) { |
|
503 | + foreach ($products as $product) { |
|
504 | 504 | /** |
505 | 505 | * Check if product is in stock if $index_in_stock is set to 1 |
506 | 506 | */ |
507 | - if ( '1' === $index_in_stock && $product->is_in_stock() ) { |
|
507 | + if ('1' === $index_in_stock && $product->is_in_stock()) { |
|
508 | 508 | /** |
509 | 509 | * Extract image from $product->get_image() |
510 | 510 | */ |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | /** |
527 | 527 | * Do not check if product is in stock if $index_in_stock is set to 0 |
528 | 528 | */ |
529 | - if ( '0' === $index_in_stock ) { |
|
529 | + if ('0' === $index_in_stock) { |
|
530 | 530 | /** |
531 | 531 | * Extract image from $product->get_image() |
532 | 532 | */ |
@@ -554,14 +554,14 @@ discard block |
||
554 | 554 | * Send the information to Algolia and save the result |
555 | 555 | * If result is NullResponse, print an error message |
556 | 556 | */ |
557 | - $result = $index->saveObjects( $records ); |
|
557 | + $result = $index->saveObjects($records); |
|
558 | 558 | |
559 | - if ( 'Algolia\AlgoliaSearch\Response\NullResponse' === get_class( $result ) ) { |
|
559 | + if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) { |
|
560 | 560 | add_action( |
561 | 561 | 'admin_notices', |
562 | - function () { |
|
562 | + function() { |
|
563 | 563 | echo '<div class="error notice is-dismissible"> |
564 | - <p>' . esc_html__( 'No response from the server. Please check your settings and try again ', 'algolia-woo-indexer' ) . '</p> |
|
564 | + <p>' . esc_html__('No response from the server. Please check your settings and try again ', 'algolia-woo-indexer') . '</p> |
|
565 | 565 | </div>'; |
566 | 566 | } |
567 | 567 | ); |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * Display success message |
573 | 573 | */ |
574 | 574 | echo '<div class="notice notice-success is-dismissible"> |
575 | - <p>' . esc_html__( 'Product(s) sent to Algolia.', 'algolia-woo-indexer' ) . '</p> |
|
575 | + <p>' . esc_html__('Product(s) sent to Algolia.', 'algolia-woo-indexer') . '</p> |
|
576 | 576 | </div>'; |
577 | 577 | } |
578 | 578 | |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | * @param string $input Settings text data |
583 | 583 | * @return array |
584 | 584 | */ |
585 | - public static function settings_fields_validate_options( $input ) { |
|
585 | + public static function settings_fields_validate_options($input) { |
|
586 | 586 | $valid = array(); |
587 | 587 | $valid['name'] = preg_replace( |
588 | 588 | '/[^a-zA-Z\s]/', |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @return void |
599 | 599 | */ |
600 | 600 | public static function load_textdomain() { |
601 | - load_plugin_textdomain( 'algolia-woo-indexer', false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
|
601 | + load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/'); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | public static function admin_menu() { |
610 | 610 | add_submenu_page( |
611 | 611 | 'options-general.php', |
612 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
613 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
612 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
613 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
614 | 614 | 'manage_options', |
615 | 615 | 'algolia-woo-indexer-settings', |
616 | - array( get_called_class(), 'algolia_woo_indexer_settings' ) |
|
616 | + array(get_called_class(), 'algolia_woo_indexer_settings') |
|
617 | 617 | ); |
618 | 618 | } |
619 | 619 | |
@@ -626,23 +626,23 @@ discard block |
||
626 | 626 | /** |
627 | 627 | * Verify that the user can access the settings page |
628 | 628 | */ |
629 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
630 | - wp_die( esc_html__( 'Action not allowed.', 'algolia_woo_indexer_settings' ) ); |
|
629 | + if ( ! current_user_can('manage_options')) { |
|
630 | + wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings')); |
|
631 | 631 | } |
632 | 632 | ?> |
633 | 633 | <div class="wrap"> |
634 | - <h1><?php esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ); ?></h1> |
|
635 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
634 | + <h1><?php esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'); ?></h1> |
|
635 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
636 | 636 | <?php |
637 | - settings_fields( 'algolia_woo_options' ); |
|
638 | - do_settings_sections( 'algolia_woo_indexer' ); |
|
639 | - submit_button( '', 'primary wide' ); |
|
637 | + settings_fields('algolia_woo_options'); |
|
638 | + do_settings_sections('algolia_woo_indexer'); |
|
639 | + submit_button('', 'primary wide'); |
|
640 | 640 | ?> |
641 | 641 | </form> |
642 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
643 | - <?php wp_nonce_field( 'send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name' ); ?> |
|
642 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
643 | + <?php wp_nonce_field('send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name'); ?> |
|
644 | 644 | <input type="hidden" name="send_products_to_algolia" id="send_products_to_algolia" value="true" /> |
645 | - <?php submit_button( esc_html__( 'Send products to Algolia', 'algolia_woo_indexer_settings' ), 'primary wide', '', false ); ?> |
|
645 | + <?php submit_button(esc_html__('Send products to Algolia', 'algolia_woo_indexer_settings'), 'primary wide', '', false); ?> |
|
646 | 646 | </form> |
647 | 647 | </div> |
648 | 648 | <?php |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | * @return object |
655 | 655 | */ |
656 | 656 | public static function get_instance() { |
657 | - if ( ! self::$instance ) { |
|
657 | + if ( ! self::$instance) { |
|
658 | 658 | self::$instance = new Algolia_Woo_Indexer(); |
659 | 659 | } |
660 | 660 | return self::$instance; |
@@ -670,47 +670,47 @@ discard block |
||
670 | 670 | /** |
671 | 671 | * Set default values for options if not already set |
672 | 672 | */ |
673 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
674 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
675 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
676 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
677 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
673 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
674 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
675 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
676 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
677 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
678 | 678 | |
679 | - if ( empty( $index_in_stock ) ) { |
|
679 | + if (empty($index_in_stock)) { |
|
680 | 680 | add_option( |
681 | 681 | ALGOWOO_DB_OPTION . '_index_in_stock', |
682 | 682 | '0' |
683 | 683 | ); |
684 | 684 | } |
685 | 685 | |
686 | - if ( empty( $automatically_send_new_products ) ) { |
|
686 | + if (empty($automatically_send_new_products)) { |
|
687 | 687 | add_option( |
688 | 688 | ALGOWOO_DB_OPTION . '_automatically_send_new_products', |
689 | 689 | '0' |
690 | 690 | ); |
691 | 691 | } |
692 | 692 | |
693 | - if ( empty( $algolia_application_id ) ) { |
|
693 | + if (empty($algolia_application_id)) { |
|
694 | 694 | add_option( |
695 | 695 | ALGOWOO_DB_OPTION . '_application_id', |
696 | 696 | 'Change me' |
697 | 697 | ); |
698 | 698 | } |
699 | 699 | |
700 | - if ( empty( $algolia_api_key ) ) { |
|
700 | + if (empty($algolia_api_key)) { |
|
701 | 701 | add_option( |
702 | 702 | ALGOWOO_DB_OPTION . '_admin_api_key', |
703 | 703 | 'Change me' |
704 | 704 | ); |
705 | 705 | } |
706 | 706 | |
707 | - if ( empty( $algolia_index_name ) ) { |
|
707 | + if (empty($algolia_index_name)) { |
|
708 | 708 | add_option( |
709 | 709 | ALGOWOO_DB_OPTION . '_index_name', |
710 | 710 | 'Change me' |
711 | 711 | ); |
712 | 712 | } |
713 | - set_transient( self::PLUGIN_TRANSIENT, true ); |
|
713 | + set_transient(self::PLUGIN_TRANSIENT, true); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | /** |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * @return void |
720 | 720 | */ |
721 | 721 | public static function deactivate_plugin() { |
722 | - delete_transient( self::PLUGIN_TRANSIENT, true ); |
|
722 | + delete_transient(self::PLUGIN_TRANSIENT, true); |
|
723 | 723 | } |
724 | 724 | } |
725 | 725 | } |