PluginProbe
Patchstack – WordPress & Plugins Security / 2.1.19
Patchstack – WordPress & Plugins Security v2.1.19
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
patchstack / includes / cron.php

cron.php in Patchstack – WordPress & Plugins Security 2.1.19, at includes/cron.php

117 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Do not allow the file to be called directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * This class is used to schedule the tasks used by Patchstack.
10 */
11 class P_Cron extends P_Core {
12
13 /**
14 * Add the actions required for the task scheduler.
15 *
16 * @param Patchstack $core
17 * @return void
18 */
19 public function __construct( $core ) {
20 parent::__construct( $core );
21 add_action( 'init', array( $this, 'schedule_events' ) );
22 add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) );
23 }
24
25 /**
26 * Define our own custom cron schedules.
27 *
28 * @param array $schedules
29 * @return array
30 */
31 public function cron_schedules( $schedules ) {
32 // Define the scheduled tasks.
33 $schedules['patchstack_15minute'] = array(
34 'interval' => ( 60 * 15 ),
35 'display' => __( 'Every 15 Minutes' ),
36 );
37
38 $schedules['patchstack_hourly'] = array(
39 'interval' => ( 60 * 60 ),
40 'display' => __( 'Every Hour' ),
41 );
42
43 $schedules['patchstack_trihourly'] = array(
44 'interval' => ( 60 * 60 * 3 ),
45 'display' => __( 'Every 3 Hours' ),
46 );
47
48 $schedules['patchstack_twicedaily'] = array(
49 'interval' => ( 60 * 60 * 12 ),
50 'display' => __( '2 Times Daily' ),
51 );
52
53 $schedules['patchstack_daily'] = array(
54 'interval' => ( 60 * 60 * 24 ),
55 'display' => __( '1 Time Daily' ),
56 );
57
58 return $schedules;
59 }
60
61 /**
62 * Initialize our scheduled tasks.
63 *
64 * @return void
65 */
66 public function schedule_events() {
67 // Random time throughout the day to make sure not all sites synchronize at the same time.
68 $crons = get_option( 'patchstack_cron_offset', false );
69 if ( ! $crons || ! isset ( $crons['patchstack_daily'] ) ) {
70 $crons = array(
71 'patchstack_daily' => strtotime( 'today' ) + mt_rand( 0, 86399 ),
72 'patchstack_hourly' => strtotime( 'today' ) + mt_rand( 0, 3600 ),
73 'patchstack_trihourly' => strtotime( 'today' ) + mt_rand( 0, 9599 ),
74 'patchstack_twicedaily' => strtotime( 'today' ) + mt_rand( 0, 43199 ),
75 'patchstack_15minute' => strtotime( 'today' ) + mt_rand( 0, 899 ),
76 );
77 update_option( 'patchstack_cron_offset', $crons );
78
79 // Clear existing scheduled events so we can use the new timestamps.
80 foreach ( array( 'patchstack_send_software_data', 'patchstack_send_hacker_logs', 'patchstack_post_firewall_rules', 'patchstack_post_firewall_htaccess_rules', 'patchstack_post_dynamic_firewall_rules', 'patchstack_update_license_status', 'patchstack_send_event_logs', 'patchstack_update_plugins', 'patchstack_send_ping' ) as $event ) {
81 wp_clear_scheduled_hook( $event );
82 }
83 }
84
85 // List of the different events.
86 $free = array(
87 'patchstack_send_software_data' => 'patchstack_twicedaily',
88 'patchstack_update_license_status' => 'patchstack_twicedaily',
89 'patchstack_send_ping' => 'patchstack_trihourly',
90 'patchstack_update_plugins' => 'patchstack_15minute'
91 );
92
93 $premium = array(
94 'patchstack_send_hacker_logs' => 'patchstack_15minute',
95 'patchstack_post_firewall_rules' => 'patchstack_twicedaily',
96 'patchstack_post_firewall_htaccess_rules' => 'patchstack_trihourly',
97 'patchstack_post_dynamic_firewall_rules' => 'patchstack_hourly',
98 'patchstack_send_event_logs' => 'patchstack_15minute'
99 );
100
101 // Schedule the events if they are not scheduled yet.
102 foreach ( $free as $event => $interval ) {
103 if ( ! wp_next_scheduled( $event ) ) {
104 wp_schedule_event( $crons[ $interval ], $interval, $event );
105 }
106 }
107
108 if ( $this->get_option( 'patchstack_license_free', 0 ) == 0 ) {
109 foreach ( $premium as $event => $interval ) {
110 if ( ! wp_next_scheduled( $event ) ) {
111 wp_schedule_event( $crons[ $interval ], $interval, $event );
112 }
113 }
114 }
115 }
116 }
117