Merge pull request #21090 from woocommerce/fix/20937-v0.1
Added test if request is a REST API request so that cart is not loaded.
This commit is contained in:
commit
15bcef85e9
|
@ -56,13 +56,10 @@ class WC_REST_Authentication {
|
|||
|
||||
$rest_prefix = trailingslashit( rest_get_url_prefix() );
|
||||
|
||||
// Check if our endpoint.
|
||||
$woocommerce = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc/' ) ); // @codingStandardsIgnoreLine
|
||||
|
||||
// Allow third party plugins use our authentication methods.
|
||||
$third_party = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc-' ) ); // @codingStandardsIgnoreLine
|
||||
|
||||
return apply_filters( 'woocommerce_rest_is_request_to_rest_api', $woocommerce || $third_party );
|
||||
return apply_filters( 'woocommerce_rest_is_request_to_rest_api', WC()->is_rest_api_request() || $third_party );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -240,6 +240,29 @@ final class WooCommerce {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the request is a non-legacy REST API request.
|
||||
*
|
||||
* Legacy REST requests should still run some extra code for backwards compatibility.
|
||||
*
|
||||
* @todo: replace this function once core WP function is available: https://core.trac.wordpress.org/ticket/42061.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_rest_api_request() {
|
||||
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// REST API prefix.
|
||||
$rest_prefix = trailingslashit( rest_get_url_prefix() );
|
||||
|
||||
// Check if this is a WC endpoint.
|
||||
$is_woocommerce_endpoint = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc/' ) ); // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
|
||||
return apply_filters( 'woocommerce_is_rest_api_request', $is_woocommerce_endpoint );
|
||||
}
|
||||
|
||||
/**
|
||||
* What type of request is this?
|
||||
*
|
||||
|
@ -255,7 +278,7 @@ final class WooCommerce {
|
|||
case 'cron':
|
||||
return defined( 'DOING_CRON' );
|
||||
case 'frontend':
|
||||
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! defined( 'REST_REQUEST' );
|
||||
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! $this->is_rest_api_request();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue