From 3b609cf19f9aa9d7f2c24bdd1cc430da49a97be2 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 16 Jan 2020 11:46:05 -0700 Subject: [PATCH] Avoid redundant/unnecessary cleanup. (https://github.com/woocommerce/woocommerce-admin/pull/3580) The feature plugin doesn't need to clean up when the core package exists. --- plugins/woocommerce-admin/src/FeaturePlugin.php | 6 ++++++ plugins/woocommerce-admin/src/Install.php | 1 + plugins/woocommerce-admin/src/Package.php | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/plugins/woocommerce-admin/src/FeaturePlugin.php b/plugins/woocommerce-admin/src/FeaturePlugin.php index df14f018859..61649331770 100644 --- a/plugins/woocommerce-admin/src/FeaturePlugin.php +++ b/plugins/woocommerce-admin/src/FeaturePlugin.php @@ -96,6 +96,12 @@ class FeaturePlugin { * @return void */ public function on_deactivation() { + // Don't clean up if the WooCommerce Admin package is in core. + // NOTE: Any future divergence from the core package will need to be accounted for here. + if ( defined( 'WC_ADMIN_PACKAGE_EXISTS' ) && WC_ADMIN_PACKAGE_EXISTS ) { + return; + } + // Check if we are deactivating due to dependencies not being satisfied. // If WooCommerce is disabled we can't include files that depend upon it. if ( ! $this->has_satisfied_dependencies() ) { diff --git a/plugins/woocommerce-admin/src/Install.php b/plugins/woocommerce-admin/src/Install.php index a65b0ef4347..f6290c21627 100644 --- a/plugins/woocommerce-admin/src/Install.php +++ b/plugins/woocommerce-admin/src/Install.php @@ -379,6 +379,7 @@ class Install { if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) { wp_schedule_event( time(), 'daily', 'wc_admin_daily' ); } + // @todo This is potentially redundant when the core package exists. wp_schedule_single_event( time() + 10, 'generate_category_lookup_table' ); } diff --git a/plugins/woocommerce-admin/src/Package.php b/plugins/woocommerce-admin/src/Package.php index 46af23ec29a..dabf09a0635 100644 --- a/plugins/woocommerce-admin/src/Package.php +++ b/plugins/woocommerce-admin/src/Package.php @@ -32,6 +32,11 @@ class Package { return; } + // Indicate to the feature plugin that the core package exists. + if ( ! defined( 'WC_ADMIN_PACKAGE_EXISTS' ) ) { + define( 'WC_ADMIN_PACKAGE_EXISTS', true ); + } + // Avoid double initialization when the feature plugin is in use. if ( defined( 'WC_ADMIN_VERSION_NUMBER' ) ) { return;