PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.10.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.10.0
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / UsageTracking / Core / Scheduler.php
custom-facebook-feed / inc / UsageTracking / Core Last commit date
PayloadBuilder.php 3 weeks ago RegisterSite.php 3 weeks ago Scheduler.php 3 weeks ago Sender.php 3 weeks ago
Scheduler.php
93 lines
1 <?php
2 /**
3 * Schedules the weekly usage tracking cron. Mirrors the legacy weekly schedule pattern.
4 *
5 * @package CustomFacebookFeed\UsageTracking\Core
6 * @since 4.0
7 */
8
9 namespace CustomFacebookFeed\UsageTracking\Core;
10
11 use CustomFacebookFeed\UsageTracking\Config;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 class Scheduler {
18
19 /**
20 * Ensure weekly cron is scheduled when tracking is enabled.
21 * Call on init or when enabling the option.
22 */
23 public function schedule() {
24 $this->cleanup_legacy();
25
26 if ( ! Config::is_enabled() ) {
27 return;
28 }
29
30 if ( wp_next_scheduled( Config::CRON_HOOK ) ) {
31 return;
32 }
33
34 $tracking = array(
35 'day' => wp_rand( 0, 6 ),
36 'hour' => wp_rand( 0, 23 ),
37 'minute' => wp_rand( 0, 59 ),
38 'second' => wp_rand( 0, 59 ),
39 );
40 $tracking['offset'] = ($tracking['day'] * DAY_IN_SECONDS)
41 + ($tracking['hour'] * HOUR_IN_SECONDS)
42 + ($tracking['minute'] * MINUTE_IN_SECONDS)
43 + $tracking['second'];
44
45 $last_sunday = strtotime( 'next sunday' ) - (7 * DAY_IN_SECONDS);
46 if ( ($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS ) {
47 $tracking['initsend'] = $last_sunday + $tracking['offset'];
48 } else {
49 $tracking['initsend'] = strtotime( 'next sunday' ) + $tracking['offset'];
50 }
51
52 wp_schedule_event( $tracking['initsend'], 'weekly', Config::CRON_HOOK );
53 update_option( Config::OPTION_SCHEDULE, $tracking, false );
54 }
55
56 /**
57 * Add weekly schedule if not already present.
58 *
59 * @param array $schedules Existing cron schedules.
60 * @return array
61 */
62 public function add_schedules( $schedules ) {
63 if ( ! isset( $schedules['weekly'] ) ) {
64 $schedules['weekly'] = array(
65 'interval' => 604800,
66 'display' => __( 'Once Weekly', 'custom-facebook-feed' ),
67 );
68 }
69 return $schedules;
70 }
71
72 /**
73 * Unschedule the cron when tracking is disabled.
74 */
75 public function unschedule() {
76 wp_clear_scheduled_hook( Config::CRON_HOOK );
77 }
78
79 /**
80 * Clear the removed legacy tracking cron and delete its superseded options.
81 * Guarded so steady-state cost is a no-op.
82 */
83 private function cleanup_legacy() {
84 if ( wp_next_scheduled( 'cff_usage_tracking_cron' ) ) {
85 wp_clear_scheduled_hook( 'cff_usage_tracking_cron' );
86 }
87 if ( get_option( 'cff_smash_usage_tracking', null ) !== null ) {
88 delete_option( 'cff_smash_usage_tracking' );
89 delete_option( 'cff_usage_tracking_config' );
90 }
91 }
92 }
93