Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| wp_get_scheduled_events | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Functions. |
| 4 | * |
| 5 | * @package automattic/scheduled-updates |
| 6 | */ |
| 7 | |
| 8 | if ( ! function_exists( 'wp_get_scheduled_events' ) ) { |
| 9 | /** |
| 10 | * Retrieves scheduled events. |
| 11 | * |
| 12 | * Retrieves all the events that have been scheduled for the hook provided. |
| 13 | * |
| 14 | * This should really be in Core, and until it is, we'll define it here in a forward-compatible way. |
| 15 | * |
| 16 | * @param string $hook Action hook of the event. |
| 17 | * @return object[]|array { |
| 18 | * Array of event objects. Empty array if no events exist for the hook. |
| 19 | * |
| 20 | * @type string $hook Action hook to execute when the event is run. |
| 21 | * @type int $timestamp Unix timestamp (UTC) for when to next run the event. |
| 22 | * @type string|false $schedule How often the event should subsequently recur. |
| 23 | * @type array $args Array containing each separate argument to pass to the hook's callback function. |
| 24 | * @type int $interval Optional. The interval time in seconds for the schedule. Only present for recurring events. |
| 25 | * } |
| 26 | */ |
| 27 | function wp_get_scheduled_events( $hook ) { |
| 28 | /** |
| 29 | * Filter to override retrieving scheduled events. |
| 30 | * |
| 31 | * Returning a non-null value will short-circuit the normal process, |
| 32 | * returning the filtered value instead. |
| 33 | * |
| 34 | * Return false if the event does not exist, otherwise an event object |
| 35 | * should be returned. |
| 36 | * |
| 37 | * @param null|false|object $pre Value to return instead. Default null to continue retrieving the event. |
| 38 | * @param string $hook Action hook of the event. |
| 39 | */ |
| 40 | $pre = apply_filters( 'pre_get_scheduled_events', null, $hook ); |
| 41 | |
| 42 | if ( null !== $pre ) { |
| 43 | return $pre; |
| 44 | } |
| 45 | |
| 46 | $crons = _get_cron_array(); |
| 47 | if ( empty( $crons ) ) { |
| 48 | return array(); |
| 49 | } |
| 50 | |
| 51 | $events = array(); |
| 52 | foreach ( $crons as $timestamp => $cron ) { |
| 53 | if ( isset( $cron[ $hook ] ) ) { |
| 54 | $key = key( $cron[ $hook ] ); |
| 55 | $scheduled_event = array_pop( $cron[ $hook ] ); |
| 56 | '@phan-var mixed $scheduled_event'; // @todo Remove once WordPress 7.1 is the minimum version. |
| 57 | |
| 58 | $event = (object) array( |
| 59 | 'hook' => $hook, |
| 60 | 'timestamp' => $timestamp, |
| 61 | 'schedule' => $scheduled_event['schedule'], |
| 62 | 'args' => $scheduled_event['args'], |
| 63 | ); |
| 64 | if ( isset( $scheduled_event['interval'] ) ) { |
| 65 | $event->interval = $scheduled_event['interval']; |
| 66 | } |
| 67 | |
| 68 | $events[ $key ] = $event; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return $events; |
| 73 | } |
| 74 | } |