Merge pull request #31113 from kkmuffme/use-native-wp_doing_ajax
Use native wp_doing_ajax() instead of custom is_ajax()
This commit is contained in:
commit
acbe200c79
|
@ -157,7 +157,7 @@ class WC_Admin {
|
|||
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' );
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ class WC_Cache_Helper {
|
|||
* 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 ) {
|
||||
|
|
|
@ -985,7 +985,7 @@ class WC_Checkout {
|
|||
|
||||
$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 @@ class WC_Checkout {
|
|||
$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 @@ class WC_Checkout {
|
|||
* 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 );
|
||||
|
|
|
@ -106,7 +106,7 @@ class WC_HTTPS {
|
|||
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'] ) );
|
||||
|
|
|
@ -168,7 +168,7 @@ class WC_Order_Item_Meta {
|
|||
* @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' );
|
||||
}
|
||||
|
||||
|
|
|
@ -256,18 +256,6 @@ if ( ! function_exists( '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' ) ) {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.1.0
|
||||
* @return bool
|
||||
*/
|
||||
function is_ajax() {
|
||||
wc_deprecated_function( 'is_ajax', '6.1.0', 'wp_doing_ajax' );
|
||||
return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : Constants::is_defined( 'DOING_AJAX' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,7 +520,7 @@ add_action( 'woocommerce_product_set_stock_status', 'wc_recount_after_stock_chan
|
|||
* @return array
|
||||
*/
|
||||
function wc_change_term_counts( $terms, $taxonomies ) {
|
||||
if ( is_admin() || is_ajax() ) {
|
||||
if ( is_admin() || wp_doing_ajax() ) {
|
||||
return $terms;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ if ( ! is_ajax() ) {
|
|||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if ( ! is_ajax() ) {
|
||||
if ( ! wp_doing_ajax() ) {
|
||||
do_action( 'woocommerce_review_order_after_payment' );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue