PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.0
Defender Security – Malware Scanner, Login Security & Firewall v5.7.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / scheduler / class-scheduler.php

class-scheduler.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.0, at src/component/scheduler/class-scheduler.php

63 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles the scheduling of cron jobs within the WordPress environment.
4 *
5 * @package WP_Defender\Component\Scheduler
6 */
7
8 namespace WP_Defender\Component\Scheduler;
9
10 /**
11 * Service layer to handle cron schedule.
12 */
13 class Scheduler {
14
15 /**
16 * Filter array cron schedules with matched cron keys.
17 *
18 * @param array $cron_keys Array of cron keys to fetch respective cron schedules.
19 *
20 * @return array Array of cron schedules.
21 */
22 public function filter_cron_schedules( array $cron_keys ): array {
23 return array_filter(
24 wp_get_schedules(),
25 function ( $v, $k ) use ( $cron_keys ): bool {
26 return in_array(
27 $k,
28 $cron_keys,
29 true
30 );
31 },
32 ARRAY_FILTER_USE_BOTH
33 );
34 }
35
36 /**
37 * Override existing schedule with new schedule.
38 *
39 * @param string $hook Schedule hook tag to execute/trigger.
40 * @param string $recurrence Schedule name.
41 */
42 public function override_schedule( string $hook, string $recurrence ): void {
43 $timestamp = (int) wp_next_scheduled( $hook );
44
45 wp_clear_scheduled_hook( $hook );
46
47 wp_reschedule_event( $timestamp, $recurrence, $hook );
48 }
49
50 /**
51 * Get cron schedule interval.
52 *
53 * @param string $schedule Schedule name.
54 *
55 * @since 5.1.1
56 * @return int|bool
57 */
58 public function get_cron_schedule_interval( $schedule ) {
59 $schedules = wp_get_schedules();
60 return isset( $schedules[ $schedule ] ) ? $schedules[ $schedule ]['interval'] : false;
61 }
62 }
63