From 7e635967f68a4ba82bb3a7b6a390ab677f5d7ada Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Mon, 3 Jan 2022 13:25:43 +0200 Subject: [PATCH] - changed WP Cron scheduled events; --- includes/class-init.php | 12 ++++++++++++ includes/core/class-cron.php | 9 ++++++++- includes/core/class-plugin-updater.php | 19 ++----------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/includes/class-init.php b/includes/class-init.php index b46961aa..a75c8c61 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -213,6 +213,8 @@ if ( ! class_exists( 'UM' ) ) { //run activation register_activation_hook( um_plugin, array( &$this, 'activation' ) ); + register_deactivation_hook( um_plugin, array( &$this, 'deactivation' ) ); + if ( is_multisite() && ! defined( 'DOING_AJAX' ) ) { add_action( 'wp_loaded', array( $this, 'maybe_network_activation' ) ); } @@ -454,6 +456,16 @@ if ( ! class_exists( 'UM' ) ) { } + /** + * Plugin Deactivation + * + * @since 2.3 + */ + function deactivation() { + $this->cron()->unschedule_events(); + } + + /** * Maybe need multisite activation process * diff --git a/includes/core/class-cron.php b/includes/core/class-cron.php index 610daa2c..93a1083f 100644 --- a/includes/core/class-cron.php +++ b/includes/core/class-cron.php @@ -116,5 +116,12 @@ if ( ! class_exists( 'um\core\Cron' ) ) { } } + + public function unschedule_events() { + wp_clear_scheduled_hook( 'um_weekly_scheduled_events' ); + wp_clear_scheduled_hook( 'um_daily_scheduled_events' ); + wp_clear_scheduled_hook( 'um_twicedaily_scheduled_events' ); + wp_clear_scheduled_hook( 'um_hourly_scheduled_events' ); + } } -} \ No newline at end of file +} diff --git a/includes/core/class-plugin-updater.php b/includes/core/class-plugin-updater.php index 30f0d60c..677f5f8b 100644 --- a/includes/core/class-plugin-updater.php +++ b/includes/core/class-plugin-updater.php @@ -19,15 +19,8 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) { * Plugin_Updater constructor. */ function __construct() { - //create cron event - if ( ! wp_next_scheduled( 'um_check_extensions_licenses' ) ) { - wp_schedule_event( time() + ( 24*60*60 ), 'daily', 'um_check_extensions_licenses' ); - } - - register_deactivation_hook( um_plugin, array( &$this, 'um_plugin_updater_deactivation_hook' ) ); - //cron request to UM()->store_url; - add_action( 'um_check_extensions_licenses', array( &$this, 'um_checklicenses' ) ); + add_action( 'um_daily_scheduled_events', array( &$this, 'um_checklicenses' ) ); // clean update plugin cache add_action( 'upgrader_process_complete', array( &$this, 'clean_update_plugins_cache' ), 20, 2 ); @@ -248,14 +241,6 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) { } - /** - * Remove CRON events on deactivation hook - */ - function um_plugin_updater_deactivation_hook() { - wp_clear_scheduled_hook( 'um_check_extensions_licenses' ); - } - - /** * Check license function */ @@ -665,4 +650,4 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) { } } -} \ No newline at end of file +}