PluginProbe
Patchstack – WordPress & Plugins Security / 2.1.6
Patchstack – WordPress & Plugins Security v2.1.6
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.6, at includes/cron.php

118 lines 3.7 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 if ( ! get_option( 'patchstack_cron_offset' ) ) {
69 $crons = array(
70 'patchstack_daily' => strtotime( 'today' ) + mt_rand( 0, 86399 ),
71 'patchstack_hourly' => strtotime( 'today' ) + mt_rand( 0, 3600 ),
72 'patchstack_trihourly' => strtotime( 'today' ) + mt_rand( 0, 9599 ),
73 'patchstack_twicedaily' => strtotime( 'today' ) + mt_rand( 0, 43199 ),
74 'patchstack_15minute' => strtotime( 'today' ) + mt_rand( 0, 899 ),
75 );
76 update_option( 'patchstack_cron_offset', $crons );
77
78 // Clear existing scheduled events so we can use the new timestamps.
79 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 ) {
80 wp_clear_scheduled_hook( $event );
81 }
82 } else {
83 $crons = get_option( 'patchstack_cron_offset' );
84 }
85
86 // List of the different events.
87 $free = array(
88 'patchstack_send_software_data' => 'patchstack_hourly',
89 'patchstack_update_license_status' => 'patchstack_twicedaily',
90 'patchstack_send_ping' => 'patchstack_trihourly',
91 'patchstack_update_plugins' => 'patchstack_15minute',
92 );
93
94 $premium = array(
95 'patchstack_send_hacker_logs' => 'patchstack_15minute',
96 'patchstack_post_firewall_rules' => 'patchstack_twicedaily',
97 'patchstack_post_firewall_htaccess_rules' => 'patchstack_trihourly',
98 'patchstack_post_dynamic_firewall_rules' => 'patchstack_hourly',
99 'patchstack_send_event_logs' => 'patchstack_15minute',
100 );
101
102 // Schedule the events if they are not scheduled yet.
103 foreach ( $free as $event => $interval ) {
104 if ( ! wp_next_scheduled( $event ) ) {
105 wp_schedule_event( $crons[ $interval ], $interval, $event );
106 }
107 }
108
109 if ( $this->get_option( 'patchstack_license_free', 0 ) == 0 ) {
110 foreach ( $premium as $event => $interval ) {
111 if ( ! wp_next_scheduled( $event ) ) {
112 wp_schedule_event( $crons[ $interval ], $interval, $event );
113 }
114 }
115 }
116 }
117 }
118