From 254e378346d108b9b4775ae4ab3b40e9b72362ef Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 14 May 2019 19:19:24 +0100 Subject: [PATCH] Moved actionsheduler hook to main file --- .../includes/class-wc-admin-api-init.php | 3 --- .../includes/core-functions.php | 21 ----------------- plugins/woocommerce-admin/tests/bootstrap.php | 5 +--- .../woocommerce-admin/woocommerce-admin.php | 23 +++++++++++++++++++ 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php b/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php index 941dbc92369..8e09b3c98d7 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php @@ -32,9 +32,6 @@ class WC_Admin_Api_Init { * Init classes. */ public function init_classes() { - // Core functions. - require_once WC_ADMIN_ABSPATH . 'includes/core-functions.php'; - // Interfaces. require_once WC_ADMIN_ABSPATH . 'includes/interfaces/class-wc-admin-reports-data-store-interface.php'; require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-query.php'; diff --git a/plugins/woocommerce-admin/includes/core-functions.php b/plugins/woocommerce-admin/includes/core-functions.php index 4fd0ae76fde..c794bce7880 100644 --- a/plugins/woocommerce-admin/includes/core-functions.php +++ b/plugins/woocommerce-admin/includes/core-functions.php @@ -42,24 +42,3 @@ function wc_admin_url( $path, $query = array() ) { return admin_url( 'admin.php?page=wc-admin#' . $path, dirname( __FILE__ ) ); } - -/** - * Filter in our ActionScheduler Store class. - * - * @param string $store_class ActionScheduler Store class name. - * @return string ActionScheduler Store class name. - */ -function wc_admin_set_actionscheduler_store_class( $store_class ) { - // Don't override any other overrides. - if ( 'ActionScheduler_wpPostStore' !== $store_class ) { - return $store_class; - } - - // Include our store class here instead of wc_admin_plugins_loaded() - // because ActionScheduler is hooked into `plugins_loaded` at a - // much higher priority. - require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-actionscheduler-wppoststore.php'; - - return 'WC_Admin_ActionScheduler_WPPostStore'; -} -add_filter( 'action_scheduler_store_class', 'wc_admin_set_actionscheduler_store_class' ); diff --git a/plugins/woocommerce-admin/tests/bootstrap.php b/plugins/woocommerce-admin/tests/bootstrap.php index 8dff0fbdec1..2b1a336126b 100755 --- a/plugins/woocommerce-admin/tests/bootstrap.php +++ b/plugins/woocommerce-admin/tests/bootstrap.php @@ -40,10 +40,7 @@ function wc_admin_install() { require_once dirname( dirname( __FILE__ ) ) . '/includes/class-wc-admin-install.php'; WC_Admin_Install::create_tables(); - - if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) { - wp_schedule_event( time(), 'daily', 'wc_admin_daily' ); - } + WC_Admin_Install::create_events(); // Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374. $GLOBALS['wp_roles'] = null; // WPCS: override ok. diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 83dba6dfdc3..aa8204c51a5 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -57,6 +57,7 @@ class WC_Admin_Feature_Plugin { $this->define_constants(); register_activation_hook( WC_ADMIN_PLUGIN_FILE, array( $this, 'on_activation' ) ); add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) ); + add_filter( 'action_scheduler_store_class', array( $this, 'replace_actionscheduler_store_class' ) ); } /** @@ -117,6 +118,8 @@ class WC_Admin_Feature_Plugin { * Include WC Admin classes. */ public function includes() { + require_once WC_ADMIN_ABSPATH . 'includes/core-functions.php'; + // Initialize the WC API extensions. require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-sync.php'; require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-install.php'; @@ -135,6 +138,26 @@ class WC_Admin_Feature_Plugin { require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-welcome-message.php'; } + /** + * Filter in our ActionScheduler Store class. + * + * @param string $store_class ActionScheduler Store class name. + * @return string ActionScheduler Store class name. + */ + public function replace_actionscheduler_store_class( $store_class ) { + // Don't override any other overrides. + if ( 'ActionScheduler_wpPostStore' !== $store_class ) { + return $store_class; + } + + // Include our store class here instead of wc_admin_plugins_loaded() + // because ActionScheduler is hooked into `plugins_loaded` at a + // much higher priority. + require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-actionscheduler-wppoststore.php'; + + return 'WC_Admin_ActionScheduler_WPPostStore'; + } + /** * Removes core hooks in favor of our local feature plugin handlers. *