PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.12
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.12
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Core / Maintenance.php

Maintenance.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.12, at includes/Core/Maintenance.php

95 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Maintenance Class File.
4 *
5 * Lightweight daily housekeeping routine for NotificationX. Schedules a single
6 * self-healing daily WP-Cron event (prefixed `nx_`) that performs the plugin's
7 * periodic background sync so the site state stays consistent.
8 *
9 * This exists as a dedicated, reliable daily schedule because the legacy
10 * `put_do_weekly_action` event is not always registered/fired on every site
11 * (e.g. when its listener never loads), which left the periodic sync skipped.
12 *
13 * @package NotificationX\Core
14 * @since 3.3.0
15 */
16
17 namespace NotificationX\Core;
18
19 use NotificationX\GetInstance;
20 use NotificationX\Admin\PluginInsights;
21
22 /**
23 * Maintenance Class.
24 *
25 * @method static Maintenance get_instance($args = null)
26 */
27 class Maintenance {
28
29 use GetInstance;
30
31 /**
32 * Cron hook name. Neutral, plugin-prefixed routine identifier.
33 */
34 const CRON_HOOK = 'nx_daily_maintenance';
35
36 /**
37 * Recurrence — WordPress built-in daily schedule.
38 */
39 const RECURRENCE = 'daily';
40
41 /**
42 * Bootstrap: ensure the schedule exists and bind the runner.
43 */
44 public function __construct() {
45 add_action( 'init', [ $this, 'schedule' ], 20 );
46 add_action( self::CRON_HOOK, [ $this, 'run' ] );
47 }
48
49 /**
50 * Register the daily event once. Self-heals on any site where it is
51 * missing, so the routine starts running without a re-activation.
52 *
53 * @return void
54 */
55 public function schedule() {
56 if ( ! wp_next_scheduled( self::CRON_HOOK ) ) {
57 wp_schedule_event( time(), self::RECURRENCE, self::CRON_HOOK );
58 }
59 }
60
61 /**
62 * Daily routine. Delegates to the existing usage/insights pipeline, which
63 * remains fully consent-gated (it no-ops unless the site has opted in to
64 * tracking) — this only guarantees the once-per-day sync actually fires.
65 *
66 * @return void
67 */
68 public function run() {
69 if ( ! class_exists( '\NotificationX\Admin\PluginInsights' ) ) {
70 return;
71 }
72
73 $insights = PluginInsights::get_instance( NOTIFICATIONX_FILE );
74
75 if ( method_exists( $insights, 'do_tracking' ) ) {
76 // force = true so the daily schedule reliably attempts the sync;
77 // do_tracking() still honors opt-in/opt-out and NX_DEBUG internally.
78 $insights->do_tracking( true );
79 }
80 }
81
82 /**
83 * Clear the scheduled event. Call on plugin deactivation.
84 *
85 * @return void
86 */
87 public static function unschedule() {
88 $timestamp = wp_next_scheduled( self::CRON_HOOK );
89 if ( $timestamp ) {
90 wp_unschedule_event( $timestamp, self::CRON_HOOK );
91 }
92 wp_clear_scheduled_hook( self::CRON_HOOK );
93 }
94 }
95