PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.2.25
MxChat – AI Chatbot & Content Generation for WordPress v3.2.25
3.2.25 3.2.24 3.2.23 3.2.22 3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 All 156 releases
← All changes | includes/class-mxchat-cache-purge.php +31 -1 3.2.16 → 3.2.25 View file →
@@ -32,8 +32,22 @@
32 32 const DEBOUNCE_TRANSIENT = 'mxchat_cache_purge_debounce';
33 33 const DEBOUNCE_SECONDS = 30;
34 34 const DEFERRED_EVENT = 'mxchat_deferred_cache_purge';
35 35
36 + /**
37 + * Owner switch (plan b76ed6, Support Ticket 468: a 1,400-page FlyingPress
38 + * site lost its whole preload on every settings save). Standalone option,
39 + * 'on' / 'off'; absent means ON so existing sites keep today's behaviour.
40 + * Rendered on Settings → Optimization → Page Cache Compatibility and saved
41 + * by the mxchat_cache_purge_enabled case in class-ajax-handler.php.
42 + *
43 + * The switch is read when a watched option is actually written (and when
44 + * a deferred purge fires), not at plugin load: the hooks below cost
45 + * nothing until a save happens, and a site that never touches the switch
46 + * never pays a get_option() for it on a visitor request.
47 + */
48 + const OPTION_NAME = 'mxchat_cache_purge_enabled';
49 +
36 50 private static $instance = null;
37 51
38 52 /**
39 53 * Whether this request already queued a shutdown purge (one per request).
@@ -48,8 +62,18 @@
48 62 }
49 63 return self::$instance;
50 64 }
51 65
66 + /**
67 + * Whether MxChat clears page caches when its settings are saved.
68 + * Default ON; only an explicit 'off' switches it off.
69 + *
70 + * @return bool
71 + */
72 + public static function is_enabled() {
73 + return get_option(self::OPTION_NAME, 'on') !== 'off';
74 + }
75 +
52 76 private function __construct() {
53 77 foreach ($this->watched_options() as $option_name) {
54 78 add_action('update_option_' . $option_name, array($this, 'queue_purge'), 10, 0);
55 79 add_action('add_option_' . $option_name, array($this, 'queue_purge'), 10, 0);
@@ -79,9 +103,9 @@
79 103 /**
80 104 * Coalesce all option writes in this request into one shutdown purge.
81 105 */
82 106 public function queue_purge() {
83 - if ($this->purge_queued) {
107 + if ($this->purge_queued || !self::is_enabled()) {
84 108 return;
85 109 }
86 110 $this->purge_queued = true;
87 111 add_action('shutdown', array($this, 'run_queued_purge'), 5);
@@ -106,8 +130,14 @@
106 130 * Purge every supported page cache via its own public API. Each call is
107 131 * guarded so installs without that plugin skip it silently.
108 132 */
109 133 public function purge_page_caches() {
134 + // The owner may have switched the purge off after a deferred purge was
135 + // scheduled; off means off.
136 + if (!self::is_enabled()) {
137 + return;
138 + }
139 +
110 140 // WP Rocket — public helper, clears the whole domain's page cache.
111 141 if (function_exists('rocket_clean_domain')) {
112 142 rocket_clean_domain();
113 143 }