diff --git a/bin/package-update.sh b/bin/package-update.sh index 0a3cc1b6a95..d45306be6cb 100755 --- a/bin/package-update.sh +++ b/bin/package-update.sh @@ -39,3 +39,10 @@ find ./packages/woocommerce-admin -iname '*.js' -exec sed -i.bak -e "s/, 'woocom # Cleanup backup files find ./packages -name "*.bak" -type f -delete output 2 "Done!" + +# Apply patches +output 2 "Applying patch #450 to Action Schduler" +cd packages/action-scheduler +curl -O https://patch-diff.githubusercontent.com/raw/woocommerce/action-scheduler/pull/450.patch +patch -p1 < 450.patch +output 2 "Done!" diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 9f4a1869a44..9fa28b060f0 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -49,7 +49,12 @@ class WC_Admin_Notices { add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) ); add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) ); add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) ); - add_action( 'shutdown', array( __CLASS__, 'store_notices' ) ); + // @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation. + // That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want + // to avoid. + if ( ! WC_Install::is_new_install() || ! wc_is_running_from_async_action_scheduler() ) { + add_action( 'shutdown', array( __CLASS__, 'store_notices' ) ); + } if ( current_user_can( 'manage_woocommerce' ) ) { add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) ); diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index b9c4e47c719..23d27e5bd73 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -127,6 +127,12 @@ class WC_Admin { * For setup wizard, transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters. */ public function admin_redirects() { + // Don't run this fn from Action Scheduler requests, as it would clear _wc_activation_redirect transient. + // That means OBW would never be shown. + if ( wc_is_running_from_async_action_scheduler() ) { + return; + } + // phpcs:disable WordPress.Security.NonceVerification.Recommended // Nonced plugin install redirects (whitelisted). if ( ! empty( $_GET['wc-install-plugin-redirect'] ) ) { diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index 01309f87ce2..357ae88bd3c 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -319,7 +319,7 @@ class WC_Install { * @since 3.2.0 * @return boolean */ - private static function is_new_install() { + public static function is_new_install() { $product_count = array_sum( (array) wp_count_posts( 'product' ) ); return is_null( get_option( 'woocommerce_version', null ) ) || ( 0 === $product_count && -1 === wc_get_page_id( 'shop' ) ); diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index f742e09042b..465515b7b68 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -2273,3 +2273,13 @@ function wc_load_cart() { WC()->initialize_session(); WC()->initialize_cart(); } + +/** + * Test whether the context of execution comes from async action scheduler. + * + * @since 4.0.0 + * @return bool + */ +function wc_is_running_from_async_action_scheduler() { + return isset( $_REQUEST['action'] ) && 'as_async_request_queue_runner' === $_REQUEST['action']; +}