From 9c8a6d78d9b358aeace95b39b10c9fcde363efcb Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Tue, 28 Jan 2020 16:28:40 -0800 Subject: [PATCH 1/5] Added automattic/jetpack-constants package to make testing constants easier --- composer.json | 1 + composer.lock | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 06b4761723b..7f1ece33269 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "require": { "php": ">=5.6|>=7.0", "automattic/jetpack-autoloader": "^1.2.0", + "automattic/jetpack-constants": "^1.1", "composer/installers": "1.7.0", "maxmind-db/reader": "1.6.0", "woocommerce/woocommerce-blocks": "2.5.11", diff --git a/composer.lock b/composer.lock index e7cdd373318..41dcd2a2d71 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e6dfd8d640c9fc3f21795ddb41a23477", + "content-hash": "41bbf9384ba5827f6d298881bcd1b86e", "packages": [ { "name": "automattic/jetpack-autoloader", @@ -42,6 +42,36 @@ "description": "Creates a custom autoloader for a plugin or theme.", "time": "2019-09-24T06:39:29+00:00" }, + { + "name": "automattic/jetpack-constants", + "version": "v1.1.3", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-constants.git", + "reference": "5fdd94dec1151e7defd684a97e0b64fe6ff1bd3a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/5fdd94dec1151e7defd684a97e0b64fe6ff1bd3a", + "reference": "5fdd94dec1151e7defd684a97e0b64fe6ff1bd3a", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "A wrapper for defining constants in a more testable way.", + "time": "2019-11-08T21:16:05+00:00" + }, { "name": "composer/installers", "version": "v1.7.0", From 6ad091a9b7e4132657414cff0bef3386bf31782c Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Tue, 28 Jan 2020 21:21:29 -0800 Subject: [PATCH 2/5] Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages --- .../abstracts/abstract-wc-payment-gateway.php | 4 +++- includes/abstracts/abstract-wc-widget.php | 4 +++- includes/admin/class-wc-admin-assets.php | 6 ++++-- includes/admin/class-wc-admin-dashboard.php | 4 +++- includes/admin/class-wc-admin-exporters.php | 4 +++- includes/admin/class-wc-admin-importers.php | 8 +++++--- includes/admin/class-wc-admin-meta-boxes.php | 4 +++- includes/admin/class-wc-admin-post-types.php | 4 +++- includes/admin/class-wc-admin-settings.php | 4 +++- .../admin/class-wc-admin-setup-wizard.php | 4 +++- includes/admin/class-wc-admin-status.php | 6 +++++- includes/admin/helper/class-wc-helper.php | 4 +++- .../class-wc-settings-integrations.php | 4 +++- .../settings/class-wc-settings-shipping.php | 4 +++- .../html-notice-regenerating-lookup-table.php | 4 +++- includes/admin/views/html-notice-updating.php | 4 +++- includes/class-wc-ajax.php | 4 +++- includes/class-wc-background-emailer.php | 4 +++- includes/class-wc-emails.php | 4 +++- includes/class-wc-frontend-scripts.php | 6 ++++-- includes/class-wc-install.php | 4 +++- includes/class-wc-logger.php | 14 +++++++++---- includes/class-wc-session-handler.php | 4 +++- includes/class-wc-shipping.php | 4 +++- includes/class-wc-tracker.php | 6 ++++-- includes/class-wc-webhook.php | 4 +++- includes/class-woocommerce.php | 10 ++++++---- includes/cli/class-wc-cli-rest-command.php | 6 ++++-- .../paypal/class-wc-gateway-paypal.php | 4 +++- includes/libraries/class-wc-eval-math.php | 5 ++++- .../log-handlers/class-wc-log-handler-db.php | 4 +++- .../class-wc-log-handler-file.php | 4 +++- includes/tracks/class-wc-tracks-client.php | 13 ++++++------ includes/tracks/class-wc-tracks-event.php | 7 +++---- .../events/class-wc-products-tracking.php | 4 +++- includes/wc-cart-functions.php | 4 +++- includes/wc-conditional-functions.php | 8 +++++--- includes/wc-core-functions.php | 20 +++++++++++-------- includes/wc-deprecated-functions.php | 4 +++- includes/wc-product-functions.php | 4 +++- ...ccom-site-installer-requirements-check.php | 4 +++- .../widgets/class-wc-widget-price-filter.php | 4 +++- .../framework/helpers/class-wc-helper-fee.php | 10 ++++++---- tests/includes/wp-http-testcase.php | 8 +++++--- .../util/class-wc-tests-core-functions.php | 6 ++++-- uninstall.php | 4 +++- 46 files changed, 177 insertions(+), 82 deletions(-) diff --git a/includes/abstracts/abstract-wc-payment-gateway.php b/includes/abstracts/abstract-wc-payment-gateway.php index 6930fccec99..180c3f05adf 100644 --- a/includes/abstracts/abstract-wc-payment-gateway.php +++ b/includes/abstracts/abstract-wc-payment-gateway.php @@ -9,6 +9,8 @@ * @package WooCommerce/Abstracts */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -450,7 +452,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API { public function tokenization_script() { wp_enqueue_script( 'woocommerce-tokenization-form', - plugins_url( '/assets/js/frontend/tokenization-form' . ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ) . '.js', WC_PLUGIN_FILE ), + plugins_url( '/assets/js/frontend/tokenization-form' . ( Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min' ) . '.js', WC_PLUGIN_FILE ), array( 'jquery' ), WC()->version ); diff --git a/includes/abstracts/abstract-wc-widget.php b/includes/abstracts/abstract-wc-widget.php index a65a3914c61..c2f6f1bf298 100644 --- a/includes/abstracts/abstract-wc-widget.php +++ b/includes/abstracts/abstract-wc-widget.php @@ -6,6 +6,8 @@ * @package WooCommerce/Abstracts */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -319,7 +321,7 @@ abstract class WC_Widget extends WP_Widget { * @since 3.3.0 */ protected function get_current_page_url() { - if ( defined( 'SHOP_IS_ON_FRONT' ) ) { + if ( Constants::is_defined( 'SHOP_IS_ON_FRONT' ) ) { $link = home_url(); } elseif ( is_shop() ) { $link = get_permalink( wc_get_page_id( 'shop' ) ); diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index baabe2594c2..9f09ef53c2d 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -6,6 +6,8 @@ * @version 3.7.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -88,7 +90,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : $screen = get_current_screen(); $screen_id = $screen ? $screen->id : ''; $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; // Register scripts. wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION ); @@ -234,7 +236,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : 'save_variations_nonce' => wp_create_nonce( 'save-variations' ), 'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ), /* translators: %d: Number of variations */ - 'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), defined( 'WC_MAX_LINKED_VARIATIONS' ) ? WC_MAX_LINKED_VARIATIONS : 50 ) ), + 'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), Constants::is_defined( 'WC_MAX_LINKED_VARIATIONS' ) ? Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ) : 50 ) ), 'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ), 'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ), 'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ), diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index 33621090e1d..5697065b302 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -6,6 +6,8 @@ * @version 2.1.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } @@ -322,7 +324,7 @@ if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) : * Network orders widget. */ public function network_orders() { - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION ); diff --git a/includes/admin/class-wc-admin-exporters.php b/includes/admin/class-wc-admin-exporters.php index be599f7db2d..336a97eb942 100644 --- a/includes/admin/class-wc-admin-exporters.php +++ b/includes/admin/class-wc-admin-exporters.php @@ -6,6 +6,8 @@ * @version 3.1.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -84,7 +86,7 @@ class WC_Admin_Exporters { * Enqueue scripts. */ public function admin_scripts() { - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); wp_localize_script( 'wc-product-export', diff --git a/includes/admin/class-wc-admin-importers.php b/includes/admin/class-wc-admin-importers.php index 65c477e546d..6f02008aef4 100644 --- a/includes/admin/class-wc-admin-importers.php +++ b/includes/admin/class-wc-admin-importers.php @@ -5,6 +5,8 @@ * @package WooCommerce/Admin */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -81,7 +83,7 @@ class WC_Admin_Importers { * Register importer scripts. */ public function admin_scripts() { - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_register_script( 'wc-product-import', WC()->plugin_url() . '/assets/js/admin/wc-product-import' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true ); } @@ -92,7 +94,7 @@ class WC_Admin_Importers { * If we're on that screen, redirect to the custom one. */ public function product_importer() { - if ( defined( 'WP_LOAD_IMPORTERS' ) ) { + if ( Constants::is_defined( 'WP_LOAD_IMPORTERS' ) ) { wp_safe_redirect( admin_url( 'edit.php?post_type=product&page=product_importer' ) ); exit; } @@ -108,7 +110,7 @@ class WC_Admin_Importers { * Register WordPress based importers. */ public function register_importers() { - if ( defined( 'WP_LOAD_IMPORTERS' ) ) { + if ( Constants::is_defined( 'WP_LOAD_IMPORTERS' ) ) { add_action( 'import_start', array( $this, 'post_importer_compatibility' ) ); register_importer( 'woocommerce_product_csv', __( 'WooCommerce products (CSV)', 'woocommerce' ), __( 'Import products to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) ); register_importer( 'woocommerce_tax_rate_csv', __( 'WooCommerce tax rates (CSV)', 'woocommerce' ), __( 'Import tax rates to your store via a csv file.', 'woocommerce' ), array( $this, 'tax_rates_importer' ) ); diff --git a/includes/admin/class-wc-admin-meta-boxes.php b/includes/admin/class-wc-admin-meta-boxes.php index 89ec46dd3ae..dd50c90d3a5 100644 --- a/includes/admin/class-wc-admin-meta-boxes.php +++ b/includes/admin/class-wc-admin-meta-boxes.php @@ -7,6 +7,8 @@ * @package WooCommerce/Admin/Meta Boxes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -188,7 +190,7 @@ class WC_Admin_Meta_Boxes { } // Dont' save meta boxes for revisions or autosaves. - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { + if ( Constants::is_true( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { return; } diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index 99d3c6b6ccd..21430ad4fcd 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -6,6 +6,8 @@ * @version 3.3.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -294,7 +296,7 @@ class WC_Admin_Post_Types { */ public function bulk_and_quick_edit_save_post( $post_id, $post ) { // If this is an autosave, our form has not been submitted, so we don't want to do anything. - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + if ( Constants::is_true( 'DOING_AUTOSAVE' ) ) { return $post_id; } diff --git a/includes/admin/class-wc-admin-settings.php b/includes/admin/class-wc-admin-settings.php index 63587f17fb2..c47cd100e58 100644 --- a/includes/admin/class-wc-admin-settings.php +++ b/includes/admin/class-wc-admin-settings.php @@ -6,6 +6,8 @@ * @version 3.4.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -128,7 +130,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) : public static function output() { global $current_section, $current_tab; - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; do_action( 'woocommerce_settings_start' ); diff --git a/includes/admin/class-wc-admin-setup-wizard.php b/includes/admin/class-wc-admin-setup-wizard.php index d8e00367b09..76687495687 100644 --- a/includes/admin/class-wc-admin-setup-wizard.php +++ b/includes/admin/class-wc-admin-setup-wizard.php @@ -8,6 +8,8 @@ * @version 2.6.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -187,7 +189,7 @@ class WC_Admin_Setup_Wizard { public function enqueue_scripts() { // Whether or not there is a pending background install of Jetpack. $pending_jetpack = ! class_exists( 'Jetpack' ) && get_option( 'woocommerce_setup_background_installing_jetpack' ); - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.6' ); diff --git a/includes/admin/class-wc-admin-status.php b/includes/admin/class-wc-admin-status.php index 33b4c3bd676..73d7777e4dc 100644 --- a/includes/admin/class-wc-admin-status.php +++ b/includes/admin/class-wc-admin-status.php @@ -6,6 +6,8 @@ * @version 2.2.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -95,7 +97,9 @@ class WC_Admin_Status { * Show the logs page. */ public static function status_logs() { - if ( defined( 'WC_LOG_HANDLER' ) && 'WC_Log_Handler_DB' === WC_LOG_HANDLER ) { + $log_handler = Constants::get_constant( 'WC_LOG_HANDLER' ); + + if ( 'WC_Log_Handler_DB' === $log_handler ) { self::status_logs_db(); } else { self::status_logs_file(); diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index aafd65148ea..3296c82a89d 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -6,6 +6,8 @@ * @package WooCommerce/Admin */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -1665,7 +1667,7 @@ class WC_Helper { * @param string $level Optional, defaults to info, valid levels: emergency|alert|critical|error|warning|notice|info|debug. */ public static function log( $message, $level = 'info' ) { - if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { + if ( ! Constants::is_true( 'WP_DEBUG' ) ) { return; } diff --git a/includes/admin/settings/class-wc-settings-integrations.php b/includes/admin/settings/class-wc-settings-integrations.php index 5c6ab9e2602..248287f059f 100644 --- a/includes/admin/settings/class-wc-settings-integrations.php +++ b/includes/admin/settings/class-wc-settings-integrations.php @@ -8,6 +8,8 @@ * @version 2.1.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } @@ -41,7 +43,7 @@ if ( ! class_exists( 'WC_Settings_Integrations', false ) ) : $sections = array(); - if ( ! defined( 'WC_INSTALLING' ) ) { + if ( ! Constants::is_defined( 'WC_INSTALLING' ) ) { $integrations = WC()->integrations->get_integrations(); if ( ! $current_section && ! empty( $integrations ) ) { diff --git a/includes/admin/settings/class-wc-settings-shipping.php b/includes/admin/settings/class-wc-settings-shipping.php index b71310034e3..f34eb287011 100644 --- a/includes/admin/settings/class-wc-settings-shipping.php +++ b/includes/admin/settings/class-wc-settings-shipping.php @@ -6,6 +6,8 @@ * @version 2.6.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; if ( class_exists( 'WC_Settings_Shipping', false ) ) { @@ -49,7 +51,7 @@ class WC_Settings_Shipping extends WC_Settings_Page { 'classes' => __( 'Shipping classes', 'woocommerce' ), ); - if ( ! defined( 'WC_INSTALLING' ) ) { + if ( ! Constants::is_defined( 'WC_INSTALLING' ) ) { // Load shipping methods so we can show any global options they may have. $shipping_methods = WC()->shipping()->load_shipping_methods(); diff --git a/includes/admin/views/html-notice-regenerating-lookup-table.php b/includes/admin/views/html-notice-regenerating-lookup-table.php index f4ca01f67fc..8cf8bceb887 100644 --- a/includes/admin/views/html-notice-regenerating-lookup-table.php +++ b/includes/admin/views/html-notice-regenerating-lookup-table.php @@ -5,10 +5,12 @@ * @package WooCommerce/admin */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; $pending_actions_url = admin_url( 'admin.php?page=wc-status&tab=action-scheduler&s=wc_update_product_lookup_tables&status=pending' ); -$cron_disabled = defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON; +$cron_disabled = Constants::is_true( 'DISABLE_WP_CRON' ); $cron_cta = $cron_disabled ? __( 'You can manually run queued updates here.', 'woocommerce' ) : __( 'View progress →', 'woocommerce' ); ?>
diff --git a/includes/admin/views/html-notice-updating.php b/includes/admin/views/html-notice-updating.php index 67980996eb9..82a2ee7904a 100644 --- a/includes/admin/views/html-notice-updating.php +++ b/includes/admin/views/html-notice-updating.php @@ -5,12 +5,14 @@ * @package WooCommerce\Admin */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } $pending_actions_url = admin_url( 'admin.php?page=wc-status&tab=action-scheduler&s=woocommerce_run_update&status=pending' ); -$cron_disabled = defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON; +$cron_disabled = Constants::is_true( 'DISABLE_WP_CRON' ); $cron_cta = $cron_disabled ? __( 'You can manually run queued updates here.', 'woocommerce' ) : __( 'View progress →', 'woocommerce' ); ?>
diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index 89483356a05..b6368f7ff30 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -6,6 +6,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -62,7 +64,7 @@ class WC_AJAX { header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); header( 'X-Robots-Tag: noindex' ); status_header( 200 ); - } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + } elseif ( Constants::is_true( 'WP_DEBUG' ) ) { headers_sent( $file, $line ); trigger_error( "wc_ajax_headers cannot set headers - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine } diff --git a/includes/class-wc-background-emailer.php b/includes/class-wc-background-emailer.php index ecd143647b9..331fa87a27f 100644 --- a/includes/class-wc-background-emailer.php +++ b/includes/class-wc-background-emailer.php @@ -6,6 +6,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'WC_Background_Process', false ) ) { @@ -56,7 +58,7 @@ class WC_Background_Emailer extends WC_Background_Process { try { WC_Emails::send_queued_transactional_email( $callback['filter'], $callback['args'] ); } catch ( Exception $e ) { - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + if ( Constants::is_true( 'WP_DEBUG' ) ) { trigger_error( 'Transactional email triggered fatal error for callback ' . esc_html( $callback['filter'] ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } } diff --git a/includes/class-wc-emails.php b/includes/class-wc-emails.php index 8d788128119..3edef5e03f3 100644 --- a/includes/class-wc-emails.php +++ b/includes/class-wc-emails.php @@ -8,6 +8,8 @@ * @version 2.3.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -175,7 +177,7 @@ class WC_Emails { 'source' => 'transactional-emails', ) ); - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + if ( Constants::is_true( 'WP_DEBUG' ) ) { trigger_error( $error, E_USER_WARNING ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } } diff --git a/includes/class-wc-frontend-scripts.php b/includes/class-wc-frontend-scripts.php index 67ad3dab90d..b82749d5998 100644 --- a/includes/class-wc-frontend-scripts.php +++ b/includes/class-wc-frontend-scripts.php @@ -6,6 +6,8 @@ * @version 2.3.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -163,7 +165,7 @@ class WC_Frontend_Scripts { * Register all WC scripts. */ private static function register_scripts() { - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; $register_scripts = array( 'flexslider' => array( 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ), @@ -513,7 +515,7 @@ class WC_Frontend_Scripts { 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ), 'checkout_url' => WC_AJAX::get_endpoint( 'checkout' ), 'is_checkout' => is_checkout() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0, - 'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG, + 'debug_mode' => Constants::is_true( 'WP_DEBUG' ), 'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ), ); break; diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index fba3c6263e4..24a9aa1193c 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -6,6 +6,8 @@ * @version 3.0.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -162,7 +164,7 @@ class WC_Install { * This check is done on all requests and runs if the versions do not match. */ public static function check_version() { - if ( ! defined( 'IFRAME_REQUEST' ) && version_compare( get_option( 'woocommerce_version' ), WC()->version, '<' ) ) { + if ( ! Constants::is_defined( 'IFRAME_REQUEST' ) && version_compare( get_option( 'woocommerce_version' ), WC()->version, '<' ) ) { self::install(); do_action( 'woocommerce_updated' ); } diff --git a/includes/class-wc-logger.php b/includes/class-wc-logger.php index 9f0a68e22c6..41bb7f6db2e 100644 --- a/includes/class-wc-logger.php +++ b/includes/class-wc-logger.php @@ -7,6 +7,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -61,12 +63,16 @@ class WC_Logger implements WC_Logger_Interface { } } + // Support the constant as long as a valid log level has been set for it. + if ( null === $threshold ) { + $threshold = Constants::get_constant( 'WC_LOG_THRESHOLD' ); + if ( null !== $threshold && ! WC_Log_Levels::is_valid_level( $threshold ) ) { + $threshold = null; + } + } + if ( null !== $threshold ) { $threshold = WC_Log_Levels::get_level_severity( $threshold ); - } elseif ( defined( 'WC_LOG_THRESHOLD' ) && WC_Log_Levels::is_valid_level( WC_LOG_THRESHOLD ) ) { - $threshold = WC_Log_Levels::get_level_severity( WC_LOG_THRESHOLD ); - } else { - $threshold = null; } $this->handlers = $register_handlers; diff --git a/includes/class-wc-session-handler.php b/includes/class-wc-session-handler.php index 0818329a7c2..689e61e083e 100644 --- a/includes/class-wc-session-handler.php +++ b/includes/class-wc-session-handler.php @@ -10,6 +10,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -316,7 +318,7 @@ class WC_Session_Handler extends WC_Session { public function get_session( $customer_id, $default = false ) { global $wpdb; - if ( defined( 'WP_SETUP_CONFIG' ) ) { + if ( Constants::is_defined( 'WP_SETUP_CONFIG' ) ) { return false; } diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index ef2bfe08ed3..81355da7583 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -8,6 +8,8 @@ * @package WooCommerce/Classes/Shipping */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -163,7 +165,7 @@ class WC_Shipping { $matched_zone_notice = sprintf( __( 'Customer matched zone "%s"', 'woocommerce' ), $shipping_zone->get_zone_name() ); // Debug output. - if ( $debug_mode && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! defined( 'WC_DOING_AJAX' ) && ! wc_has_notice( $matched_zone_notice ) ) { + if ( $debug_mode && ! Constants::is_defined( 'WOOCOMMERCE_CHECKOUT' ) && ! Constants::is_defined( 'WC_DOING_AJAX' ) && ! wc_has_notice( $matched_zone_notice ) ) { wc_add_notice( $matched_zone_notice ); } } else { diff --git a/includes/class-wc-tracker.php b/includes/class-wc-tracker.php index 372bf1aeb25..102ce0c376b 100644 --- a/includes/class-wc-tracker.php +++ b/includes/class-wc-tracker.php @@ -10,6 +10,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -38,7 +40,7 @@ class WC_Tracker { */ public static function send_tracking_data( $override = false ) { // Don't trigger this on AJAX Requests. - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + if ( Constants::is_true( 'DOING_AJAX' ) ) { return; } @@ -109,7 +111,7 @@ class WC_Tracker { $data['inactive_plugins'] = $all_plugins['inactive_plugins']; // Jetpack & WooCommerce Connect. - $data['jetpack_version'] = defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : 'none'; + $data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none'; $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no'; $data['jetpack_is_staging'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_staging_site' ) && Jetpack::is_staging_site() ) ? 'yes' : 'no'; $data['connect_installed'] = class_exists( 'WC_Connect_Loader' ) ? 'yes' : 'no'; diff --git a/includes/class-wc-webhook.php b/includes/class-wc-webhook.php index f5b7f1294f2..fecee6b4c80 100644 --- a/includes/class-wc-webhook.php +++ b/includes/class-wc-webhook.php @@ -11,6 +11,8 @@ * @since 2.2.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; require_once 'legacy/class-wc-legacy-webhook.php'; @@ -531,7 +533,7 @@ class WC_Webhook extends WC_Legacy_Webhook { 'Body' => $response_body, ); - if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { + if ( ! Constants::is_true( 'WP_DEBUG' ) ) { $message['Webhook Delivery']['Body'] = 'Webhook body is not logged unless WP_DEBUG mode is turned on. This is to avoid the storing of personal data in the logs.'; $message['Webhook Delivery']['Response']['Body'] = 'Webhook body is not logged unless WP_DEBUG mode is turned on. This is to avoid the storing of personal data in the logs.'; } diff --git a/includes/class-woocommerce.php b/includes/class-woocommerce.php index ffda8fe009c..0b44bc58f5c 100644 --- a/includes/class-woocommerce.php +++ b/includes/class-woocommerce.php @@ -6,6 +6,8 @@ * @since 3.2.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -297,11 +299,11 @@ final class WooCommerce { case 'admin': return is_admin(); case 'ajax': - return defined( 'DOING_AJAX' ); + return Constants::is_defined( 'DOING_AJAX' ); case 'cron': - return defined( 'DOING_CRON' ); + return Constants::is_defined( 'DOING_CRON' ); case 'frontend': - return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! $this->is_rest_api_request(); + return ( ! is_admin() || Constants::is_defined( 'DOING_AJAX' ) ) && ! Constants::is_defined( 'DOING_CRON' ) && ! $this->is_rest_api_request(); } } @@ -450,7 +452,7 @@ final class WooCommerce { */ include_once WC_ABSPATH . 'includes/libraries/action-scheduler/action-scheduler.php'; - if ( defined( 'WP_CLI' ) && WP_CLI ) { + if ( Constants::is_true( 'WP_CLI' ) ) { include_once WC_ABSPATH . 'includes/class-wc-cli.php'; } diff --git a/includes/cli/class-wc-cli-rest-command.php b/includes/cli/class-wc-cli-rest-command.php index ad15172198b..0e8eb2a81c9 100644 --- a/includes/cli/class-wc-cli-rest-command.php +++ b/includes/cli/class-wc-cli-rest-command.php @@ -5,6 +5,8 @@ * @package WooCommerce\Cli */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -286,11 +288,11 @@ class WC_CLI_REST_Command { $request->set_param( $key, $value ); } } - if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { + if ( Constants::is_true( 'SAVEQUERIES' ) ) { $original_queries = is_array( $GLOBALS['wpdb']->queries ) ? array_keys( $GLOBALS['wpdb']->queries ) : array(); } $response = rest_do_request( $request ); - if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { + if ( Constants::is_true( 'SAVEQUERIES' ) ) { $performed_queries = array(); foreach ( (array) $GLOBALS['wpdb']->queries as $key => $query ) { if ( in_array( $key, $original_queries, true ) ) { diff --git a/includes/gateways/paypal/class-wc-gateway-paypal.php b/includes/gateways/paypal/class-wc-gateway-paypal.php index bebf222af9b..d057d5babfd 100644 --- a/includes/gateways/paypal/class-wc-gateway-paypal.php +++ b/includes/gateways/paypal/class-wc-gateway-paypal.php @@ -10,6 +10,8 @@ * @package WooCommerce/Classes/Payment */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -450,7 +452,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { return; } - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_enqueue_script( 'woocommerce_paypal_admin', WC()->plugin_url() . '/includes/gateways/paypal/assets/js/paypal-admin' . $suffix . '.js', array(), WC_VERSION, true ); } diff --git a/includes/libraries/class-wc-eval-math.php b/includes/libraries/class-wc-eval-math.php index eaf174c5dc8..f4d5e5dc3d8 100644 --- a/includes/libraries/class-wc-eval-math.php +++ b/includes/libraries/class-wc-eval-math.php @@ -1,4 +1,7 @@ get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . ''; + $coupon_html = $discount_amount_html . ' ' . __( '[Remove]', 'woocommerce' ) . ''; echo wp_kses( apply_filters( 'woocommerce_cart_totals_coupon_html', $coupon_html, $coupon, $discount_amount_html ), array_replace_recursive( wp_kses_allowed_html( 'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound } diff --git a/includes/wc-conditional-functions.php b/includes/wc-conditional-functions.php index eb414263c34..53bc24b4f30 100644 --- a/includes/wc-conditional-functions.php +++ b/includes/wc-conditional-functions.php @@ -8,6 +8,8 @@ * @version 2.3.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -93,7 +95,7 @@ if ( ! function_exists( 'is_cart' ) ) { function is_cart() { $page_id = wc_get_page_id( 'cart' ); - return ( $page_id && is_page( $page_id ) ) || defined( 'WOOCOMMERCE_CART' ) || wc_post_content_has_shortcode( 'woocommerce_cart' ); + return ( $page_id && is_page( $page_id ) ) || Constants::is_defined( 'WOOCOMMERCE_CART' ) || wc_post_content_has_shortcode( 'woocommerce_cart' ); } } @@ -107,7 +109,7 @@ if ( ! function_exists( 'is_checkout' ) ) { function is_checkout() { $page_id = wc_get_page_id( 'checkout' ); - return ( $page_id && is_page( $page_id ) ) || wc_post_content_has_shortcode( 'woocommerce_checkout' ) || apply_filters( 'woocommerce_is_checkout', false ) || defined( 'WOOCOMMERCE_CHECKOUT' ); + return ( $page_id && is_page( $page_id ) ) || wc_post_content_has_shortcode( 'woocommerce_checkout' ) || apply_filters( 'woocommerce_is_checkout', false ) || Constants::is_defined( 'WOOCOMMERCE_CHECKOUT' ); } } @@ -262,7 +264,7 @@ if ( ! function_exists( 'is_ajax' ) ) { * @return bool */ function is_ajax() { - return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : defined( 'DOING_AJAX' ); + return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : Constants::is_defined( 'DOING_AJAX' ); } } diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index ce2f10b6c60..4233869ee76 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -8,6 +8,8 @@ * @version 3.3.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -887,7 +889,7 @@ function wc_print_js() { function wc_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { if ( ! headers_sent() ) { setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'woocommerce_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); - } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + } elseif ( Constants::is_true( 'WP_DEBUG' ) ) { headers_sent( $file, $line ); trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine } @@ -901,7 +903,11 @@ function wc_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = * @return string the URL. */ function get_woocommerce_api_url( $path ) { - $version = defined( 'WC_API_REQUEST_VERSION' ) ? WC_API_REQUEST_VERSION : substr( WC_API::VERSION, 0, 1 ); + if ( Constants::is_defined( 'WC_API_REQUEST_VERSION' ) ) { + $version = Constants::get_constant( 'WC_API_REQUEST_VERSION' ); + } else { + $version = substr( WC_API::VERSION, 0, 1 ); + } $url = get_home_url( null, "wc-api/v{$version}/", is_ssl() ? 'https' : 'http' ); @@ -1847,14 +1853,12 @@ function wc_print_r( $expression, $return = false ) { * @return array */ function wc_register_default_log_handler( $handlers ) { - if ( defined( 'WC_LOG_HANDLER' ) && class_exists( WC_LOG_HANDLER ) ) { - $handler_class = WC_LOG_HANDLER; - $default_handler = new $handler_class(); - } else { - $default_handler = new WC_Log_Handler_File(); + $handler_class = Constants::get_constant( 'WC_LOG_HANDLER' ); + if ( ! class_exists( $handler_class ) ) { + $handler_class = WC_Log_Handler_File::class; } - array_push( $handlers, $default_handler ); + array_push( $handlers, new $handler_class() ); return $handlers; } diff --git a/includes/wc-deprecated-functions.php b/includes/wc-deprecated-functions.php index ca53046c7bb..80a31ae4620 100644 --- a/includes/wc-deprecated-functions.php +++ b/includes/wc-deprecated-functions.php @@ -10,6 +10,8 @@ * @version 3.3.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -897,7 +899,7 @@ function woocommerce_compile_less_styles() { * @return string */ function woocommerce_calc_shipping_backwards_compatibility( $value ) { - if ( defined( 'WC_UPDATING' ) ) { + if ( Constants::is_defined( 'WC_UPDATING' ) ) { return $value; } return 'disabled' === get_option( 'woocommerce_ship_to_countries' ) ? 'no' : 'yes'; diff --git a/includes/wc-product-functions.php b/includes/wc-product-functions.php index 87732f7c3fa..669cec53498 100644 --- a/includes/wc-product-functions.php +++ b/includes/wc-product-functions.php @@ -8,6 +8,8 @@ * @version 3.0.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -1334,7 +1336,7 @@ function wc_update_product_lookup_tables_is_running() { function wc_update_product_lookup_tables() { global $wpdb; - $is_cli = defined( 'WP_CLI' ) && WP_CLI; + $is_cli = Constants::is_true( 'WP_CLI' ); if ( ! $is_cli ) { WC_Admin_Notices::add_notice( 'regenerating_lookup_table' ); diff --git a/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php b/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php index a0a3cf277a0..8e54f3665ba 100644 --- a/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php +++ b/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php @@ -6,6 +6,8 @@ * @since 3.8.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -45,7 +47,7 @@ class WC_WCCOM_Site_Installer_Requirements_Check { * @return bool */ private static function met_wp_cron_requirement() { - return ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ); + return ! Constants::is_true( 'DISABLE_WP_CRON' ); } /** diff --git a/includes/widgets/class-wc-widget-price-filter.php b/includes/widgets/class-wc-widget-price-filter.php index 699a73971a8..98d00237170 100644 --- a/includes/widgets/class-wc-widget-price-filter.php +++ b/includes/widgets/class-wc-widget-price-filter.php @@ -8,6 +8,8 @@ * @version 2.3.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -30,7 +32,7 @@ class WC_Widget_Price_Filter extends WC_Widget { 'label' => __( 'Title', 'woocommerce' ), ), ); - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2', true ); wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), WC_VERSION, true ); wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), WC_VERSION, true ); diff --git a/tests/framework/helpers/class-wc-helper-fee.php b/tests/framework/helpers/class-wc-helper-fee.php index ac3b7927e0f..2dc8bfc89b1 100644 --- a/tests/framework/helpers/class-wc-helper-fee.php +++ b/tests/framework/helpers/class-wc-helper-fee.php @@ -1,5 +1,7 @@ assertFalse( defined( 'WC_TESTING_DEFINE_FUNCTION' ) ); + $this->assertFalse( Constants::is_defined( 'WC_TESTING_DEFINE_FUNCTION' ) ); // Check if defined. wc_maybe_define_constant( 'WC_TESTING_DEFINE_FUNCTION', true ); - $this->assertTrue( defined( 'WC_TESTING_DEFINE_FUNCTION' ) ); + $this->assertTrue( Constants::is_defined( 'WC_TESTING_DEFINE_FUNCTION' ) ); // Check value. wc_maybe_define_constant( 'WC_TESTING_DEFINE_FUNCTION', false ); diff --git a/uninstall.php b/uninstall.php index 5b1c071fad9..9eaf3732834 100644 --- a/uninstall.php +++ b/uninstall.php @@ -8,6 +8,8 @@ * @version 2.3.0 */ +use Automattic\Jetpack\Constants; + defined( 'WP_UNINSTALL_PLUGIN' ) || exit; global $wpdb, $wp_version; @@ -25,7 +27,7 @@ wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); * wp-config.php. This is to prevent data loss when deleting the plugin from the backend * and to ensure only the site owner can perform this action. */ -if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { +if ( Constants::is_true( 'WC_REMOVE_ALL_DATA' ) ) { include_once dirname( __FILE__ ) . '/includes/class-wc-install.php'; // Roles + caps. From 1d1413b4ee669cd37ee025c93972ce785a10a0b9 Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Fri, 31 Jan 2020 22:18:47 -0800 Subject: [PATCH 3/5] Replaced direct access of many constants with the Constants library --- .../abstract-wc-deprecated-hooks.php | 4 +- includes/admin/class-wc-admin-addons.php | 4 +- includes/admin/class-wc-admin-assets.php | 76 +++++++++---------- includes/admin/class-wc-admin-dashboard.php | 4 +- includes/admin/class-wc-admin-exporters.php | 2 +- includes/admin/class-wc-admin-importers.php | 2 +- includes/admin/class-wc-admin-notices.php | 4 +- .../admin/class-wc-admin-setup-wizard.php | 7 +- includes/admin/helper/class-wc-helper.php | 4 +- .../class-wc-plugin-updates.php | 4 +- .../class-wc-plugins-screen-updates.php | 6 +- includes/class-wc-ajax.php | 2 +- includes/class-wc-frontend-scripts.php | 44 +++++------ includes/class-wc-webhook.php | 4 +- .../abstract-wc-order-data-store-cpt.php | 6 +- .../class-wc-product-data-store-cpt.php | 4 +- ...ss-wc-product-variation-data-store-cpt.php | 4 +- .../paypal/class-wc-gateway-paypal.php | 2 +- .../class-wc-gateway-paypal-pdt-handler.php | 4 +- .../class-wc-twenty-nineteen.php | 4 +- .../class-wc-twenty-seventeen.php | 4 +- .../theme-support/class-wc-twenty-twenty.php | 4 +- includes/wc-core-functions.php | 6 +- includes/wc-template-functions.php | 6 +- .../widgets/class-wc-widget-price-filter.php | 4 +- tests/unit-tests/core/main-class.php | 4 +- .../order/class-wc-tests-order-functions.php | 4 +- 27 files changed, 126 insertions(+), 97 deletions(-) diff --git a/includes/abstracts/abstract-wc-deprecated-hooks.php b/includes/abstracts/abstract-wc-deprecated-hooks.php index 77acca23686..c7cb4c56975 100644 --- a/includes/abstracts/abstract-wc-deprecated-hooks.php +++ b/includes/abstracts/abstract-wc-deprecated-hooks.php @@ -7,6 +7,8 @@ * @version 3.3.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -94,7 +96,7 @@ abstract class WC_Deprecated_Hooks { * @return string */ protected function get_deprecated_version( $old_hook ) { - return ! empty( $this->deprecated_version[ $old_hook ] ) ? $this->deprecated_version[ $old_hook ] : WC_VERSION; + return ! empty( $this->deprecated_version[ $old_hook ] ) ? $this->deprecated_version[ $old_hook ] : Constants::get_constant( 'WC_VERSION' ); } /** diff --git a/includes/admin/class-wc-admin-addons.php b/includes/admin/class-wc-admin-addons.php index c4ba6b50c9a..31e9adac3a3 100644 --- a/includes/admin/class-wc-admin-addons.php +++ b/includes/admin/class-wc-admin-addons.php @@ -6,6 +6,8 @@ * @version 2.5.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -489,7 +491,7 @@ class WC_Admin_Addons { return array( 'wccom-site' => site_url(), 'wccom-back' => rawurlencode( $back_admin_path ), - 'wccom-woo-version' => WC_VERSION, + 'wccom-woo-version' => Constants::get_constant( 'WC_VERSION' ), 'wccom-connect-nonce' => wp_create_nonce( 'connect' ), ); } diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index 9f09ef53c2d..adfd14074d9 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -37,12 +37,12 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : $screen_id = $screen ? $screen->id : ''; // Register admin styles. - wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC_VERSION ); - wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); - wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), WC_VERSION ); - wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION ); - wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' ); - wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), WC_VERSION ); + wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), Constants::get_constant( 'WC_VERSION' ), 'print' ); + wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), Constants::get_constant( 'WC_VERSION' ) ); // Add RTL support for admin styles. wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' ); @@ -93,29 +93,29 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; // Register scripts. - wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION ); + wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), Constants::get_constant( 'WC_VERSION' ) ); wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); - wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true ); - wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), WC_VERSION ); - wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' ); - wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION ); - wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), WC_VERSION ); - wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION ); - wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION ); - wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION ); - wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.6' ); - wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION ); + wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), Constants::get_constant( 'WC_VERSION' ) ); wp_register_script( 'js-cookie', WC()->plugin_url() . '/assets/js/js-cookie/js.cookie' . $suffix . '.js', array(), '2.1.4', true ); wp_localize_script( @@ -148,7 +148,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : ) ); - wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION ); + wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), Constants::get_constant( 'WC_VERSION' ) ); wp_localize_script( 'wc-orders', 'wc_orders_params', @@ -204,7 +204,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Products. if ( in_array( $screen_id, array( 'edit-product' ) ) ) { - wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), WC_VERSION ); + wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), Constants::get_constant( 'WC_VERSION' ) ); $params = array( 'strings' => array( @@ -218,8 +218,8 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Meta boxes. if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) { wp_enqueue_media(); - wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), WC_VERSION ); - wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), WC_VERSION ); + wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), Constants::get_constant( 'WC_VERSION' ) ); wp_enqueue_script( 'wc-admin-product-meta-boxes' ); wp_enqueue_script( 'wc-admin-variation-meta-boxes' ); @@ -261,7 +261,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) { $default_location = wc_get_customer_default_location(); - wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), WC_VERSION ); + wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), Constants::get_constant( 'WC_VERSION' ) ); wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', @@ -276,7 +276,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : ); } if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { - wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION ); + wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), Constants::get_constant( 'WC_VERSION' ) ); wp_localize_script( 'wc-admin-coupon-meta-boxes', 'woocommerce_admin_meta_boxes_coupon', @@ -367,7 +367,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Term ordering - only when sorting by term_order. if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( wp_unslash( $_GET['taxonomy'] ), apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) { - wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION ); + wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), Constants::get_constant( 'WC_VERSION' ) ); wp_enqueue_script( 'woocommerce_term_ordering' ); $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : ''; @@ -381,13 +381,13 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Product sorting - only when sorting by menu order on the products page. if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) { - wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true ); + wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), Constants::get_constant( 'WC_VERSION' ), true ); wp_enqueue_script( 'woocommerce_product_ordering' ); } // Reports Pages. if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) { - wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), WC_VERSION ); + wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), Constants::get_constant( 'WC_VERSION' ) ); wp_enqueue_script( 'wc-reports' ); wp_enqueue_script( 'flot' ); @@ -399,7 +399,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // API settings. if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) { - wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), WC_VERSION, true ); + wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), Constants::get_constant( 'WC_VERSION' ), true ); wp_enqueue_script( 'wc-api-keys' ); wp_localize_script( 'wc-api-keys', @@ -414,7 +414,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // System status. if ( $wc_screen_id . '_page_wc-status' === $screen_id ) { - wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), WC_VERSION ); + wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), Constants::get_constant( 'WC_VERSION' ) ); wp_enqueue_script( 'wc-admin-system-status' ); wp_localize_script( 'wc-admin-system-status', @@ -426,7 +426,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : } if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) { - wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), WC_VERSION, true ); + wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), Constants::get_constant( 'WC_VERSION' ), true ); wp_enqueue_script( 'wc-users' ); wp_localize_script( 'wc-users', @@ -444,7 +444,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : 'marketplace-suggestions', WC()->plugin_url() . '/assets/js/admin/marketplace-suggestions' . $suffix . '.js', array( 'jquery', 'underscore', 'js-cookie' ), - WC_VERSION, + Constants::get_constant( 'WC_VERSION' ), true ); wp_localize_script( diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index 5697065b302..5f6dd06f071 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -326,9 +326,9 @@ if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) : public function network_orders() { $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; - wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION ); + wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), Constants::get_constant( 'WC_VERSION' ) ); - wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true ); + wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), Constants::get_constant( 'WC_VERSION' ), true ); $user = wp_get_current_user(); $blogs = get_blogs_of_user( $user->ID ); diff --git a/includes/admin/class-wc-admin-exporters.php b/includes/admin/class-wc-admin-exporters.php index 336a97eb942..212214e68f1 100644 --- a/includes/admin/class-wc-admin-exporters.php +++ b/includes/admin/class-wc-admin-exporters.php @@ -87,7 +87,7 @@ class WC_Admin_Exporters { */ public function admin_scripts() { $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; - wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); wp_localize_script( 'wc-product-export', 'wc_product_export_params', diff --git a/includes/admin/class-wc-admin-importers.php b/includes/admin/class-wc-admin-importers.php index 6f02008aef4..4a22fa3e292 100644 --- a/includes/admin/class-wc-admin-importers.php +++ b/includes/admin/class-wc-admin-importers.php @@ -84,7 +84,7 @@ class WC_Admin_Importers { */ public function admin_scripts() { $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; - wp_register_script( 'wc-product-import', WC()->plugin_url() . '/assets/js/admin/wc-product-import' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true ); + wp_register_script( 'wc-product-import', WC()->plugin_url() . '/assets/js/admin/wc-product-import' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ), true ); } /** diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 76ba356bd6c..19d1fa07414 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -6,6 +6,8 @@ * @version 3.4.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -166,7 +168,7 @@ class WC_Admin_Notices { return; } - wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ), array(), WC_VERSION ); + wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ), array(), Constants::get_constant( 'WC_VERSION' ) ); // Add RTL support. wp_style_add_data( 'woocommerce-activation', 'rtl', 'replace' ); diff --git a/includes/admin/class-wc-admin-setup-wizard.php b/includes/admin/class-wc-admin-setup-wizard.php index 76687495687..9b50c1bc13d 100644 --- a/includes/admin/class-wc-admin-setup-wizard.php +++ b/includes/admin/class-wc-admin-setup-wizard.php @@ -193,7 +193,7 @@ class WC_Admin_Setup_Wizard { wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.6' ); - wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION ); + wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), Constants::get_constant( 'WC_VERSION' ) ); wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', @@ -213,10 +213,9 @@ class WC_Admin_Setup_Wizard { 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), ) ); - wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); - wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), WC_VERSION ); + wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util', 'jquery-tiptip', 'backbone', 'wc-backbone-modal' ), WC_VERSION ); wp_localize_script( 'wc-setup', 'wc_setup_params', diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 3296c82a89d..42500a0b983 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -470,7 +470,7 @@ class WC_Helper { $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); if ( $wc_screen_id . '_page_wc-addons' === $screen_id && isset( $_GET['section'] ) && 'helper' === $_GET['section'] ) { - wp_enqueue_style( 'woocommerce-helper', WC()->plugin_url() . '/assets/css/helper.css', array(), WC_VERSION ); + wp_enqueue_style( 'woocommerce-helper', WC()->plugin_url() . '/assets/css/helper.css', array(), Constants::get_constant( 'WC_VERSION' ) ); } } @@ -1584,7 +1584,7 @@ class WC_Helper { } $data = $updates->response['woocommerce/woocommerce.php']; - if ( version_compare( WC_VERSION, $data->new_version, '>=' ) ) { + if ( version_compare( Constants::get_constant( 'WC_VERSION' ), $data->new_version, '>=' ) ) { return false; } diff --git a/includes/admin/plugin-updates/class-wc-plugin-updates.php b/includes/admin/plugin-updates/class-wc-plugin-updates.php index fc0d70f78a1..809dc91b1ef 100644 --- a/includes/admin/plugin-updates/class-wc-plugin-updates.php +++ b/includes/admin/plugin-updates/class-wc-plugin-updates.php @@ -6,6 +6,8 @@ * @version 3.2.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -188,7 +190,7 @@ class WC_Plugin_Updates { } if ( 'major' === $release ) { - $current_version_parts = explode( '.', WC_VERSION ); + $current_version_parts = explode( '.', Constants::get_constant( 'WC_VERSION' ) ); // If user has already moved to the major version, we don't need to flag up anything. if ( version_compare( $current_version_parts[0] . '.' . $current_version_parts[1], $new_version_parts[0] . '.0', '>=' ) ) { diff --git a/includes/admin/plugin-updates/class-wc-plugins-screen-updates.php b/includes/admin/plugin-updates/class-wc-plugins-screen-updates.php index 2b34a24fd4f..f544f408582 100644 --- a/includes/admin/plugin-updates/class-wc-plugins-screen-updates.php +++ b/includes/admin/plugin-updates/class-wc-plugins-screen-updates.php @@ -6,6 +6,8 @@ * @version 3.2.0 */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -45,7 +47,7 @@ class WC_Plugins_Screen_Updates extends WC_Plugin_Updates { $this->major_untested_plugins = $this->get_untested_plugins( $response->new_version, 'major' ); $this->minor_untested_plugins = $this->get_untested_plugins( $response->new_version, 'minor' ); - $current_version_parts = explode( '.', WC_VERSION ); + $current_version_parts = explode( '.', Constants::get_constant( 'WC_VERSION' ) ); $new_version_parts = explode( '.', $this->new_version ); // If user has already moved to the minor version, we don't need to flag up anything. @@ -109,7 +111,7 @@ class WC_Plugins_Screen_Updates extends WC_Plugin_Updates { $upgrade_notice = ''; foreach ( $check_for_notices as $check_version ) { - if ( version_compare( WC_VERSION, $check_version, '>' ) ) { + if ( version_compare( Constants::get_constant( 'WC_VERSION' ), $check_version, '>' ) ) { continue; } diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index b6368f7ff30..1dade2307b2 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -746,7 +746,7 @@ class WC_AJAX { wp_die(); } - echo esc_html( $data_store->create_all_product_variations( $product, WC_MAX_LINKED_VARIATIONS ) ); + echo esc_html( $data_store->create_all_product_variations( $product, Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ) ) ); $data_store->sort_all_product_variations( $product->get_id() ); wp_die(); diff --git a/includes/class-wc-frontend-scripts.php b/includes/class-wc-frontend-scripts.php index b82749d5998..063c8c3a106 100644 --- a/includes/class-wc-frontend-scripts.php +++ b/includes/class-wc-frontend-scripts.php @@ -59,21 +59,21 @@ class WC_Frontend_Scripts { 'woocommerce-layout' => array( 'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ), 'deps' => '', - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'all', 'has_rtl' => true, ), 'woocommerce-smallscreen' => array( 'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ), 'deps' => 'woocommerce-layout', - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')', 'has_rtl' => true, ), 'woocommerce-general' => array( 'src' => self::get_asset_url( 'assets/css/woocommerce.css' ), 'deps' => '', - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'all', 'has_rtl' => true, ), @@ -210,7 +210,7 @@ class WC_Frontend_Scripts { 'prettyPhoto-init' => array( // deprecated. 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ), 'deps' => array( 'jquery', 'prettyPhoto' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'select2' => array( 'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ), @@ -225,72 +225,72 @@ class WC_Frontend_Scripts { 'wc-address-i18n' => array( 'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ), 'deps' => array( 'jquery', 'wc-country-select' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-add-payment-method' => array( 'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-cart' => array( 'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-cart-fragments' => array( 'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ), 'deps' => array( 'jquery', 'js-cookie' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-checkout' => array( 'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-country-select' => array( 'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ), 'deps' => array( 'jquery' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-credit-card-form' => array( 'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ), 'deps' => array( 'jquery', 'jquery-payment' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-add-to-cart' => array( 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ), 'deps' => array( 'jquery', 'jquery-blockui' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-add-to-cart-variation' => array( 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ), 'deps' => array( 'jquery', 'wp-util', 'jquery-blockui' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-geolocation' => array( 'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ), 'deps' => array( 'jquery' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-lost-password' => array( 'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-password-strength-meter' => array( 'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ), 'deps' => array( 'jquery', 'password-strength-meter' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'wc-single-product' => array( 'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ), 'deps' => array( 'jquery' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'woocommerce' => array( 'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ), 'deps' => array( 'jquery', 'jquery-blockui', 'js-cookie' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), ), 'zoom' => array( 'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ), @@ -311,25 +311,25 @@ class WC_Frontend_Scripts { 'photoswipe' => array( 'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.min.css' ), 'deps' => array(), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'has_rtl' => false, ), 'photoswipe-default-skin' => array( 'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.min.css' ), 'deps' => array( 'photoswipe' ), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'has_rtl' => false, ), 'select2' => array( 'src' => self::get_asset_url( 'assets/css/select2.css' ), 'deps' => array(), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'has_rtl' => false, ), 'woocommerce_prettyPhoto_css' => array( // deprecated. 'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ), 'deps' => array(), - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'has_rtl' => true, ), ); diff --git a/includes/class-wc-webhook.php b/includes/class-wc-webhook.php index fecee6b4c80..36e4cbbd66c 100644 --- a/includes/class-wc-webhook.php +++ b/includes/class-wc-webhook.php @@ -299,7 +299,7 @@ class WC_Webhook extends WC_Legacy_Webhook { 'redirection' => 0, 'httpversion' => '1.0', 'blocking' => true, - 'user-agent' => sprintf( 'WooCommerce/%s Hookshot (WordPress/%s)', WC_VERSION, $GLOBALS['wp_version'] ), + 'user-agent' => sprintf( 'WooCommerce/%s Hookshot (WordPress/%s)', Constants::get_constant( 'WC_VERSION' ), $GLOBALS['wp_version'] ), 'body' => trim( wp_json_encode( $payload ) ), 'headers' => array( 'Content-Type' => 'application/json', @@ -612,7 +612,7 @@ class WC_Webhook extends WC_Legacy_Webhook { */ public function deliver_ping() { $args = array( - 'user-agent' => sprintf( 'WooCommerce/%s Hookshot (WordPress/%s)', WC_VERSION, $GLOBALS['wp_version'] ), + 'user-agent' => sprintf( 'WooCommerce/%s Hookshot (WordPress/%s)', Constants::get_constant( 'WC_VERSION' ), $GLOBALS['wp_version'] ), 'body' => 'webhook_id=' . $this->get_id(), ); diff --git a/includes/data-stores/abstract-wc-order-data-store-cpt.php b/includes/data-stores/abstract-wc-order-data-store-cpt.php index 18f60caa5b7..687562d8417 100644 --- a/includes/data-stores/abstract-wc-order-data-store-cpt.php +++ b/includes/data-stores/abstract-wc-order-data-store-cpt.php @@ -5,6 +5,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -54,7 +56,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme * @param WC_Order $order Order object. */ public function create( &$order ) { - $order->set_version( WC_VERSION ); + $order->set_version( Constants::get_constant( 'WC_VERSION' ) ); $order->set_date_created( time() ); $order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() ); @@ -131,7 +133,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme */ public function update( &$order ) { $order->save_meta_data(); - $order->set_version( WC_VERSION ); + $order->set_version( Constants::get_constant( 'WC_VERSION' ) ); if ( null === $order->get_date_created( 'edit' ) ) { $order->set_date_created( time() ); diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 9d951bd4a90..07e77b11b28 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -5,6 +5,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -823,7 +825,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da $new_type = $product->get_type(); wp_set_object_terms( $product->get_id(), $new_type, 'product_type' ); - update_post_meta( $product->get_id(), '_product_version', WC_VERSION ); + update_post_meta( $product->get_id(), '_product_version', Constants::get_constant( 'WC_VERSION' ) ); // Action for the transition. if ( $old_type !== $new_type ) { diff --git a/includes/data-stores/class-wc-product-variation-data-store-cpt.php b/includes/data-stores/class-wc-product-variation-data-store-cpt.php index a4d4071273a..2dd1d116678 100644 --- a/includes/data-stores/class-wc-product-variation-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variation-data-store-cpt.php @@ -5,6 +5,8 @@ * @package WooCommerce\DataStores */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -333,7 +335,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl */ protected function update_version_and_type( &$product ) { wp_set_object_terms( $product->get_id(), '', 'product_type' ); - update_post_meta( $product->get_id(), '_product_version', WC_VERSION ); + update_post_meta( $product->get_id(), '_product_version', Constants::get_constant( 'WC_VERSION' ) ); } /** diff --git a/includes/gateways/paypal/class-wc-gateway-paypal.php b/includes/gateways/paypal/class-wc-gateway-paypal.php index d057d5babfd..3047f8c58d5 100644 --- a/includes/gateways/paypal/class-wc-gateway-paypal.php +++ b/includes/gateways/paypal/class-wc-gateway-paypal.php @@ -454,7 +454,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; - wp_enqueue_script( 'woocommerce_paypal_admin', WC()->plugin_url() . '/includes/gateways/paypal/assets/js/paypal-admin' . $suffix . '.js', array(), WC_VERSION, true ); + wp_enqueue_script( 'woocommerce_paypal_admin', WC()->plugin_url() . '/includes/gateways/paypal/assets/js/paypal-admin' . $suffix . '.js', array(), Constants::get_constant( 'WC_VERSION' ), true ); } /** diff --git a/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php b/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php index d8ead0f5faf..c37d4d1462e 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-pdt-handler.php @@ -5,6 +5,8 @@ * @package WooCommerce\Gateways */ +use Automattic\Jetpack\Constants; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -51,7 +53,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response { ), 'timeout' => 60, 'httpversion' => '1.1', - 'user-agent' => 'WooCommerce/' . WC_VERSION, + 'user-agent' => 'WooCommerce/' . Constants::get_constant( 'WC_VERSION' ), ); // Post back to get a response. diff --git a/includes/theme-support/class-wc-twenty-nineteen.php b/includes/theme-support/class-wc-twenty-nineteen.php index 84a0c73d2d7..a0bcf9f443e 100644 --- a/includes/theme-support/class-wc-twenty-nineteen.php +++ b/includes/theme-support/class-wc-twenty-nineteen.php @@ -6,6 +6,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -78,7 +80,7 @@ class WC_Twenty_Nineteen { $styles['woocommerce-general'] = array( 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-nineteen.css', 'deps' => '', - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'all', 'has_rtl' => true, ); diff --git a/includes/theme-support/class-wc-twenty-seventeen.php b/includes/theme-support/class-wc-twenty-seventeen.php index 2c69bf90135..cca349a2175 100644 --- a/includes/theme-support/class-wc-twenty-seventeen.php +++ b/includes/theme-support/class-wc-twenty-seventeen.php @@ -6,6 +6,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -49,7 +51,7 @@ class WC_Twenty_Seventeen { $styles['woocommerce-general'] = array( 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-seventeen.css', 'deps' => '', - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'all', 'has_rtl' => true, ); diff --git a/includes/theme-support/class-wc-twenty-twenty.php b/includes/theme-support/class-wc-twenty-twenty.php index 4045ef6a30e..35bf512b205 100644 --- a/includes/theme-support/class-wc-twenty-twenty.php +++ b/includes/theme-support/class-wc-twenty-twenty.php @@ -6,6 +6,8 @@ * @package WooCommerce/Classes */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -92,7 +94,7 @@ class WC_Twenty_Twenty { $styles['woocommerce-general'] = array( 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-twenty.css', 'deps' => '', - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'all', 'has_rtl' => true, ); diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index 4233869ee76..2a047018e18 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -159,7 +159,7 @@ function wc_update_order( $args ) { * @param string $name Template name (default: ''). */ function wc_get_template_part( $slug, $name = '' ) { - $cache_key = sanitize_key( implode( '-', array( 'template-part', $slug, $name, WC_VERSION ) ) ); + $cache_key = sanitize_key( implode( '-', array( 'template-part', $slug, $name, Constants::get_constant( 'WC_VERSION' ) ) ) ); $template = (string) wp_cache_get( $cache_key, 'woocommerce' ); if ( ! $template ) { @@ -207,7 +207,7 @@ function wc_get_template_part( $slug, $name = '' ) { * @param string $default_path Default path. (default: ''). */ function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { - $cache_key = sanitize_key( implode( '-', array( 'template', $template_name, $template_path, $default_path, WC_VERSION ) ) ); + $cache_key = sanitize_key( implode( '-', array( 'template', $template_name, $template_path, $default_path, Constants::get_constant( 'WC_VERSION' ) ) ) ); $template = (string) wp_cache_get( $cache_key, 'woocommerce' ); if ( ! $template ) { @@ -1298,7 +1298,7 @@ function wc_transaction_query( $type = 'start', $force = false ) { wc_maybe_define_constant( 'WC_USE_TRANSACTIONS', true ); - if ( WC_USE_TRANSACTIONS || $force ) { + if ( Constants::is_true( 'WC_USE_TRANSACTIONS' ) || $force ) { switch ( $type ) { case 'commit': $wpdb->query( 'COMMIT' ); diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 40ba942adb8..d07e13b8b00 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -8,6 +8,8 @@ * @version 2.5.0 */ +use Automattic\Jetpack\Constants; + defined( 'ABSPATH' ) || exit; /** @@ -252,10 +254,10 @@ function woocommerce_product_loop() { function wc_generator_tag( $gen, $type ) { switch ( $type ) { case 'html': - $gen .= "\n" . ''; + $gen .= "\n" . ''; break; case 'xhtml': - $gen .= "\n" . ''; + $gen .= "\n" . ''; break; } return $gen; diff --git a/includes/widgets/class-wc-widget-price-filter.php b/includes/widgets/class-wc-widget-price-filter.php index 98d00237170..4add29cb2a3 100644 --- a/includes/widgets/class-wc-widget-price-filter.php +++ b/includes/widgets/class-wc-widget-price-filter.php @@ -34,8 +34,8 @@ class WC_Widget_Price_Filter extends WC_Widget { ); $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2', true ); - wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), WC_VERSION, true ); - wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), WC_VERSION, true ); + wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), Constants::get_constant( 'WC_VERSION' ), true ); wp_localize_script( 'wc-price-slider', 'woocommerce_price_slider_params', diff --git a/tests/unit-tests/core/main-class.php b/tests/unit-tests/core/main-class.php index 2069750f92a..5e9d92f4223 100644 --- a/tests/unit-tests/core/main-class.php +++ b/tests/unit-tests/core/main-class.php @@ -1,5 +1,7 @@ assertEquals( str_replace( 'tests/unit-tests/core/', '', plugin_dir_path( __FILE__ ) ) . 'woocommerce.php', WC_PLUGIN_FILE ); - $this->assertEquals( $this->wc->version, WC_VERSION ); + $this->assertEquals( $this->wc->version, Constants::get_constant( 'WC_VERSION' ) ); $this->assertEquals( WC_VERSION, WOOCOMMERCE_VERSION ); $this->assertEquals( 6, WC_ROUNDING_PRECISION ); $this->assertEquals( 2, WC_DISCOUNT_ROUNDING_MODE ); diff --git a/tests/unit-tests/order/class-wc-tests-order-functions.php b/tests/unit-tests/order/class-wc-tests-order-functions.php index 81e94b0e73a..a2dcb479f39 100644 --- a/tests/unit-tests/order/class-wc-tests-order-functions.php +++ b/tests/unit-tests/order/class-wc-tests-order-functions.php @@ -5,6 +5,8 @@ * @package WooCommerce/Tests */ +use Automattic\Jetpack\Constants; + /** * Class Functions. * @@ -368,7 +370,7 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case { $orders = wc_get_orders( array( - 'version' => WC_VERSION, + 'version' => Constants::get_constant( 'WC_VERSION' ), 'return' => 'ids', ) ); From bf02776a3b92d6f4736d90a15b3d337d95087bd4 Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Mon, 3 Feb 2020 13:15:12 -0800 Subject: [PATCH 4/5] Corrected inconsistent uses of the Constants library --- includes/admin/class-wc-admin-setup-wizard.php | 1 + includes/tracks/class-wc-tracks-event.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-setup-wizard.php b/includes/admin/class-wc-admin-setup-wizard.php index b764d55e7e4..844f2f0286c 100644 --- a/includes/admin/class-wc-admin-setup-wizard.php +++ b/includes/admin/class-wc-admin-setup-wizard.php @@ -216,6 +216,7 @@ class WC_Admin_Setup_Wizard { wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), Constants::get_constant( 'WC_VERSION' ) ); wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util', 'jquery-tiptip', 'backbone', 'wc-backbone-modal' ), Constants::get_constant( 'WC_VERSION' ) ); wp_localize_script( 'wc-setup', 'wc_setup_params', diff --git a/includes/tracks/class-wc-tracks-event.php b/includes/tracks/class-wc-tracks-event.php index 7187db0270f..1c28f1ef1b9 100644 --- a/includes/tracks/class-wc-tracks-event.php +++ b/includes/tracks/class-wc-tracks-event.php @@ -54,7 +54,7 @@ class WC_Tracks_Event { * @return bool Always returns true. */ public function record() { - if ( wp_doing_ajax() || Constants::is_defined( 'REST_REQUEST' ) ) { + if ( wp_doing_ajax() || Constants::is_true( 'REST_REQUEST' ) ) { return WC_Tracks_Client::record_event( $this ); } From 4ae1e1f5fc6e9da4c4d0348d1590cd09b51fbbce Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Tue, 4 Feb 2020 14:02:57 -0800 Subject: [PATCH 5/5] Extracted the repetitive Constants::get_constant( 'WC_VERSION' ) calls where possible --- includes/admin/class-wc-admin-assets.php | 78 ++++++++++--------- includes/admin/class-wc-admin-dashboard.php | 7 +- includes/admin/class-wc-admin-exporters.php | 5 +- includes/admin/class-wc-admin-importers.php | 5 +- .../admin/class-wc-admin-setup-wizard.php | 9 ++- includes/class-wc-frontend-scripts.php | 52 +++++++------ .../paypal/class-wc-gateway-paypal.php | 5 +- includes/wc-template-functions.php | 6 +- .../widgets/class-wc-widget-price-filter.php | 5 +- 9 files changed, 94 insertions(+), 78 deletions(-) diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index adfd14074d9..5bdd3e12685 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -33,16 +33,17 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : public function admin_styles() { global $wp_scripts; + $version = Constants::get_constant( 'WC_VERSION' ); $screen = get_current_screen(); $screen_id = $screen ? $screen->id : ''; // Register admin styles. - wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), Constants::get_constant( 'WC_VERSION' ), 'print' ); - wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), $version ); + wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), $version ); + wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.min.css', array(), $version ); + wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), $version ); + wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), $version, 'print' ); + wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), $version ); // Add RTL support for admin styles. wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' ); @@ -91,31 +92,32 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : $screen_id = $screen ? $screen->id : ''; $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); // Register scripts. - wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), $version ); wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); - wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ), true ); - wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), $version, true ); + wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), $version ); + wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), $version ); + wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), $version ); + wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), $version ); + wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), $version ); wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' ); - wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), $version ); + wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); + wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); + wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); + wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), $version ); + wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), $version ); + wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), $version ); + wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), $version ); + wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), $version ); + wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), $version ); + wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), $version ); wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.6' ); - wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), $version ); wp_register_script( 'js-cookie', WC()->plugin_url() . '/assets/js/js-cookie/js.cookie' . $suffix . '.js', array(), '2.1.4', true ); wp_localize_script( @@ -148,7 +150,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : ) ); - wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), $version ); wp_localize_script( 'wc-orders', 'wc_orders_params', @@ -204,7 +206,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Products. if ( in_array( $screen_id, array( 'edit-product' ) ) ) { - wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), $version ); $params = array( 'strings' => array( @@ -218,8 +220,8 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Meta boxes. if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) { wp_enqueue_media(); - wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), Constants::get_constant( 'WC_VERSION' ) ); - wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), $version ); + wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), $version ); wp_enqueue_script( 'wc-admin-product-meta-boxes' ); wp_enqueue_script( 'wc-admin-variation-meta-boxes' ); @@ -261,7 +263,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) { $default_location = wc_get_customer_default_location(); - wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), $version ); wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', @@ -276,7 +278,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : ); } if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { - wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), $version ); wp_localize_script( 'wc-admin-coupon-meta-boxes', 'woocommerce_admin_meta_boxes_coupon', @@ -367,7 +369,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Term ordering - only when sorting by term_order. if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( wp_unslash( $_GET['taxonomy'] ), apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) { - wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version ); wp_enqueue_script( 'woocommerce_term_ordering' ); $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : ''; @@ -381,13 +383,13 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // Product sorting - only when sorting by menu order on the products page. if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) { - wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), $version, true ); wp_enqueue_script( 'woocommerce_product_ordering' ); } // Reports Pages. if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) { - wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), $version ); wp_enqueue_script( 'wc-reports' ); wp_enqueue_script( 'flot' ); @@ -399,7 +401,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // API settings. if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) { - wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), $version, true ); wp_enqueue_script( 'wc-api-keys' ); wp_localize_script( 'wc-api-keys', @@ -414,7 +416,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : // System status. if ( $wc_screen_id . '_page_wc-status' === $screen_id ) { - wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), $version ); wp_enqueue_script( 'wc-admin-system-status' ); wp_localize_script( 'wc-admin-system-status', @@ -426,7 +428,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : } if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) { - wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), $version, true ); wp_enqueue_script( 'wc-users' ); wp_localize_script( 'wc-users', @@ -444,7 +446,7 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) : 'marketplace-suggestions', WC()->plugin_url() . '/assets/js/admin/marketplace-suggestions' . $suffix . '.js', array( 'jquery', 'underscore', 'js-cookie' ), - Constants::get_constant( 'WC_VERSION' ), + $version, true ); wp_localize_script( diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index 5f6dd06f071..9b5ef4941b3 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -324,11 +324,12 @@ if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) : * Network orders widget. */ public function network_orders() { - $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); - wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), $version ); - wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), $version, true ); $user = wp_get_current_user(); $blogs = get_blogs_of_user( $user->ID ); diff --git a/includes/admin/class-wc-admin-exporters.php b/includes/admin/class-wc-admin-exporters.php index 212214e68f1..011d2e1429e 100644 --- a/includes/admin/class-wc-admin-exporters.php +++ b/includes/admin/class-wc-admin-exporters.php @@ -86,8 +86,9 @@ class WC_Admin_Exporters { * Enqueue scripts. */ public function admin_scripts() { - $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; - wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ) ); + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); + wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), $version ); wp_localize_script( 'wc-product-export', 'wc_product_export_params', diff --git a/includes/admin/class-wc-admin-importers.php b/includes/admin/class-wc-admin-importers.php index 4a22fa3e292..8f85ad27b60 100644 --- a/includes/admin/class-wc-admin-importers.php +++ b/includes/admin/class-wc-admin-importers.php @@ -83,8 +83,9 @@ class WC_Admin_Importers { * Register importer scripts. */ public function admin_scripts() { - $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; - wp_register_script( 'wc-product-import', WC()->plugin_url() . '/assets/js/admin/wc-product-import' . $suffix . '.js', array( 'jquery' ), Constants::get_constant( 'WC_VERSION' ), true ); + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); + wp_register_script( 'wc-product-import', WC()->plugin_url() . '/assets/js/admin/wc-product-import' . $suffix . '.js', array( 'jquery' ), $version, true ); } /** diff --git a/includes/admin/class-wc-admin-setup-wizard.php b/includes/admin/class-wc-admin-setup-wizard.php index 844f2f0286c..4e9b5fbb363 100644 --- a/includes/admin/class-wc-admin-setup-wizard.php +++ b/includes/admin/class-wc-admin-setup-wizard.php @@ -190,10 +190,11 @@ class WC_Admin_Setup_Wizard { // Whether or not there is a pending background install of Jetpack. $pending_jetpack = ! class_exists( 'Jetpack' ) && get_option( 'woocommerce_setup_background_installing_jetpack' ); $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.6' ); - wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), $version ); wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', @@ -213,10 +214,10 @@ class WC_Admin_Setup_Wizard { 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), ) ); - wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), Constants::get_constant( 'WC_VERSION' ) ); - wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), $version ); + wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), $version ); - wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util', 'jquery-tiptip', 'backbone', 'wc-backbone-modal' ), Constants::get_constant( 'WC_VERSION' ) ); + wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util', 'jquery-tiptip', 'backbone', 'wc-backbone-modal' ), $version ); wp_localize_script( 'wc-setup', 'wc_setup_params', diff --git a/includes/class-wc-frontend-scripts.php b/includes/class-wc-frontend-scripts.php index 063c8c3a106..935f0696803 100644 --- a/includes/class-wc-frontend-scripts.php +++ b/includes/class-wc-frontend-scripts.php @@ -53,27 +53,29 @@ class WC_Frontend_Scripts { * @return array */ public static function get_styles() { + $version = Constants::get_constant( 'WC_VERSION' ); + return apply_filters( 'woocommerce_enqueue_styles', array( 'woocommerce-layout' => array( 'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ), 'deps' => '', - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'media' => 'all', 'has_rtl' => true, ), 'woocommerce-smallscreen' => array( 'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ), 'deps' => 'woocommerce-layout', - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')', 'has_rtl' => true, ), 'woocommerce-general' => array( 'src' => self::get_asset_url( 'assets/css/woocommerce.css' ), 'deps' => '', - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'media' => 'all', 'has_rtl' => true, ), @@ -165,7 +167,9 @@ class WC_Frontend_Scripts { * Register all WC scripts. */ private static function register_scripts() { - $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); + $register_scripts = array( 'flexslider' => array( 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ), @@ -210,7 +214,7 @@ class WC_Frontend_Scripts { 'prettyPhoto-init' => array( // deprecated. 'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ), 'deps' => array( 'jquery', 'prettyPhoto' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'select2' => array( 'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ), @@ -225,72 +229,72 @@ class WC_Frontend_Scripts { 'wc-address-i18n' => array( 'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ), 'deps' => array( 'jquery', 'wc-country-select' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-add-payment-method' => array( 'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-cart' => array( 'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-cart-fragments' => array( 'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ), 'deps' => array( 'jquery', 'js-cookie' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-checkout' => array( 'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-country-select' => array( 'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ), 'deps' => array( 'jquery' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-credit-card-form' => array( 'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ), 'deps' => array( 'jquery', 'jquery-payment' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-add-to-cart' => array( 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ), 'deps' => array( 'jquery', 'jquery-blockui' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-add-to-cart-variation' => array( 'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ), 'deps' => array( 'jquery', 'wp-util', 'jquery-blockui' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-geolocation' => array( 'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ), 'deps' => array( 'jquery' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-lost-password' => array( 'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ), 'deps' => array( 'jquery', 'woocommerce' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-password-strength-meter' => array( 'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ), 'deps' => array( 'jquery', 'password-strength-meter' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'wc-single-product' => array( 'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ), 'deps' => array( 'jquery' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'woocommerce' => array( 'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ), 'deps' => array( 'jquery', 'jquery-blockui', 'js-cookie' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, ), 'zoom' => array( 'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ), @@ -307,29 +311,31 @@ class WC_Frontend_Scripts { * Register all WC sty;es. */ private static function register_styles() { + $version = Constants::get_constant( 'WC_VERSION' ); + $register_styles = array( 'photoswipe' => array( 'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.min.css' ), 'deps' => array(), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'has_rtl' => false, ), 'photoswipe-default-skin' => array( 'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.min.css' ), 'deps' => array( 'photoswipe' ), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'has_rtl' => false, ), 'select2' => array( 'src' => self::get_asset_url( 'assets/css/select2.css' ), 'deps' => array(), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'has_rtl' => false, ), 'woocommerce_prettyPhoto_css' => array( // deprecated. 'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ), 'deps' => array(), - 'version' => Constants::get_constant( 'WC_VERSION' ), + 'version' => $version, 'has_rtl' => true, ), ); diff --git a/includes/gateways/paypal/class-wc-gateway-paypal.php b/includes/gateways/paypal/class-wc-gateway-paypal.php index 3047f8c58d5..03d7972e7bd 100644 --- a/includes/gateways/paypal/class-wc-gateway-paypal.php +++ b/includes/gateways/paypal/class-wc-gateway-paypal.php @@ -452,9 +452,10 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { return; } - $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); - wp_enqueue_script( 'woocommerce_paypal_admin', WC()->plugin_url() . '/includes/gateways/paypal/assets/js/paypal-admin' . $suffix . '.js', array(), Constants::get_constant( 'WC_VERSION' ), true ); + wp_enqueue_script( 'woocommerce_paypal_admin', WC()->plugin_url() . '/includes/gateways/paypal/assets/js/paypal-admin' . $suffix . '.js', array(), $version, true ); } /** diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index d07e13b8b00..cb98fedbf04 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -252,12 +252,14 @@ function woocommerce_product_loop() { * @return string */ function wc_generator_tag( $gen, $type ) { + $version = Constants::get_constant( 'WC_VERSION' ); + switch ( $type ) { case 'html': - $gen .= "\n" . ''; + $gen .= "\n" . ''; break; case 'xhtml': - $gen .= "\n" . ''; + $gen .= "\n" . ''; break; } return $gen; diff --git a/includes/widgets/class-wc-widget-price-filter.php b/includes/widgets/class-wc-widget-price-filter.php index 4add29cb2a3..a27bbf1b048 100644 --- a/includes/widgets/class-wc-widget-price-filter.php +++ b/includes/widgets/class-wc-widget-price-filter.php @@ -33,9 +33,10 @@ class WC_Widget_Price_Filter extends WC_Widget { ), ); $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; + $version = Constants::get_constant( 'WC_VERSION' ); wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2', true ); - wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), Constants::get_constant( 'WC_VERSION' ), true ); - wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), Constants::get_constant( 'WC_VERSION' ), true ); + wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), $version, true ); + wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), $version, true ); wp_localize_script( 'wc-price-slider', 'woocommerce_price_slider_params',