function test_get_cron_tasks__all() { add_filter('FHEE__EEH_Activation__get_cron_tasks', array($this, 'change_cron_tasks')); $old_cron_tasks = EEH_Activation::get_cron_tasks('all'); $this->assertArrayHasKey(self::expired_cron_task_name, $old_cron_tasks); $this->assertArrayHasKey(self::current_cron_task_name, $old_cron_tasks); }
/** * Remove the currently-existing and now-removed cron tasks. * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones */ public static function remove_cron_tasks($remove_all = true) { $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; $crons = _get_cron_array(); $crons = is_array($crons) ? $crons : array(); /* reminder that $crons looks like: top-level keys are timestamps, * and their values are arrays. * The 2nd level arrays have keys with each of the cron task hooknames to run at that time * and their values are arrays. * The 3rd level level arrays are keys which are hashes of the cron task's arguments, * and their values are the UN-hashed arguments * eg * array (size=13) * 1429903276 => * array (size=1) * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => * array (size=1) * '561299d6e42c8e079285870ade0e47e6' => * array (size=2) * ... * ... */ foreach (EEH_Activation::get_cron_tasks($cron_tasks_to_remove) as $hook_name => $frequency) { foreach ($crons as $timestamp => $hooks_to_fire_at_time) { if (array_key_exists($hook_name, $hooks_to_fire_at_time)) { unset($crons[$timestamp][$hook_name]); } } } _set_cron_array($crons); }
/** * Remove the currently-existing and now-removed cron tasks. * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones */ public static function remove_cron_tasks($remove_all = true) { $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; foreach (EEH_Activation::get_cron_tasks($cron_tasks_to_remove) as $hook_name => $frequency) { while ($scheduled_time = wp_next_scheduled($hook_name)) { wp_unschedule_event($scheduled_time, $hook_name); } } }