Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages

This commit is contained in:
Christopher Allford 2020-01-28 21:21:29 -08:00
parent 9c8a6d78d9
commit 6ad091a9b7
46 changed files with 177 additions and 82 deletions

View File

@ -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
);

View File

@ -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' ) );

View File

@ -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' ) ),

View File

@ -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 );

View File

@ -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',

View File

@ -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 <strong>products</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) );
register_importer( 'woocommerce_tax_rate_csv', __( 'WooCommerce tax rates (CSV)', 'woocommerce' ), __( 'Import <strong>tax rates</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'tax_rates_importer' ) );

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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' );

View File

@ -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' );

View File

@ -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();

View File

@ -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;
}

View File

@ -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 ) ) {

View File

@ -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();

View File

@ -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 &rarr;', 'woocommerce' );
?>
<div id="message" class="updated woocommerce-message">

View File

@ -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 &rarr;', 'woocommerce' );
?>
<div id="message" class="updated woocommerce-message wc-connect">

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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;

View File

@ -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' );
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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';

View File

@ -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.';
}

View File

@ -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';
}

View File

@ -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 ) ) {

View File

@ -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 );
}

View File

@ -1,4 +1,7 @@
<?php
use Automattic\Jetpack\Constants;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -315,7 +318,7 @@ if ( ! class_exists( 'WC_Eval_Math', false ) ) {
*/
private static function trigger( $msg ) {
self::$last_error = $msg;
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
if ( Constants::is_true( 'WP_DEBUG' ) ) {
echo "\nError found in:";
self::debugPrintCallingFunction();
trigger_error( $msg, E_USER_WARNING );

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Log Handlers
*/
use Automattic\Jetpack\Constants;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@ -165,7 +167,7 @@ class WC_Log_Handler_DB extends WC_Log_Handler {
*
* @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters
*/
if ( defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) {
if ( Constants::is_defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) {
$debug_backtrace_arg = DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:ignore PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound
} else {
$debug_backtrace_arg = false;

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Log Handlers
*/
use Automattic\Jetpack\Constants;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@ -146,7 +148,7 @@ class WC_Log_Handler_File extends WC_Log_Handler {
$temphandle = @fopen( $file, 'w+' ); // @codingStandardsIgnoreLine.
@fclose( $temphandle ); // @codingStandardsIgnoreLine.
if ( defined( 'FS_CHMOD_FILE' ) ) {
if ( Constants::is_defined( 'FS_CHMOD_FILE' ) ) {
@chmod( $file, FS_CHMOD_FILE ); // @codingStandardsIgnoreLine.
}
}

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tracks
*/
use Automattic\Jetpack\Constants;
defined( 'ABSPATH' ) || exit;
/**
@ -44,7 +46,7 @@ class WC_Tracks_Client {
*/
public static function maybe_set_identity_cookie() {
// Do not set on AJAX requests.
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
if ( Constants::is_true( 'DOING_AJAX' ) ) {
return;
}
@ -69,10 +71,7 @@ class WC_Tracks_Client {
}
// Don't set cookie on API requests.
if (
! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) &&
! ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
) {
if ( ! Constants::is_true( 'REST_REQUEST' ) && ! Constants::is_true( 'XMLRPC_REQUEST' ) ) {
wc_setcookie( 'tk_ai', $anon_id );
}
}
@ -144,8 +143,8 @@ class WC_Tracks_Client {
public static function get_identity( $user_id ) {
$jetpack_lib = '/tracks/client.php';
if ( class_exists( 'Jetpack' ) && defined( 'JETPACK__VERSION' ) ) {
if ( version_compare( JETPACK__VERSION, '7.5', '<' ) ) {
if ( class_exists( 'Jetpack' ) && Constants::is_defined( 'JETPACK__VERSION' ) ) {
if ( version_compare( Constants::get_constant( 'JETPACK__VERSION' ), '7.5', '<' ) ) {
if ( file_exists( jetpack_require_lib_dir() . $jetpack_lib ) ) {
include_once jetpack_require_lib_dir() . $jetpack_lib;
if ( function_exists( 'jetpack_tracks_get_identity' ) ) {

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tracks
*/
use Automattic\Jetpack\Constants;
defined( 'ABSPATH' ) || exit;
/**
@ -52,10 +54,7 @@ class WC_Tracks_Event {
* @return bool Always returns true.
*/
public function record() {
if (
wp_doing_ajax() ||
( defined( 'REST_REQUEST' ) && REST_REQUEST )
) {
if ( wp_doing_ajax() || Constants::is_defined( 'REST_REQUEST' ) ) {
return WC_Tracks_Client::record_event( $this );
}

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tracks
*/
use Automattic\Jetpack\Constants;
defined( 'ABSPATH' ) || exit;
/**
@ -71,7 +73,7 @@ class WC_Products_Tracking {
// Only track category creation from the edit product screen or the
// category management screen (which both occur via AJAX).
if (
! defined( 'DOING_AJAX' ) ||
! Constants::is_defined( 'DOING_AJAX' ) ||
empty( $_POST['action'] ) ||
(
// Product Categories screen.

View File

@ -8,6 +8,8 @@
* @version 2.5.0
*/
use Automattic\Jetpack\Constants;
defined( 'ABSPATH' ) || exit;
/**
@ -288,7 +290,7 @@ function wc_cart_totals_coupon_html( $coupon ) {
}
$discount_amount_html = apply_filters( 'woocommerce_coupon_discount_amount_html', $discount_amount_html, $coupon );
$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', rawurlencode( $coupon->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' ) . '</a>';
$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', rawurlencode( $coupon->get_code() ), Constants::is_defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';
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
}

View File

@ -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' );
}
}

View File

@ -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;
}

View File

@ -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';

View File

@ -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' );

View File

@ -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' );
}
/**

View File

@ -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 );

View File

@ -1,5 +1,7 @@
<?php
use Automattic\Jetpack\Constants;
/**
* Class WC_Helper_Fee.
*
@ -13,7 +15,7 @@ class WC_Helper_Fee {
* @since 2.3
*/
public static function create_simple_fee() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
if ( is_admin() && ! Constants::is_defined( 'DOING_AJAX' ) ) {
return;
}
@ -26,7 +28,7 @@ class WC_Helper_Fee {
* @since 3.2
*/
public static function create_taxed_fee() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
if ( is_admin() && ! Constants::is_defined( 'DOING_AJAX' ) ) {
return;
}
@ -39,7 +41,7 @@ class WC_Helper_Fee {
* @since 3.2
*/
public static function create_negative_fee() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
if ( is_admin() && ! Constants::is_defined( 'DOING_AJAX' ) ) {
return;
}
@ -53,7 +55,7 @@ class WC_Helper_Fee {
* @since 3.2
*/
public static function create_negative_taxed_fee() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
if ( is_admin() && ! Constants::is_defined( 'DOING_AJAX' ) ) {
return;
}

View File

@ -7,6 +7,8 @@
* @since 1.0.0
*/
use Automattic\Jetpack\Constants;
/**
* Parent test case for tests involving HTTP requests.
*
@ -355,11 +357,11 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
return $value;
}
if ( ! defined( 'WP_HTTP_TC_' . $var ) ) {
if ( ! Constants::is_defined( 'WP_HTTP_TC_' . $var ) ) {
return $default;
}
return constant( 'WP_HTTP_TC_' . $var );
return Constants::get_constant( 'WP_HTTP_TC_' . $var );
}
/**
@ -434,7 +436,7 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
}
}
if ( ! defined( 'WP_HTTP_TC_NO_BACKPAT' ) ) {
if ( ! Constants::is_defined( 'WP_HTTP_TC_NO_BACKPAT' ) ) {
abstract class WP_HTTP_UnitTestCase extends WP_HTTP_TestCase {}
}

View File

@ -6,6 +6,8 @@
* @since 2.2
*/
use Automattic\Jetpack\Constants;
/**
* Core function unit tests.
*/
@ -494,11 +496,11 @@ class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
* @since 3.2.0
*/
public function test_wc_maybe_define_constant() {
$this->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 );

View File

@ -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.