| 1 |
<?php |
| 2 |
|
| 3 |
namespace SlimStat\Components; |
| 4 |
|
| 5 |
class Event |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Schedule a cron event |
| 9 |
* |
| 10 |
* @param string $hook |
| 11 |
* @param int $timestamp |
| 12 |
* @param string $recurrence |
| 13 |
* @param callable $callback |
| 14 |
*/ |
| 15 |
public static function schedule($hook, $timestamp, $recurrence, $callback) |
| 16 |
{ |
| 17 |
if (!wp_next_scheduled($hook)) { |
| 18 |
wp_schedule_event($timestamp, $recurrence, $hook); |
| 19 |
} |
| 20 |
|
| 21 |
add_action($hook, $callback); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Unschedule a cron event |
| 26 |
* |
| 27 |
* @param string $hook |
| 28 |
*/ |
| 29 |
public static function unschedule($hook) |
| 30 |
{ |
| 31 |
$timestamp = wp_next_scheduled($hook); |
| 32 |
if ($timestamp) { |
| 33 |
wp_unschedule_event($timestamp, $hook); |
| 34 |
} |
| 35 |
} |
| 36 |
} |