diff --git a/plugins/woocommerce/includes/admin/class-wc-admin.php b/plugins/woocommerce/includes/admin/class-wc-admin.php index 215f061789b8..3785f3c43f83 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin.php @@ -157,7 +157,7 @@ public function admin_redirects() { public function prevent_admin_access() { $prevent_access = false; - if ( apply_filters( 'woocommerce_disable_admin_bar', true ) && ! is_ajax() && isset( $_SERVER['SCRIPT_FILENAME'] ) && basename( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) !== 'admin-post.php' ) { + if ( apply_filters( 'woocommerce_disable_admin_bar', true ) && ! wp_doing_ajax() && isset( $_SERVER['SCRIPT_FILENAME'] ) && basename( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) !== 'admin-post.php' ) { $has_cap = false; $access_caps = array( 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' ); diff --git a/plugins/woocommerce/includes/class-wc-cache-helper.php b/plugins/woocommerce/includes/class-wc-cache-helper.php index 4a9c0604eab3..32500527c5ec 100644 --- a/plugins/woocommerce/includes/class-wc-cache-helper.php +++ b/plugins/woocommerce/includes/class-wc-cache-helper.php @@ -186,7 +186,7 @@ public static function prevent_caching() { * This prevents caching of the wrong data for this request. */ public static function geolocation_ajax_redirect() { - if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! is_ajax() && empty( $_POST ) ) { // WPCS: CSRF ok, input var ok. + if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! wp_doing_ajax() && empty( $_POST ) ) { // WPCS: CSRF ok, input var ok. $location_hash = self::geolocation_ajax_get_location_hash(); $current_hash = isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : ''; // WPCS: sanitization ok, input var ok, CSRF ok. if ( empty( $current_hash ) || $current_hash !== $location_hash ) { diff --git a/plugins/woocommerce/includes/class-wc-checkout.php b/plugins/woocommerce/includes/class-wc-checkout.php index 3133be81505a..2c28a6e4af29 100644 --- a/plugins/woocommerce/includes/class-wc-checkout.php +++ b/plugins/woocommerce/includes/class-wc-checkout.php @@ -985,7 +985,7 @@ protected function process_order_payment( $order_id, $payment_method ) { $result = apply_filters( 'woocommerce_payment_successful_result', $result, $order_id ); - if ( ! is_ajax() ) { + if ( ! wp_doing_ajax() ) { // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect wp_redirect( $result['redirect'] ); exit; @@ -1006,7 +1006,7 @@ protected function process_order_without_payment( $order_id ) { $order->payment_complete(); wc_empty_cart(); - if ( ! is_ajax() ) { + if ( ! wp_doing_ajax() ) { wp_safe_redirect( apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', $order->get_checkout_order_received_url(), $order ) ); @@ -1106,7 +1106,7 @@ protected function process_customer( $data ) { * If checkout failed during an AJAX call, send failure response. */ protected function send_ajax_failure_response() { - if ( is_ajax() ) { + if ( wp_doing_ajax() ) { // Only print notices if not reloading the checkout, otherwise they're lost in the page reload. if ( ! isset( WC()->session->reload_checkout ) ) { $messages = wc_print_notices( true ); diff --git a/plugins/woocommerce/includes/class-wc-https.php b/plugins/woocommerce/includes/class-wc-https.php index 84e3aeddd7bf..045d594dc2b5 100644 --- a/plugins/woocommerce/includes/class-wc-https.php +++ b/plugins/woocommerce/includes/class-wc-https.php @@ -106,7 +106,7 @@ public static function unforce_https_template_redirect() { return; } - if ( ! wc_site_is_https() && is_ssl() && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! is_ajax() && ! is_account_page() && apply_filters( 'woocommerce_unforce_ssl_checkout', true ) ) { + if ( ! wc_site_is_https() && is_ssl() && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! wp_doing_ajax() && ! is_account_page() && apply_filters( 'woocommerce_unforce_ssl_checkout', true ) ) { if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { wp_safe_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ) ); diff --git a/plugins/woocommerce/includes/class-wc-order-item-meta.php b/plugins/woocommerce/includes/class-wc-order-item-meta.php index 693be2323286..badc1ba7d01b 100644 --- a/plugins/woocommerce/includes/class-wc-order-item-meta.php +++ b/plugins/woocommerce/includes/class-wc-order-item-meta.php @@ -168,7 +168,7 @@ public function get_formatted( $hideprefix = '_' ) { * @return array */ public function get_formatted_legacy( $hideprefix = '_' ) { - if ( ! is_ajax() ) { + if ( ! wp_doing_ajax() ) { wc_deprecated_argument( 'WC_Order_Item_Meta::get_formatted', '2.4', 'Item Meta Data is being called with legacy arguments' ); } diff --git a/plugins/woocommerce/includes/wc-conditional-functions.php b/plugins/woocommerce/includes/wc-conditional-functions.php index 641066cb6575..13c8eca298b2 100644 --- a/plugins/woocommerce/includes/wc-conditional-functions.php +++ b/plugins/woocommerce/includes/wc-conditional-functions.php @@ -256,18 +256,6 @@ function is_lost_password_page() { } } -if ( ! function_exists( 'is_ajax' ) ) { - - /** - * Is_ajax - Returns true when the page is loaded via ajax. - * - * @return bool - */ - function is_ajax() { - return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : Constants::is_defined( 'DOING_AJAX' ); - } -} - if ( ! function_exists( 'is_store_notice_showing' ) ) { /** diff --git a/plugins/woocommerce/includes/wc-deprecated-functions.php b/plugins/woocommerce/includes/wc-deprecated-functions.php index ea5f57f7191c..9810d6a6c7e6 100644 --- a/plugins/woocommerce/includes/wc-deprecated-functions.php +++ b/plugins/woocommerce/includes/wc-deprecated-functions.php @@ -45,7 +45,7 @@ function wc_do_deprecated_action( $tag, $args, $version, $replacement = null, $m */ function wc_deprecated_function( $function, $version, $replacement = null ) { // @codingStandardsIgnoreStart - if ( is_ajax() || WC()->is_rest_api_request() ) { + if ( wp_doing_ajax() || WC()->is_rest_api_request() ) { do_action( 'deprecated_function_run', $function, $replacement, $version ); $log_string = "The {$function} function is deprecated since version {$version}."; $log_string .= $replacement ? " Replace with {$replacement}." : ''; @@ -67,7 +67,7 @@ function wc_deprecated_function( $function, $version, $replacement = null ) { */ function wc_deprecated_hook( $hook, $version, $replacement = null, $message = null ) { // @codingStandardsIgnoreStart - if ( is_ajax() || WC()->is_rest_api_request() ) { + if ( wp_doing_ajax() || WC()->is_rest_api_request() ) { do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message ); $message = empty( $message ) ? '' : ' ' . $message; @@ -111,7 +111,7 @@ function wc_doing_it_wrong( $function, $message, $version ) { // @codingStandardsIgnoreStart $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); - if ( is_ajax() || WC()->is_rest_api_request() ) { + if ( wp_doing_ajax() || WC()->is_rest_api_request() ) { do_action( 'doing_it_wrong_run', $function, $message, $version ); error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); } else { @@ -129,7 +129,7 @@ function wc_doing_it_wrong( $function, $message, $version ) { * @param string $replacement */ function wc_deprecated_argument( $argument, $version, $message = null ) { - if ( is_ajax() || WC()->is_rest_api_request() ) { + if ( wp_doing_ajax() || WC()->is_rest_api_request() ) { do_action( 'deprecated_argument_run', $argument, $message, $version ); error_log( "The {$argument} argument is deprecated since version {$version}. {$message}" ); } else { @@ -1123,3 +1123,17 @@ function get_woocommerce_term_meta( $term_id, $key, $single = true ) { wc_deprecated_function( 'get_woocommerce_term_meta', '3.6', 'get_term_meta' ); return function_exists( 'get_term_meta' ) ? get_term_meta( $term_id, $key, $single ) : get_metadata( 'woocommerce_term', $term_id, $key, $single ); } + +if ( ! function_exists( 'is_ajax' ) ) { + + /** + * Is_ajax - Returns true when the page is loaded via ajax. + * + * @deprecated 6.0.0 + * @return bool + */ + function is_ajax() { + wc_deprecated_function( 'is_ajax', '6.0', 'wp_doing_ajax' ); + return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : Constants::is_defined( 'DOING_AJAX' ); + } +} diff --git a/plugins/woocommerce/includes/wc-term-functions.php b/plugins/woocommerce/includes/wc-term-functions.php index 163a1e476c84..0a2fd5cef679 100644 --- a/plugins/woocommerce/includes/wc-term-functions.php +++ b/plugins/woocommerce/includes/wc-term-functions.php @@ -520,7 +520,7 @@ function wc_recount_after_stock_change( $product_id ) { * @return array */ function wc_change_term_counts( $terms, $taxonomies ) { - if ( is_admin() || is_ajax() ) { + if ( is_admin() || wp_doing_ajax() ) { return $terms; } diff --git a/plugins/woocommerce/templates/checkout/payment.php b/plugins/woocommerce/templates/checkout/payment.php index a5467a71c720..7da3423e324c 100644 --- a/plugins/woocommerce/templates/checkout/payment.php +++ b/plugins/woocommerce/templates/checkout/payment.php @@ -17,7 +17,7 @@ defined( 'ABSPATH' ) || exit; -if ( ! is_ajax() ) { +if ( ! wp_doing_ajax() ) { do_action( 'woocommerce_review_order_before_payment' ); } ?> @@ -56,6 +56,6 @@