Unscheduler.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Cron; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Support\Collection; |
| 6 | use IAWPSCOPED\Illuminate\Support\Str; |
| 7 | /** @internal */ |
| 8 | class Unscheduler |
| 9 | { |
| 10 | /** |
| 11 | * Unschedule all cron events for Independent Analytics |
| 12 | * |
| 13 | * @return void |
| 14 | */ |
| 15 | public static function unschedule_all_events() |
| 16 | { |
| 17 | $prefix = 'iawp_'; |
| 18 | $raw_cron_data = \get_option('cron'); |
| 19 | if (!\is_array($raw_cron_data)) { |
| 20 | return; |
| 21 | } |
| 22 | $event_names = Collection::make(); |
| 23 | foreach ($raw_cron_data as $timestamp => $events) { |
| 24 | if (!\is_int($timestamp) || !\is_array($events)) { |
| 25 | continue; |
| 26 | } |
| 27 | foreach ($events as $name => $details) { |
| 28 | if (!Str::startsWith($name, $prefix)) { |
| 29 | continue; |
| 30 | } |
| 31 | $event_names->push($name); |
| 32 | } |
| 33 | } |
| 34 | $event_names->unique()->values()->each(function ($event_name) { |
| 35 | \wp_unschedule_hook($event_name); |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 |