@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * Include plugin file if function is_plugin_active does not exist |
23 | 23 | */ |
24 | 24 | if (! function_exists('is_plugin_active')) { |
25 | - require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
|
25 | + require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public static function setup_settings_sections() { |
92 | 92 | /** |
93 | - * Setup arguments for settings sections and fields |
|
94 | - * |
|
95 | - * @see https://developer.wordpress.org/reference/functions/register_setting/ |
|
96 | - */ |
|
93 | + * Setup arguments for settings sections and fields |
|
94 | + * |
|
95 | + * @see https://developer.wordpress.org/reference/functions/register_setting/ |
|
96 | + */ |
|
97 | 97 | if ( is_admin() ) { |
98 | 98 | $arguments = array( |
99 | 99 | 'type' => 'string', |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | ); |
466 | 466 | |
467 | 467 | /** |
468 | - * Setup arguments for sending only a single product |
|
469 | - */ |
|
468 | + * Setup arguments for sending only a single product |
|
469 | + */ |
|
470 | 470 | if ( isset( $id ) && '' !== $id ) { |
471 | 471 | $arguments = array( |
472 | 472 | 'status' => 'publish', |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | $products = /** @scrutinizer ignore-call */ wc_get_products( $arguments ); |
484 | 484 | |
485 | 485 | if ( ! $products ) { |
486 | - return; |
|
487 | - } |
|
486 | + return; |
|
487 | + } |
|
488 | 488 | $records = array(); |
489 | 489 | $record = array(); |
490 | 490 | |
@@ -585,8 +585,8 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public static function algolia_woo_indexer_settings() { |
587 | 587 | /** |
588 | - * Verify that the user can access the settings page |
|
589 | - */ |
|
588 | + * Verify that the user can access the settings page |
|
589 | + */ |
|
590 | 590 | if ( ! current_user_can( 'manage_options' ) ) { |
591 | 591 | wp_die( esc_html__( 'Action not allowed.', 'algolia_woo_indexer_settings' ) ); |
592 | 592 | } |
@@ -14,27 +14,27 @@ 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 | 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 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | define('ALGOLIA_APPLICATION_ID', '_application_id'); |
45 | 45 | define('ALGOLIA_API_KEY', '_admin_api_key'); |
46 | 46 | |
47 | -if ( ! class_exists( 'Algolia_Woo_Indexer' ) ) { |
|
47 | +if ( ! class_exists('Algolia_Woo_Indexer')) { |
|
48 | 48 | /** |
49 | 49 | * Algolia WooIndexer main class |
50 | 50 | */ |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @see https://developer.wordpress.org/reference/functions/register_setting/ |
96 | 96 | */ |
97 | - if ( is_admin() ) { |
|
97 | + if (is_admin()) { |
|
98 | 98 | $arguments = array( |
99 | 99 | 'type' => 'string', |
100 | 100 | 'sanitize_callback' => 'settings_fields_validate_options', |
101 | 101 | 'default' => null, |
102 | 102 | ); |
103 | - register_setting( 'algolia_woo_options', 'algolia_woo_options', $arguments ); |
|
103 | + register_setting('algolia_woo_options', 'algolia_woo_options', $arguments); |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Make sure we reference the instance of the current class by using self::get_instance() |
@@ -113,35 +113,35 @@ discard block |
||
113 | 113 | */ |
114 | 114 | add_settings_section( |
115 | 115 | 'algolia_woo_indexer_main', |
116 | - esc_html__( 'Algolia Woo Plugin Settings', 'algolia-woo-indexer' ), |
|
117 | - array( $algowooindexer, 'algolia_woo_indexer_section_text' ), |
|
116 | + esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'), |
|
117 | + array($algowooindexer, 'algolia_woo_indexer_section_text'), |
|
118 | 118 | 'algolia_woo_indexer' |
119 | 119 | ); |
120 | 120 | add_settings_field( |
121 | 121 | 'algolia_woo_indexer_application_id', |
122 | - esc_html__( 'Application ID', 'algolia-woo-indexer' ), |
|
123 | - array( $algowooindexer, 'algolia_woo_indexer_application_id_output' ), |
|
122 | + esc_html__('Application ID', 'algolia-woo-indexer'), |
|
123 | + array($algowooindexer, 'algolia_woo_indexer_application_id_output'), |
|
124 | 124 | 'algolia_woo_indexer', |
125 | 125 | 'algolia_woo_indexer_main' |
126 | 126 | ); |
127 | 127 | add_settings_field( |
128 | 128 | 'algolia_woo_indexer_admin_api_key', |
129 | - esc_html__( 'Admin API Key', 'algolia-woo-indexer' ), |
|
130 | - array( $algowooindexer, 'algolia_woo_indexer_admin_api_key_output' ), |
|
129 | + esc_html__('Admin API Key', 'algolia-woo-indexer'), |
|
130 | + array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'), |
|
131 | 131 | 'algolia_woo_indexer', |
132 | 132 | 'algolia_woo_indexer_main' |
133 | 133 | ); |
134 | 134 | add_settings_field( |
135 | 135 | 'algolia_woo_indexer_index_name', |
136 | - esc_html__( 'Index name (will be created if not existing)', 'algolia-woo-indexer' ), |
|
137 | - array( $algowooindexer, 'algolia_woo_indexer_index_name_output' ), |
|
136 | + esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'), |
|
137 | + array($algowooindexer, 'algolia_woo_indexer_index_name_output'), |
|
138 | 138 | 'algolia_woo_indexer', |
139 | 139 | 'algolia_woo_indexer_main' |
140 | 140 | ); |
141 | 141 | add_settings_field( |
142 | 142 | 'algolia_woo_indexer_automatically_send_new_products', |
143 | - esc_html__( 'Automatically index new products', 'algolia-woo-indexer' ), |
|
144 | - array( $algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output' ), |
|
143 | + esc_html__('Automatically index new products', 'algolia-woo-indexer'), |
|
144 | + array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'), |
|
145 | 145 | 'algolia_woo_indexer', |
146 | 146 | 'algolia_woo_indexer_main' |
147 | 147 | ); |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | * @return void |
157 | 157 | */ |
158 | 158 | public static function algolia_woo_indexer_admin_api_key_output() { |
159 | - $api_key = get_option( ALGOWOO_DB_OPTION . ALGOLIA_API_KEY ); |
|
159 | + $api_key = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY); |
|
160 | 160 | $api_key = is_string($api_key) ? $api_key : CHANGE_ME; |
161 | 161 | |
162 | - wp_nonce_field( 'algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name' ); |
|
162 | + wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name'); |
|
163 | 163 | |
164 | 164 | echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]' |
165 | - type='text' value='" . esc_attr( $api_key ) . "' />"; |
|
165 | + type='text' value='" . esc_attr($api_key) . "' />"; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @return void |
172 | 172 | */ |
173 | 173 | public static function algolia_woo_indexer_application_id_output() { |
174 | - $application_id = get_option( ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID ); |
|
174 | + $application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID); |
|
175 | 175 | $application_id = is_string($application_id) ? $application_id : CHANGE_ME; |
176 | 176 | |
177 | 177 | echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]' |
178 | - type='text' value='" . esc_attr( $application_id ) . "' />"; |
|
178 | + type='text' value='" . esc_attr($application_id) . "' />"; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * @return void |
185 | 185 | */ |
186 | 186 | public static function algolia_woo_indexer_index_name_output() { |
187 | - $index_name = get_option( ALGOWOO_DB_OPTION . INDEX_NAME ); |
|
187 | + $index_name = get_option(ALGOWOO_DB_OPTION . INDEX_NAME); |
|
188 | 188 | $index_name = is_string($index_name) ? $index_name : CHANGE_ME; |
189 | 189 | |
190 | 190 | echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]' |
191 | - type='text' value='" . esc_attr( $index_name ) . "' />"; |
|
191 | + type='text' value='" . esc_attr($index_name) . "' />"; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | * Sanitization is not really needed as the variable is not directly echoed |
202 | 202 | * But I have still done it to be 100% safe |
203 | 203 | */ |
204 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS ); |
|
205 | - $automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
204 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS); |
|
205 | + $automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
206 | 206 | ?> |
207 | 207 | <input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]" |
208 | - type="checkbox" <?php checked( 1, $automatically_send_new_products ); ?> /> |
|
208 | + type="checkbox" <?php checked(1, $automatically_send_new_products); ?> /> |
|
209 | 209 | <?php |
210 | 210 | } |
211 | 211 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return void |
216 | 216 | */ |
217 | 217 | public static function algolia_woo_indexer_section_text() { |
218 | - echo esc_html__( 'Enter your settings here', 'algolia-woo-indexer' ); |
|
218 | + echo esc_html__('Enter your settings here', 'algolia-woo-indexer'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public static function maybe_send_products() { |
227 | 227 | |
228 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
228 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
229 | 229 | self::send_products_to_algolia(); |
230 | 230 | } |
231 | 231 | } |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | /** |
241 | 241 | * Fetch the option to see if we are going to automatically send new products |
242 | 242 | */ |
243 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS ); |
|
243 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS); |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Check that we have the minimum versions required and all of the required PHP extensions |
247 | 247 | */ |
248 | 248 | Algolia_Check_Requirements::check_unmet_requirements(); |
249 | 249 | |
250 | - if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check() ) { |
|
250 | + if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check()) { |
|
251 | 251 | add_action( |
252 | 252 | 'admin_notices', |
253 | - function () { |
|
253 | + function() { |
|
254 | 254 | echo '<div class="error notice"> |
255 | - <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> |
|
255 | + <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> |
|
256 | 256 | </div>'; |
257 | 257 | } |
258 | 258 | ); |
@@ -263,33 +263,33 @@ discard block |
||
263 | 263 | /** |
264 | 264 | * Setup translations |
265 | 265 | */ |
266 | - add_action( 'plugins_loaded', array( $ob_class, 'load_textdomain' ) ); |
|
266 | + add_action('plugins_loaded', array($ob_class, 'load_textdomain')); |
|
267 | 267 | |
268 | 268 | /** |
269 | 269 | * Add actions to setup admin menu |
270 | 270 | */ |
271 | - if ( is_admin() ) { |
|
272 | - add_action( 'admin_menu', array( $ob_class, 'admin_menu' ) ); |
|
273 | - add_action( 'admin_init', array( $ob_class, 'setup_settings_sections' ) ); |
|
274 | - add_action( 'admin_init', array( $ob_class, 'update_settings_options' ) ); |
|
275 | - add_action( 'admin_init', array( $ob_class, 'maybe_send_products' ) ); |
|
271 | + if (is_admin()) { |
|
272 | + add_action('admin_menu', array($ob_class, 'admin_menu')); |
|
273 | + add_action('admin_init', array($ob_class, 'setup_settings_sections')); |
|
274 | + add_action('admin_init', array($ob_class, 'update_settings_options')); |
|
275 | + add_action('admin_init', array($ob_class, 'maybe_send_products')); |
|
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Register hook to automatically send new products if the option is set |
279 | 279 | */ |
280 | 280 | |
281 | - if ( '1' === $automatically_send_new_products ) { |
|
282 | - add_action( 'save_post', array( $ob_class, 'send_new_product_to_algolia' ), 10, 3 ); |
|
281 | + if ('1' === $automatically_send_new_products) { |
|
282 | + add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3); |
|
283 | 283 | } |
284 | 284 | |
285 | - self::$plugin_url = admin_url( 'options-general.php?page=algolia-woo-indexer-settings' ); |
|
285 | + self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings'); |
|
286 | 286 | |
287 | - if ( ! is_plugin_active('woocommerce/woocommerce.php') ) { |
|
287 | + if ( ! is_plugin_active('woocommerce/woocommerce.php')) { |
|
288 | 288 | add_action( |
289 | 289 | 'admin_notices', |
290 | - function () { |
|
290 | + function() { |
|
291 | 291 | echo '<div class="error notice"> |
292 | - <p>' . esc_html__( 'WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer' ) . '</p> |
|
292 | + <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p> |
|
293 | 293 | </div>'; |
294 | 294 | } |
295 | 295 | ); |
@@ -305,12 +305,12 @@ discard block |
||
305 | 305 | * |
306 | 306 | * @return void |
307 | 307 | */ |
308 | - public static function send_new_product_to_algolia( $post_id, $post ) { |
|
308 | + public static function send_new_product_to_algolia($post_id, $post) { |
|
309 | 309 | |
310 | - if ( 'publish' !== $post->post_status || 'product' !== $post->post_type ) { |
|
310 | + if ('publish' !== $post->post_status || 'product' !== $post->post_type) { |
|
311 | 311 | return; |
312 | 312 | } |
313 | - self::send_products_to_algolia( $post_id ); |
|
313 | + self::send_products_to_algolia($post_id); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | /** |
327 | 327 | * Do not proceed if we are going to send products |
328 | 328 | */ |
329 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
329 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 | |
@@ -335,24 +335,24 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @see https://www.php.net/manual/en/function.filter-input.php |
337 | 337 | */ |
338 | - $post_application_id = filter_input( INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
339 | - $post_api_key = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
340 | - $post_index_name = filter_input( INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
341 | - $automatically_send_new_products = filter_input( INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
338 | + $post_application_id = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
339 | + $post_api_key = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
340 | + $post_index_name = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
341 | + $automatically_send_new_products = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
342 | 342 | |
343 | 343 | /** |
344 | 344 | * Properly sanitize text fields before updating data |
345 | 345 | * |
346 | 346 | * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/ |
347 | 347 | */ |
348 | - $filtered_application_id = sanitize_text_field( $post_application_id['id'] ); |
|
349 | - $filtered_api_key = sanitize_text_field( $post_api_key['key'] ); |
|
350 | - $filtered_index_name = sanitize_text_field( $post_index_name['name'] ); |
|
348 | + $filtered_application_id = sanitize_text_field($post_application_id['id']); |
|
349 | + $filtered_api_key = sanitize_text_field($post_api_key['key']); |
|
350 | + $filtered_index_name = sanitize_text_field($post_index_name['name']); |
|
351 | 351 | |
352 | 352 | /** |
353 | 353 | * Sanitizing by setting the value to either 1 or 0 |
354 | 354 | */ |
355 | - $filtered_automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
355 | + $filtered_automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
356 | 356 | |
357 | 357 | /** |
358 | 358 | * Values have been filtered and sanitized |
@@ -360,28 +360,28 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @see https://developer.wordpress.org/reference/functions/update_option/ |
362 | 362 | */ |
363 | - if ( isset( $filtered_application_id ) && ( ! empty( $filtered_application_id ) ) ) { |
|
363 | + if (isset($filtered_application_id) && ( ! empty($filtered_application_id))) { |
|
364 | 364 | update_option( |
365 | 365 | ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID, |
366 | 366 | $filtered_application_id |
367 | 367 | ); |
368 | 368 | } |
369 | 369 | |
370 | - if ( isset( $filtered_api_key ) && ( ! empty( $filtered_api_key ) ) ) { |
|
370 | + if (isset($filtered_api_key) && ( ! empty($filtered_api_key))) { |
|
371 | 371 | update_option( |
372 | 372 | ALGOWOO_DB_OPTION . ALGOLIA_API_KEY, |
373 | 373 | $filtered_api_key |
374 | 374 | ); |
375 | 375 | } |
376 | 376 | |
377 | - if ( isset( $filtered_index_name ) && ( ! empty( $filtered_index_name ) ) ) { |
|
377 | + if (isset($filtered_index_name) && ( ! empty($filtered_index_name))) { |
|
378 | 378 | update_option( |
379 | 379 | ALGOWOO_DB_OPTION . INDEX_NAME, |
380 | 380 | $filtered_index_name |
381 | 381 | ); |
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $filtered_automatically_send_new_products ) && ( ! empty( $filtered_automatically_send_new_products ) ) ) { |
|
384 | + if (isset($filtered_automatically_send_new_products) && ( ! empty($filtered_automatically_send_new_products))) { |
|
385 | 385 | update_option( |
386 | 386 | ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS, |
387 | 387 | $filtered_automatically_send_new_products |
@@ -395,31 +395,31 @@ discard block |
||
395 | 395 | * @param Int $id Product to send to Algolia if we send only a single product |
396 | 396 | * @return void |
397 | 397 | */ |
398 | - public static function send_products_to_algolia( $id = '' ) { |
|
398 | + public static function send_products_to_algolia($id = '') { |
|
399 | 399 | /** |
400 | 400 | * Remove classes from plugin URL and autoload Algolia with Composer |
401 | 401 | */ |
402 | 402 | |
403 | - $base_plugin_directory = str_replace( 'classes', '', dirname( __FILE__ ) ); |
|
403 | + $base_plugin_directory = str_replace('classes', '', dirname(__FILE__)); |
|
404 | 404 | require_once $base_plugin_directory . '/vendor/autoload.php'; |
405 | 405 | |
406 | 406 | /** |
407 | 407 | * Fetch the required variables from the Settings API |
408 | 408 | */ |
409 | 409 | |
410 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID ); |
|
411 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . ALGOLIA_API_KEY ); |
|
412 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . INDEX_NAME ); |
|
410 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID); |
|
411 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY); |
|
412 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . INDEX_NAME); |
|
413 | 413 | |
414 | 414 | /** |
415 | 415 | * Display admin notice and return if not all values have been set |
416 | 416 | */ |
417 | - if ( empty( $algolia_application_id ) || empty( $algolia_api_key || empty( $algolia_index_name ) ) ) { |
|
417 | + if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) { |
|
418 | 418 | add_action( |
419 | 419 | 'admin_notices', |
420 | - function () { |
|
420 | + function() { |
|
421 | 421 | echo '<div class="error notice"> |
422 | - <p>' . esc_html__( 'All settings need to be set for the plugin to work.', 'algolia-woo-indexer' ) . '</p> |
|
422 | + <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p> |
|
423 | 423 | </div>'; |
424 | 424 | } |
425 | 425 | ); |
@@ -429,19 +429,19 @@ discard block |
||
429 | 429 | /** |
430 | 430 | * Initiate the Algolia client |
431 | 431 | */ |
432 | - self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create( $algolia_application_id, $algolia_api_key ); |
|
432 | + self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key); |
|
433 | 433 | |
434 | 434 | /** |
435 | 435 | * Check if we can connect, if not, handle the exception, display an error and then return |
436 | 436 | */ |
437 | 437 | try { |
438 | 438 | self::$algolia->listApiKeys(); |
439 | - } catch ( \Algolia\AlgoliaSearch\Exceptions\UnreachableException $error ) { |
|
439 | + } catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) { |
|
440 | 440 | add_action( |
441 | 441 | 'admin_notices', |
442 | - function () { |
|
442 | + function() { |
|
443 | 443 | echo '<div class="error notice"> |
444 | - <p>' . esc_html__( 'An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer' ) . '</p> |
|
444 | + <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p> |
|
445 | 445 | </div>'; |
446 | 446 | } |
447 | 447 | ); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | /** |
452 | 452 | * Initialize the search index and set the name to the option from the database |
453 | 453 | */ |
454 | - $index = self::$algolia->initIndex( $algolia_index_name ); |
|
454 | + $index = self::$algolia->initIndex($algolia_index_name); |
|
455 | 455 | |
456 | 456 | /** |
457 | 457 | * Setup arguments for sending all products to Algolia |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | /** |
468 | 468 | * Setup arguments for sending only a single product |
469 | 469 | */ |
470 | - if ( isset( $id ) && '' !== $id ) { |
|
470 | + if (isset($id) && '' !== $id) { |
|
471 | 471 | $arguments = array( |
472 | 472 | 'status' => 'publish', |
473 | - 'include' => array( $id ), |
|
473 | + 'include' => array($id), |
|
474 | 474 | 'paginate' => false, |
475 | 475 | ); |
476 | 476 | } |
@@ -480,15 +480,15 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html |
482 | 482 | */ |
483 | - $products = /** @scrutinizer ignore-call */ wc_get_products( $arguments ); |
|
483 | + $products = /** @scrutinizer ignore-call */ wc_get_products($arguments); |
|
484 | 484 | |
485 | - if ( ! $products ) { |
|
485 | + if ( ! $products) { |
|
486 | 486 | return; |
487 | 487 | } |
488 | 488 | $records = array(); |
489 | 489 | $record = array(); |
490 | 490 | |
491 | - foreach ( $products as $product ) { |
|
491 | + foreach ($products as $product) { |
|
492 | 492 | /** |
493 | 493 | * Extract image from $product->get_image() |
494 | 494 | */ |
@@ -515,14 +515,14 @@ discard block |
||
515 | 515 | * Send the information to Algolia and save the result |
516 | 516 | * If result is NullResponse, print an error message |
517 | 517 | */ |
518 | - $result = $index->saveObjects( $records ); |
|
518 | + $result = $index->saveObjects($records); |
|
519 | 519 | |
520 | - if ( 'Algolia\AlgoliaSearch\Response\NullResponse' === get_class( $result ) ) { |
|
520 | + if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) { |
|
521 | 521 | add_action( |
522 | 522 | 'admin_notices', |
523 | - function () { |
|
523 | + function() { |
|
524 | 524 | echo '<div class="error notice is-dismissible"> |
525 | - <p>' . esc_html__( 'No response from the server. Please check your settings and try again ', 'algolia-woo-indexer' ) . '</p> |
|
525 | + <p>' . esc_html__('No response from the server. Please check your settings and try again ', 'algolia-woo-indexer') . '</p> |
|
526 | 526 | </div>'; |
527 | 527 | } |
528 | 528 | ); |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * Display success message |
534 | 534 | */ |
535 | 535 | echo '<div class="notice notice-success is-dismissible"> |
536 | - <p>' . esc_html__( 'Product(s) sent to Algolia.', 'algolia-woo-indexer' ) . '</p> |
|
536 | + <p>' . esc_html__('Product(s) sent to Algolia.', 'algolia-woo-indexer') . '</p> |
|
537 | 537 | </div>'; |
538 | 538 | } |
539 | 539 | |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @param string $input Settings text data |
544 | 544 | * @return array |
545 | 545 | */ |
546 | - public static function settings_fields_validate_options( $input ) { |
|
546 | + public static function settings_fields_validate_options($input) { |
|
547 | 547 | $valid = array(); |
548 | 548 | $valid['name'] = preg_replace( |
549 | 549 | '/[^a-zA-Z\s]/', |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | * @return void |
560 | 560 | */ |
561 | 561 | public static function load_textdomain() { |
562 | - load_plugin_textdomain( 'algolia-woo-indexer', false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
|
562 | + load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/'); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
@@ -570,11 +570,11 @@ discard block |
||
570 | 570 | public static function admin_menu() { |
571 | 571 | add_submenu_page( |
572 | 572 | 'options-general.php', |
573 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
574 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
573 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
574 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
575 | 575 | 'manage_options', |
576 | 576 | 'algolia-woo-indexer-settings', |
577 | - array( get_called_class(), 'algolia_woo_indexer_settings' ) |
|
577 | + array(get_called_class(), 'algolia_woo_indexer_settings') |
|
578 | 578 | ); |
579 | 579 | } |
580 | 580 | |
@@ -587,23 +587,23 @@ discard block |
||
587 | 587 | /** |
588 | 588 | * Verify that the user can access the settings page |
589 | 589 | */ |
590 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
591 | - wp_die( esc_html__( 'Action not allowed.', 'algolia_woo_indexer_settings' ) ); |
|
590 | + if ( ! current_user_can('manage_options')) { |
|
591 | + wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings')); |
|
592 | 592 | } |
593 | 593 | ?> |
594 | 594 | <div class="wrap"> |
595 | - <h1><?php esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ); ?></h1> |
|
596 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
595 | + <h1><?php esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'); ?></h1> |
|
596 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
597 | 597 | <?php |
598 | - settings_fields( 'algolia_woo_options' ); |
|
599 | - do_settings_sections( 'algolia_woo_indexer' ); |
|
600 | - submit_button( '', 'primary wide' ); |
|
598 | + settings_fields('algolia_woo_options'); |
|
599 | + do_settings_sections('algolia_woo_indexer'); |
|
600 | + submit_button('', 'primary wide'); |
|
601 | 601 | ?> |
602 | 602 | </form> |
603 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
604 | - <?php wp_nonce_field( 'send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name' ); ?> |
|
603 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
604 | + <?php wp_nonce_field('send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name'); ?> |
|
605 | 605 | <input type="hidden" name="send_products_to_algolia" id="send_products_to_algolia" value="true" /> |
606 | - <?php submit_button( esc_html__( 'Send products to Algolia', 'algolia_woo_indexer_settings' ), 'primary wide', '', false ); ?> |
|
606 | + <?php submit_button(esc_html__('Send products to Algolia', 'algolia_woo_indexer_settings'), 'primary wide', '', false); ?> |
|
607 | 607 | </form> |
608 | 608 | </div> |
609 | 609 | <?php |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @return object |
616 | 616 | */ |
617 | 617 | public static function get_instance() { |
618 | - if ( ! self::$instance ) { |
|
618 | + if ( ! self::$instance) { |
|
619 | 619 | self::$instance = new Algolia_Woo_Indexer(); |
620 | 620 | } |
621 | 621 | return self::$instance; |
@@ -631,39 +631,39 @@ discard block |
||
631 | 631 | /** |
632 | 632 | * Set default values for options if not already set |
633 | 633 | */ |
634 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS ); |
|
635 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID ); |
|
636 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . ALGOLIA_API_KEY ); |
|
637 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . INDEX_NAME ); |
|
634 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS); |
|
635 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID); |
|
636 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . ALGOLIA_API_KEY); |
|
637 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . INDEX_NAME); |
|
638 | 638 | |
639 | - if ( empty( $automatically_send_new_products ) ) { |
|
639 | + if (empty($automatically_send_new_products)) { |
|
640 | 640 | add_option( |
641 | 641 | ALGOWOO_DB_OPTION . AUTOMATICALLY_SEND_NEW_PRODUCTS, |
642 | 642 | '0' |
643 | 643 | ); |
644 | 644 | } |
645 | 645 | |
646 | - if ( empty( $algolia_application_id ) ) { |
|
646 | + if (empty($algolia_application_id)) { |
|
647 | 647 | add_option( |
648 | 648 | ALGOWOO_DB_OPTION . ALGOLIA_APPLICATION_ID, |
649 | 649 | 'Change me' |
650 | 650 | ); |
651 | 651 | } |
652 | 652 | |
653 | - if ( empty( $algolia_api_key ) ) { |
|
653 | + if (empty($algolia_api_key)) { |
|
654 | 654 | add_option( |
655 | 655 | ALGOWOO_DB_OPTION . ALGOLIA_API_KEY, |
656 | 656 | 'Change me' |
657 | 657 | ); |
658 | 658 | } |
659 | 659 | |
660 | - if ( empty( $algolia_index_name ) ) { |
|
660 | + if (empty($algolia_index_name)) { |
|
661 | 661 | add_option( |
662 | 662 | ALGOWOO_DB_OPTION . INDEX_NAME, |
663 | 663 | 'Change me' |
664 | 664 | ); |
665 | 665 | } |
666 | - set_transient( self::PLUGIN_TRANSIENT, true ); |
|
666 | + set_transient(self::PLUGIN_TRANSIENT, true); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,5 +672,5 @@ discard block |
||
672 | 672 | * @return void |
673 | 673 | */ |
674 | 674 | public static function deactivate_plugin() { |
675 | - delete_transient( self::PLUGIN_TRANSIENT, true ); |
|
675 | + delete_transient(self::PLUGIN_TRANSIENT, true); |
|
676 | 676 | } |
677 | 677 | \ No newline at end of file |