@@ -14,29 +14,29 @@ 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 | -if ( ! class_exists( 'Algolia_Woo_Indexer' ) ) { |
|
| 39 | +if ( ! class_exists('Algolia_Woo_Indexer')) { |
|
| 40 | 40 | /** |
| 41 | 41 | * Algolia WooIndexer main class |
| 42 | 42 | */ |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @see https://developer.wordpress.org/reference/functions/register_setting/ |
| 88 | 88 | */ |
| 89 | - if ( is_admin() ) { |
|
| 89 | + if (is_admin()) { |
|
| 90 | 90 | $arguments = array( |
| 91 | 91 | 'type' => 'string', |
| 92 | 92 | 'sanitize_callback' => 'settings_fields_validate_options', |
| 93 | 93 | 'default' => null, |
| 94 | 94 | ); |
| 95 | - register_setting( 'algolia_woo_options', 'algolia_woo_options', $arguments ); |
|
| 95 | + register_setting('algolia_woo_options', 'algolia_woo_options', $arguments); |
|
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Make sure we reference the instance of the current class by using self::get_instance() |
@@ -105,42 +105,42 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | add_settings_section( |
| 107 | 107 | 'algolia_woo_indexer_main', |
| 108 | - esc_html__( 'Algolia Woo Plugin Settings', 'algolia-woo-indexer' ), |
|
| 109 | - array( $algowooindexer, 'algolia_woo_indexer_section_text' ), |
|
| 108 | + esc_html__('Algolia Woo Plugin Settings', 'algolia-woo-indexer'), |
|
| 109 | + array($algowooindexer, 'algolia_woo_indexer_section_text'), |
|
| 110 | 110 | 'algolia_woo_indexer' |
| 111 | 111 | ); |
| 112 | 112 | add_settings_field( |
| 113 | 113 | 'algolia_woo_indexer_application_id', |
| 114 | - esc_html__( 'Application ID', 'algolia-woo-indexer' ), |
|
| 115 | - array( $algowooindexer, 'algolia_woo_indexer_application_id_output' ), |
|
| 114 | + esc_html__('Application ID', 'algolia-woo-indexer'), |
|
| 115 | + array($algowooindexer, 'algolia_woo_indexer_application_id_output'), |
|
| 116 | 116 | 'algolia_woo_indexer', |
| 117 | 117 | 'algolia_woo_indexer_main' |
| 118 | 118 | ); |
| 119 | 119 | add_settings_field( |
| 120 | 120 | 'algolia_woo_indexer_admin_api_key', |
| 121 | - esc_html__( 'Admin API Key', 'algolia-woo-indexer' ), |
|
| 122 | - array( $algowooindexer, 'algolia_woo_indexer_admin_api_key_output' ), |
|
| 121 | + esc_html__('Admin API Key', 'algolia-woo-indexer'), |
|
| 122 | + array($algowooindexer, 'algolia_woo_indexer_admin_api_key_output'), |
|
| 123 | 123 | 'algolia_woo_indexer', |
| 124 | 124 | 'algolia_woo_indexer_main' |
| 125 | 125 | ); |
| 126 | 126 | add_settings_field( |
| 127 | 127 | 'algolia_woo_indexer_index_name', |
| 128 | - esc_html__( 'Index name (will be created if not existing)', 'algolia-woo-indexer' ), |
|
| 129 | - array( $algowooindexer, 'algolia_woo_indexer_index_name_output' ), |
|
| 128 | + esc_html__('Index name (will be created if not existing)', 'algolia-woo-indexer'), |
|
| 129 | + array($algowooindexer, 'algolia_woo_indexer_index_name_output'), |
|
| 130 | 130 | 'algolia_woo_indexer', |
| 131 | 131 | 'algolia_woo_indexer_main' |
| 132 | 132 | ); |
| 133 | 133 | add_settings_field( |
| 134 | 134 | 'algolia_woo_indexer_index_in_stock', |
| 135 | - esc_html__( 'Only index products in stock', 'algolia-woo-indexer' ), |
|
| 136 | - array( $algowooindexer, 'algolia_woo_indexer_index_in_stock_output' ), |
|
| 135 | + esc_html__('Only index products in stock', 'algolia-woo-indexer'), |
|
| 136 | + array($algowooindexer, 'algolia_woo_indexer_index_in_stock_output'), |
|
| 137 | 137 | 'algolia_woo_indexer', |
| 138 | 138 | 'algolia_woo_indexer_main' |
| 139 | 139 | ); |
| 140 | 140 | add_settings_field( |
| 141 | 141 | 'algolia_woo_indexer_automatically_send_new_products', |
| 142 | - esc_html__( 'Automatically index new products', 'algolia-woo-indexer' ), |
|
| 143 | - array( $algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output' ), |
|
| 142 | + esc_html__('Automatically index new products', 'algolia-woo-indexer'), |
|
| 143 | + array($algowooindexer, 'algolia_woo_indexer_automatically_send_new_products_output'), |
|
| 144 | 144 | 'algolia_woo_indexer', |
| 145 | 145 | 'algolia_woo_indexer_main' |
| 146 | 146 | ); |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | 157 | public static function algolia_woo_indexer_admin_api_key_output() { |
| 158 | - $api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
| 158 | + $api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
| 159 | 159 | $api_key = is_string($api_key) ? $api_key : CHANGE_ME; |
| 160 | 160 | |
| 161 | - wp_nonce_field( 'algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name' ); |
|
| 161 | + wp_nonce_field('algolia_woo_indexer_admin_api_nonce_action', 'algolia_woo_indexer_admin_api_nonce_name'); |
|
| 162 | 162 | |
| 163 | 163 | echo "<input id='algolia_woo_indexer_admin_api_key' name='algolia_woo_indexer_admin_api_key[key]' |
| 164 | - type='text' value='" . esc_attr( $api_key ) . "' />"; |
|
| 164 | + type='text' value='" . esc_attr($api_key) . "' />"; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | * @return void |
| 171 | 171 | */ |
| 172 | 172 | public static function algolia_woo_indexer_application_id_output() { |
| 173 | - $application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
| 173 | + $application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
| 174 | 174 | $application_id = is_string($application_id) ? $application_id : CHANGE_ME; |
| 175 | 175 | |
| 176 | 176 | echo "<input id='algolia_woo_indexer_application_id' name='algolia_woo_indexer_application_id[id]' |
| 177 | - type='text' value='" . esc_attr( $application_id ) . "' />"; |
|
| 177 | + type='text' value='" . esc_attr($application_id) . "' />"; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @return void |
| 184 | 184 | */ |
| 185 | 185 | public static function algolia_woo_indexer_index_name_output() { |
| 186 | - $index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
| 186 | + $index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
| 187 | 187 | $index_name = is_string($index_name) ? $index_name : CHANGE_ME; |
| 188 | 188 | |
| 189 | 189 | echo "<input id='algolia_woo_indexer_index_name' name='algolia_woo_indexer_index_name[name]' |
| 190 | - type='text' value='" . esc_attr( $index_name ) . "' />"; |
|
| 190 | + type='text' value='" . esc_attr($index_name) . "' />"; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * Sanitization is not really needed as the variable is not directly echoed |
| 201 | 201 | * But I have still done it to be 100% safe |
| 202 | 202 | */ |
| 203 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
| 204 | - $index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0; |
|
| 203 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
| 204 | + $index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0; |
|
| 205 | 205 | ?> |
| 206 | 206 | <input id="algolia_woo_indexer_index_in_stock" name="algolia_woo_indexer_index_in_stock[checked]" |
| 207 | - type="checkbox" <?php checked( 1, $index_in_stock ); ?> /> |
|
| 207 | + type="checkbox" <?php checked(1, $index_in_stock); ?> /> |
|
| 208 | 208 | <?php |
| 209 | 209 | } |
| 210 | 210 | |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | * Sanitization is not really needed as the variable is not directly echoed |
| 219 | 219 | * But I have still done it to be 100% safe |
| 220 | 220 | */ |
| 221 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
| 222 | - $automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
| 221 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
| 222 | + $automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
| 223 | 223 | ?> |
| 224 | 224 | <input id="algolia_woo_indexer_automatically_send_new_products" name="algolia_woo_indexer_automatically_send_new_products[checked]" |
| 225 | - type="checkbox" <?php checked( 1, $automatically_send_new_products ); ?> /> |
|
| 225 | + type="checkbox" <?php checked(1, $automatically_send_new_products); ?> /> |
|
| 226 | 226 | <?php |
| 227 | 227 | } |
| 228 | 228 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @return void |
| 233 | 233 | */ |
| 234 | 234 | public static function algolia_woo_indexer_section_text() { |
| 235 | - echo esc_html__( 'Enter your settings here', 'algolia-woo-indexer' ); |
|
| 235 | + echo esc_html__('Enter your settings here', 'algolia-woo-indexer'); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | public static function maybe_send_products() { |
| 244 | 244 | |
| 245 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
| 245 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
| 246 | 246 | self::send_products_to_algolia(); |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -257,19 +257,19 @@ discard block |
||
| 257 | 257 | /** |
| 258 | 258 | * Fetch the option to see if we are going to automatically send new products |
| 259 | 259 | */ |
| 260 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
| 260 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
| 261 | 261 | |
| 262 | 262 | /** |
| 263 | 263 | * Check that we have the minimum versions required and all of the required PHP extensions |
| 264 | 264 | */ |
| 265 | 265 | Algolia_Check_Requirements::check_unmet_requirements(); |
| 266 | 266 | |
| 267 | - if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check() ) { |
|
| 267 | + if ( ! Algolia_Check_Requirements::algolia_wp_version_check() || ! Algolia_Check_Requirements::algolia_php_version_check()) { |
|
| 268 | 268 | add_action( |
| 269 | 269 | 'admin_notices', |
| 270 | - function () { |
|
| 270 | + function() { |
|
| 271 | 271 | echo '<div class="error notice"> |
| 272 | - <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> |
|
| 272 | + <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> |
|
| 273 | 273 | </div>'; |
| 274 | 274 | } |
| 275 | 275 | ); |
@@ -280,33 +280,33 @@ discard block |
||
| 280 | 280 | /** |
| 281 | 281 | * Setup translations |
| 282 | 282 | */ |
| 283 | - add_action( 'plugins_loaded', array( $ob_class, 'load_textdomain' ) ); |
|
| 283 | + add_action('plugins_loaded', array($ob_class, 'load_textdomain')); |
|
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | 286 | * Add actions to setup admin menu |
| 287 | 287 | */ |
| 288 | - if ( is_admin() ) { |
|
| 289 | - add_action( 'admin_menu', array( $ob_class, 'admin_menu' ) ); |
|
| 290 | - add_action( 'admin_init', array( $ob_class, 'setup_settings_sections' ) ); |
|
| 291 | - add_action( 'admin_init', array( $ob_class, 'update_settings_options' ) ); |
|
| 292 | - add_action( 'admin_init', array( $ob_class, 'maybe_send_products' ) ); |
|
| 288 | + if (is_admin()) { |
|
| 289 | + add_action('admin_menu', array($ob_class, 'admin_menu')); |
|
| 290 | + add_action('admin_init', array($ob_class, 'setup_settings_sections')); |
|
| 291 | + add_action('admin_init', array($ob_class, 'update_settings_options')); |
|
| 292 | + add_action('admin_init', array($ob_class, 'maybe_send_products')); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Register hook to automatically send new products if the option is set |
| 296 | 296 | */ |
| 297 | 297 | |
| 298 | - if ( '1' === $automatically_send_new_products ) { |
|
| 299 | - add_action( 'save_post', array( $ob_class, 'send_new_product_to_algolia' ), 10, 3 ); |
|
| 298 | + if ('1' === $automatically_send_new_products) { |
|
| 299 | + add_action('save_post', array($ob_class, 'send_new_product_to_algolia'), 10, 3); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - self::$plugin_url = admin_url( 'options-general.php?page=algolia-woo-indexer-settings' ); |
|
| 302 | + self::$plugin_url = admin_url('options-general.php?page=algolia-woo-indexer-settings'); |
|
| 303 | 303 | |
| 304 | - if ( ! is_plugin_active('woocommerce/woocommerce.php') ) { |
|
| 304 | + if ( ! is_plugin_active('woocommerce/woocommerce.php')) { |
|
| 305 | 305 | add_action( |
| 306 | 306 | 'admin_notices', |
| 307 | - function () { |
|
| 307 | + function() { |
|
| 308 | 308 | echo '<div class="error notice"> |
| 309 | - <p>' . esc_html__( 'WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer' ) . '</p> |
|
| 309 | + <p>' . esc_html__('WooCommerce plugin must be enabled for Algolia Woo Indexer to work.', 'algolia-woo-indexer') . '</p> |
|
| 310 | 310 | </div>'; |
| 311 | 311 | } |
| 312 | 312 | ); |
@@ -322,12 +322,12 @@ discard block |
||
| 322 | 322 | * |
| 323 | 323 | * @return void |
| 324 | 324 | */ |
| 325 | - public static function send_new_product_to_algolia( $post_id, $post ) { |
|
| 325 | + public static function send_new_product_to_algolia($post_id, $post) { |
|
| 326 | 326 | |
| 327 | - if ( 'publish' !== $post->post_status || 'product' !== $post->post_type ) { |
|
| 327 | + if ('publish' !== $post->post_status || 'product' !== $post->post_type) { |
|
| 328 | 328 | return; |
| 329 | 329 | } |
| 330 | - self::send_products_to_algolia( $post_id ); |
|
| 330 | + self::send_products_to_algolia($post_id); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | /** |
| 344 | 344 | * Do not proceed if we are going to send products |
| 345 | 345 | */ |
| 346 | - if ( true === Algolia_Verify_Nonces::verify_send_products_nonce() ) { |
|
| 346 | + if (true === Algolia_Verify_Nonces::verify_send_products_nonce()) { |
|
| 347 | 347 | return; |
| 348 | 348 | } |
| 349 | 349 | |
@@ -352,26 +352,26 @@ discard block |
||
| 352 | 352 | * |
| 353 | 353 | * @see https://www.php.net/manual/en/function.filter-input.php |
| 354 | 354 | */ |
| 355 | - $post_application_id = filter_input( INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 356 | - $post_api_key = filter_input( INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 357 | - $post_index_name = filter_input( INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 358 | - $index_in_stock = filter_input( INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 359 | - $automatically_send_new_products = filter_input( INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 355 | + $post_application_id = filter_input(INPUT_POST, 'algolia_woo_indexer_application_id', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 356 | + $post_api_key = filter_input(INPUT_POST, 'algolia_woo_indexer_admin_api_key', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 357 | + $post_index_name = filter_input(INPUT_POST, 'algolia_woo_indexer_index_name', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 358 | + $index_in_stock = filter_input(INPUT_POST, 'algolia_woo_indexer_index_in_stock', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 359 | + $automatically_send_new_products = filter_input(INPUT_POST, 'algolia_woo_indexer_automatically_send_new_products', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * Properly sanitize text fields before updating data |
| 363 | 363 | * |
| 364 | 364 | * @see https://developer.wordpress.org/reference/functions/sanitize_text_field/ |
| 365 | 365 | */ |
| 366 | - $filtered_application_id = sanitize_text_field( $post_application_id['id'] ); |
|
| 367 | - $filtered_api_key = sanitize_text_field( $post_api_key['key'] ); |
|
| 368 | - $filtered_index_name = sanitize_text_field( $post_index_name['name'] ); |
|
| 366 | + $filtered_application_id = sanitize_text_field($post_application_id['id']); |
|
| 367 | + $filtered_api_key = sanitize_text_field($post_api_key['key']); |
|
| 368 | + $filtered_index_name = sanitize_text_field($post_index_name['name']); |
|
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | 371 | * Sanitizing by setting the value to either 1 or 0 |
| 372 | 372 | */ |
| 373 | - $filtered_index_in_stock = ( ! empty( $index_in_stock ) ) ? 1 : 0; |
|
| 374 | - $filtered_automatically_send_new_products = ( ! empty( $automatically_send_new_products ) ) ? 1 : 0; |
|
| 373 | + $filtered_index_in_stock = ( ! empty($index_in_stock)) ? 1 : 0; |
|
| 374 | + $filtered_automatically_send_new_products = ( ! empty($automatically_send_new_products)) ? 1 : 0; |
|
| 375 | 375 | |
| 376 | 376 | /** |
| 377 | 377 | * Values have been filtered and sanitized |
@@ -379,35 +379,35 @@ discard block |
||
| 379 | 379 | * |
| 380 | 380 | * @see https://developer.wordpress.org/reference/functions/update_option/ |
| 381 | 381 | */ |
| 382 | - if ( isset( $filtered_application_id ) && ( ! empty( $filtered_application_id ) ) ) { |
|
| 382 | + if (isset($filtered_application_id) && ( ! empty($filtered_application_id))) { |
|
| 383 | 383 | update_option( |
| 384 | 384 | ALGOWOO_DB_OPTION . '_application_id', |
| 385 | 385 | $filtered_application_id |
| 386 | 386 | ); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - if ( isset( $filtered_api_key ) && ( ! empty( $filtered_api_key ) ) ) { |
|
| 389 | + if (isset($filtered_api_key) && ( ! empty($filtered_api_key))) { |
|
| 390 | 390 | update_option( |
| 391 | 391 | ALGOWOO_DB_OPTION . '_admin_api_key', |
| 392 | 392 | $filtered_api_key |
| 393 | 393 | ); |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( isset( $filtered_index_name ) && ( ! empty( $filtered_index_name ) ) ) { |
|
| 396 | + if (isset($filtered_index_name) && ( ! empty($filtered_index_name))) { |
|
| 397 | 397 | update_option( |
| 398 | 398 | ALGOWOO_DB_OPTION . '_index_name', |
| 399 | 399 | $filtered_index_name |
| 400 | 400 | ); |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( isset( $filtered_index_in_stock ) && ( ! empty( $filtered_index_in_stock ) ) ) { |
|
| 403 | + if (isset($filtered_index_in_stock) && ( ! empty($filtered_index_in_stock))) { |
|
| 404 | 404 | update_option( |
| 405 | 405 | ALGOWOO_DB_OPTION . '_index_in_stock', |
| 406 | 406 | $filtered_index_in_stock |
| 407 | 407 | ); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - if ( isset( $filtered_automatically_send_new_products ) && ( ! empty( $filtered_automatically_send_new_products ) ) ) { |
|
| 410 | + if (isset($filtered_automatically_send_new_products) && ( ! empty($filtered_automatically_send_new_products))) { |
|
| 411 | 411 | update_option( |
| 412 | 412 | ALGOWOO_DB_OPTION . '_automatically_send_new_products', |
| 413 | 413 | $filtered_automatically_send_new_products |
@@ -421,33 +421,33 @@ discard block |
||
| 421 | 421 | * @param Int $id Product to send to Algolia if we send only a single product |
| 422 | 422 | * @return void |
| 423 | 423 | */ |
| 424 | - public static function send_products_to_algolia( $id = '' ) { |
|
| 424 | + public static function send_products_to_algolia($id = '') { |
|
| 425 | 425 | /** |
| 426 | 426 | * Remove classes from plugin URL and autoload Algolia with Composer |
| 427 | 427 | */ |
| 428 | 428 | |
| 429 | - $base_plugin_directory = str_replace( 'classes', '', dirname( __FILE__ ) ); |
|
| 429 | + $base_plugin_directory = str_replace('classes', '', dirname(__FILE__)); |
|
| 430 | 430 | require_once $base_plugin_directory . '/vendor/autoload.php'; |
| 431 | 431 | |
| 432 | 432 | /** |
| 433 | 433 | * Fetch the required variables from the Settings API |
| 434 | 434 | */ |
| 435 | 435 | |
| 436 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
| 437 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
| 438 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
| 436 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
| 437 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
| 438 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
| 439 | 439 | |
| 440 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
| 440 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
| 441 | 441 | |
| 442 | 442 | /** |
| 443 | 443 | * Display admin notice and return if not all values have been set |
| 444 | 444 | */ |
| 445 | - if ( empty( $algolia_application_id ) || empty( $algolia_api_key || empty( $algolia_index_name ) ) ) { |
|
| 445 | + if (empty($algolia_application_id) || empty($algolia_api_key || empty($algolia_index_name))) { |
|
| 446 | 446 | add_action( |
| 447 | 447 | 'admin_notices', |
| 448 | - function () { |
|
| 448 | + function() { |
|
| 449 | 449 | echo '<div class="error notice"> |
| 450 | - <p>' . esc_html__( 'All settings need to be set for the plugin to work.', 'algolia-woo-indexer' ) . '</p> |
|
| 450 | + <p>' . esc_html__('All settings need to be set for the plugin to work.', 'algolia-woo-indexer') . '</p> |
|
| 451 | 451 | </div>'; |
| 452 | 452 | } |
| 453 | 453 | ); |
@@ -457,19 +457,19 @@ discard block |
||
| 457 | 457 | /** |
| 458 | 458 | * Initiate the Algolia client |
| 459 | 459 | */ |
| 460 | - self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create( $algolia_application_id, $algolia_api_key ); |
|
| 460 | + self::$algolia = \Algolia\AlgoliaSearch\SearchClient::create($algolia_application_id, $algolia_api_key); |
|
| 461 | 461 | |
| 462 | 462 | /** |
| 463 | 463 | * Check if we can connect, if not, handle the exception, display an error and then return |
| 464 | 464 | */ |
| 465 | 465 | try { |
| 466 | 466 | self::$algolia->listApiKeys(); |
| 467 | - } catch ( \Algolia\AlgoliaSearch\Exceptions\UnreachableException $error ) { |
|
| 467 | + } catch (\Algolia\AlgoliaSearch\Exceptions\UnreachableException $error) { |
|
| 468 | 468 | add_action( |
| 469 | 469 | 'admin_notices', |
| 470 | - function () { |
|
| 470 | + function() { |
|
| 471 | 471 | echo '<div class="error notice"> |
| 472 | - <p>' . esc_html__( 'An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer' ) . '</p> |
|
| 472 | + <p>' . esc_html__('An error has been encountered. Please check your application ID and API key. ', 'algolia-woo-indexer') . '</p> |
|
| 473 | 473 | </div>'; |
| 474 | 474 | } |
| 475 | 475 | ); |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | /** |
| 480 | 480 | * Initialize the search index and set the name to the option from the database |
| 481 | 481 | */ |
| 482 | - $index = self::$algolia->initIndex( $algolia_index_name ); |
|
| 482 | + $index = self::$algolia->initIndex($algolia_index_name); |
|
| 483 | 483 | |
| 484 | 484 | /** |
| 485 | 485 | * Setup arguments for sending all products to Algolia |
@@ -495,10 +495,10 @@ discard block |
||
| 495 | 495 | /** |
| 496 | 496 | * Setup arguments for sending only a single product |
| 497 | 497 | */ |
| 498 | - if ( isset( $id ) && '' !== $id ) { |
|
| 498 | + if (isset($id) && '' !== $id) { |
|
| 499 | 499 | $arguments = array( |
| 500 | 500 | 'status' => 'publish', |
| 501 | - 'include' => array( $id ), |
|
| 501 | + 'include' => array($id), |
|
| 502 | 502 | 'paginate' => false, |
| 503 | 503 | ); |
| 504 | 504 | } |
@@ -508,17 +508,17 @@ discard block |
||
| 508 | 508 | * |
| 509 | 509 | * @see https://docs.woocommerce.com/wc-apidocs/function-wc_get_products.html |
| 510 | 510 | */ |
| 511 | - $products = /** @scrutinizer ignore-call */ wc_get_products( $arguments ); |
|
| 511 | + $products = /** @scrutinizer ignore-call */ wc_get_products($arguments); |
|
| 512 | 512 | |
| 513 | - if ( $products ) { |
|
| 513 | + if ($products) { |
|
| 514 | 514 | $records = array(); |
| 515 | 515 | $record = array(); |
| 516 | 516 | |
| 517 | - foreach ( $products as $product ) { |
|
| 517 | + foreach ($products as $product) { |
|
| 518 | 518 | /** |
| 519 | 519 | * Check if product is in stock if $index_in_stock is set to 1 |
| 520 | 520 | */ |
| 521 | - if ( '1' === $index_in_stock && $product->is_in_stock() ) { |
|
| 521 | + if ('1' === $index_in_stock && $product->is_in_stock()) { |
|
| 522 | 522 | /** |
| 523 | 523 | * Extract image from $product->get_image() |
| 524 | 524 | */ |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | /** |
| 541 | 541 | * Do not check if product is in stock if $index_in_stock is set to 0 |
| 542 | 542 | */ |
| 543 | - if ( '0' === $index_in_stock ) { |
|
| 543 | + if ('0' === $index_in_stock) { |
|
| 544 | 544 | /** |
| 545 | 545 | * Extract image from $product->get_image() |
| 546 | 546 | */ |
@@ -568,14 +568,14 @@ discard block |
||
| 568 | 568 | * Send the information to Algolia and save the result |
| 569 | 569 | * If result is NullResponse, print an error message |
| 570 | 570 | */ |
| 571 | - $result = $index->saveObjects( $records ); |
|
| 571 | + $result = $index->saveObjects($records); |
|
| 572 | 572 | |
| 573 | - if ( 'Algolia\AlgoliaSearch\Response\NullResponse' === get_class( $result ) ) { |
|
| 573 | + if ('Algolia\AlgoliaSearch\Response\NullResponse' === get_class($result)) { |
|
| 574 | 574 | add_action( |
| 575 | 575 | 'admin_notices', |
| 576 | - function () { |
|
| 576 | + function() { |
|
| 577 | 577 | echo '<div class="error notice is-dismissible"> |
| 578 | - <p>' . esc_html__( 'No response from the server. Please check your settings and try again ', 'algolia-woo-indexer' ) . '</p> |
|
| 578 | + <p>' . esc_html__('No response from the server. Please check your settings and try again ', 'algolia-woo-indexer') . '</p> |
|
| 579 | 579 | </div>'; |
| 580 | 580 | } |
| 581 | 581 | ); |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | * Display success message |
| 587 | 587 | */ |
| 588 | 588 | echo '<div class="notice notice-success is-dismissible"> |
| 589 | - <p>' . esc_html__( 'Product(s) sent to Algolia.', 'algolia-woo-indexer' ) . '</p> |
|
| 589 | + <p>' . esc_html__('Product(s) sent to Algolia.', 'algolia-woo-indexer') . '</p> |
|
| 590 | 590 | </div>'; |
| 591 | 591 | } |
| 592 | 592 | |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | * @param string $input Settings text data |
| 597 | 597 | * @return array |
| 598 | 598 | */ |
| 599 | - public static function settings_fields_validate_options( $input ) { |
|
| 599 | + public static function settings_fields_validate_options($input) { |
|
| 600 | 600 | $valid = array(); |
| 601 | 601 | $valid['name'] = preg_replace( |
| 602 | 602 | '/[^a-zA-Z\s]/', |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | * @return void |
| 613 | 613 | */ |
| 614 | 614 | public static function load_textdomain() { |
| 615 | - load_plugin_textdomain( 'algolia-woo-indexer', false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
|
| 615 | + load_plugin_textdomain('algolia-woo-indexer', false, basename(dirname(__FILE__)) . '/languages/'); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -623,11 +623,11 @@ discard block |
||
| 623 | 623 | public static function admin_menu() { |
| 624 | 624 | add_submenu_page( |
| 625 | 625 | 'options-general.php', |
| 626 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
| 627 | - esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ), |
|
| 626 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
| 627 | + esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'), |
|
| 628 | 628 | 'manage_options', |
| 629 | 629 | 'algolia-woo-indexer-settings', |
| 630 | - array( get_called_class(), 'algolia_woo_indexer_settings' ) |
|
| 630 | + array(get_called_class(), 'algolia_woo_indexer_settings') |
|
| 631 | 631 | ); |
| 632 | 632 | } |
| 633 | 633 | |
@@ -640,23 +640,23 @@ discard block |
||
| 640 | 640 | /** |
| 641 | 641 | * Verify that the user can access the settings page |
| 642 | 642 | */ |
| 643 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 644 | - wp_die( esc_html__( 'Action not allowed.', 'algolia_woo_indexer_settings' ) ); |
|
| 643 | + if ( ! current_user_can('manage_options')) { |
|
| 644 | + wp_die(esc_html__('Action not allowed.', 'algolia_woo_indexer_settings')); |
|
| 645 | 645 | } |
| 646 | 646 | ?> |
| 647 | 647 | <div class="wrap"> |
| 648 | - <h1><?php esc_html__( 'Algolia Woo Indexer Settings', 'algolia-woo-indexer' ); ?></h1> |
|
| 649 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
| 648 | + <h1><?php esc_html__('Algolia Woo Indexer Settings', 'algolia-woo-indexer'); ?></h1> |
|
| 649 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
| 650 | 650 | <?php |
| 651 | - settings_fields( 'algolia_woo_options' ); |
|
| 652 | - do_settings_sections( 'algolia_woo_indexer' ); |
|
| 653 | - submit_button( '', 'primary wide' ); |
|
| 651 | + settings_fields('algolia_woo_options'); |
|
| 652 | + do_settings_sections('algolia_woo_indexer'); |
|
| 653 | + submit_button('', 'primary wide'); |
|
| 654 | 654 | ?> |
| 655 | 655 | </form> |
| 656 | - <form action="<?php echo esc_url( self::$plugin_url ); ?>" method="POST"> |
|
| 657 | - <?php wp_nonce_field( 'send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name' ); ?> |
|
| 656 | + <form action="<?php echo esc_url(self::$plugin_url); ?>" method="POST"> |
|
| 657 | + <?php wp_nonce_field('send_products_to_algolia_nonce_action', 'send_products_to_algolia_nonce_name'); ?> |
|
| 658 | 658 | <input type="hidden" name="send_products_to_algolia" id="send_products_to_algolia" value="true" /> |
| 659 | - <?php submit_button( esc_html__( 'Send products to Algolia', 'algolia_woo_indexer_settings' ), 'primary wide', '', false ); ?> |
|
| 659 | + <?php submit_button(esc_html__('Send products to Algolia', 'algolia_woo_indexer_settings'), 'primary wide', '', false); ?> |
|
| 660 | 660 | </form> |
| 661 | 661 | </div> |
| 662 | 662 | <?php |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | * @return object |
| 669 | 669 | */ |
| 670 | 670 | public static function get_instance() { |
| 671 | - if ( ! self::$instance ) { |
|
| 671 | + if ( ! self::$instance) { |
|
| 672 | 672 | self::$instance = new Algolia_Woo_Indexer(); |
| 673 | 673 | } |
| 674 | 674 | return self::$instance; |
@@ -684,47 +684,47 @@ discard block |
||
| 684 | 684 | /** |
| 685 | 685 | * Set default values for options if not already set |
| 686 | 686 | */ |
| 687 | - $index_in_stock = get_option( ALGOWOO_DB_OPTION . '_index_in_stock' ); |
|
| 688 | - $automatically_send_new_products = get_option( ALGOWOO_DB_OPTION . '_automatically_send_new_products' ); |
|
| 689 | - $algolia_application_id = get_option( ALGOWOO_DB_OPTION . '_application_id' ); |
|
| 690 | - $algolia_api_key = get_option( ALGOWOO_DB_OPTION . '_admin_api_key' ); |
|
| 691 | - $algolia_index_name = get_option( ALGOWOO_DB_OPTION . '_index_name' ); |
|
| 687 | + $index_in_stock = get_option(ALGOWOO_DB_OPTION . '_index_in_stock'); |
|
| 688 | + $automatically_send_new_products = get_option(ALGOWOO_DB_OPTION . '_automatically_send_new_products'); |
|
| 689 | + $algolia_application_id = get_option(ALGOWOO_DB_OPTION . '_application_id'); |
|
| 690 | + $algolia_api_key = get_option(ALGOWOO_DB_OPTION . '_admin_api_key'); |
|
| 691 | + $algolia_index_name = get_option(ALGOWOO_DB_OPTION . '_index_name'); |
|
| 692 | 692 | |
| 693 | - if ( empty( $index_in_stock ) ) { |
|
| 693 | + if (empty($index_in_stock)) { |
|
| 694 | 694 | add_option( |
| 695 | 695 | ALGOWOO_DB_OPTION . '_index_in_stock', |
| 696 | 696 | '0' |
| 697 | 697 | ); |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - if ( empty( $automatically_send_new_products ) ) { |
|
| 700 | + if (empty($automatically_send_new_products)) { |
|
| 701 | 701 | add_option( |
| 702 | 702 | ALGOWOO_DB_OPTION . '_automatically_send_new_products', |
| 703 | 703 | '0' |
| 704 | 704 | ); |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - if ( empty( $algolia_application_id ) ) { |
|
| 707 | + if (empty($algolia_application_id)) { |
|
| 708 | 708 | add_option( |
| 709 | 709 | ALGOWOO_DB_OPTION . '_application_id', |
| 710 | 710 | 'Change me' |
| 711 | 711 | ); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - if ( empty( $algolia_api_key ) ) { |
|
| 714 | + if (empty($algolia_api_key)) { |
|
| 715 | 715 | add_option( |
| 716 | 716 | ALGOWOO_DB_OPTION . '_admin_api_key', |
| 717 | 717 | 'Change me' |
| 718 | 718 | ); |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - if ( empty( $algolia_index_name ) ) { |
|
| 721 | + if (empty($algolia_index_name)) { |
|
| 722 | 722 | add_option( |
| 723 | 723 | ALGOWOO_DB_OPTION . '_index_name', |
| 724 | 724 | 'Change me' |
| 725 | 725 | ); |
| 726 | 726 | } |
| 727 | - set_transient( self::PLUGIN_TRANSIENT, true ); |
|
| 727 | + set_transient(self::PLUGIN_TRANSIENT, true); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -733,7 +733,7 @@ discard block |
||
| 733 | 733 | * @return void |
| 734 | 734 | */ |
| 735 | 735 | public static function deactivate_plugin() { |
| 736 | - delete_transient( self::PLUGIN_TRANSIENT, true ); |
|
| 736 | + delete_transient(self::PLUGIN_TRANSIENT, true); |
|
| 737 | 737 | } |
| 738 | 738 | } |
| 739 | 739 | } |