Polyfill wc_is_running_from_async_action_scheduler(). (https://github.com/woocommerce/woocommerce-admin/pull/5379)

Supports WC versions < 4.0.0.
This commit is contained in:
Jeff Stieler 2020-10-14 09:46:09 -04:00 committed by GitHub
parent 5d9664c723
commit 7c7a13077b
1 changed files with 20 additions and 4 deletions

View File

@ -119,6 +119,22 @@ class Onboarding {
add_action( 'current_screen', array( $this, 'redirect_old_onboarding' ) ); add_action( 'current_screen', array( $this, 'redirect_old_onboarding' ) );
} }
/**
* Test whether the context of execution comes from async action scheduler.
* Note: this is a polyfill for wc_is_running_from_async_action_scheduler()
* which was introduced in WC 4.0.
*
* @return bool
*/
public static function is_running_from_async_action_scheduler() {
if ( function_exists( '\wc_is_running_from_async_action_scheduler' ) ) {
return \wc_is_running_from_async_action_scheduler();
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
return isset( $_REQUEST['action'] ) && 'as_async_request_queue_runner' === $_REQUEST['action'];
}
/** /**
* Handle redirects to setup/welcome page after install and updates. * Handle redirects to setup/welcome page after install and updates.
* *
@ -127,7 +143,7 @@ class Onboarding {
public function admin_redirects() { public function admin_redirects() {
// Don't run this fn from Action Scheduler requests, as it would clear _wc_activation_redirect transient. // Don't run this fn from Action Scheduler requests, as it would clear _wc_activation_redirect transient.
// That means OBW would never be shown. // That means OBW would never be shown.
if ( wc_is_running_from_async_action_scheduler() ) { if ( self::is_running_from_async_action_scheduler() ) {
return; return;
} }