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 +42 -3 3.2.9 → 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);
@@ -59,13 +83,22 @@
59 83
60 84 /**
61 85 * Option names whose writes trigger a page-cache purge.
62 86 *
87 + * Defaults cover every option whose values reach the cached page's inline
88 + * widget payload: mxchat_options (settings/behavior gates),
89 + * mxchat_theme_options (active AI theme CSS + bot theme assignments —
90 + * written only by the MxChat Theme add-on's admin AJAX actions), and
91 + * mxchat_prompts_options (Pinecone toggle — written only by the prompts
92 + * autosave). All write sites are admin-action-driven; the debounce
93 + * absorbs back-to-back writes like apply-and-save.
94 + *
63 95 * @return string[]
64 96 */
65 97 private function watched_options() {
66 - $options = apply_filters('mxchat_cache_purge_watched_options', array('mxchat_options'));
67 - return is_array($options) ? array_filter(array_map('strval', $options)) : array('mxchat_options');
98 + $defaults = array('mxchat_options', 'mxchat_theme_options', 'mxchat_prompts_options');
99 + $options = apply_filters('mxchat_cache_purge_watched_options', $defaults);
100 + return is_array($options) ? array_filter(array_map('strval', $options)) : $defaults;
68 101 }
69 102
70 103 /**
71 104 * Coalesce all option writes in this request into one shutdown purge.
@@ -70,9 +103,9 @@
70 103 /**
71 104 * Coalesce all option writes in this request into one shutdown purge.
72 105 */
73 106 public function queue_purge() {
74 - if ($this->purge_queued) {
107 + if ($this->purge_queued || !self::is_enabled()) {
75 108 return;
76 109 }
77 110 $this->purge_queued = true;
78 111 add_action('shutdown', array($this, 'run_queued_purge'), 5);
@@ -97,8 +130,14 @@
97 130 * Purge every supported page cache via its own public API. Each call is
98 131 * guarded so installs without that plugin skip it silently.
99 132 */
100 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 +
101 140 // WP Rocket — public helper, clears the whole domain's page cache.
102 141 if (function_exists('rocket_clean_domain')) {
103 142 rocket_clean_domain();
104 143 }