diff --git a/src/includes/traits/Plugin/WcpOpcacheUtils.php b/src/includes/traits/Plugin/WcpOpcacheUtils.php index dee5b0dc..fb3d6cfa 100644 --- a/src/includes/traits/Plugin/WcpOpcacheUtils.php +++ b/src/includes/traits/Plugin/WcpOpcacheUtils.php @@ -63,6 +63,18 @@ public function clearOpcache($manually = false, $maybe = true) return 0; // Not applicable. } + /** + * Wipe the Opcache (by force). + * + * @since 16xxxx Improving OPCache support. + * + * @return int Total keys cleared. + */ + public function wipeOpcacheByForce() + { + return $this->wipeOpcache(false, false); + } + /** * Clear AC class file from Opcache (by force). * diff --git a/src/includes/traits/Plugin/WcpPluginUtils.php b/src/includes/traits/Plugin/WcpPluginUtils.php index 52fe8f72..bc6ad21d 100644 --- a/src/includes/traits/Plugin/WcpPluginUtils.php +++ b/src/includes/traits/Plugin/WcpPluginUtils.php @@ -17,12 +17,17 @@ trait WcpPluginUtils * @param bool True if activating|deactivating network-wide. Defaults to boolean `FALSE` in case parameter is not passed to hook. * * @return int Total files wiped|cleared by this routine (if any). + * + * @note Also wipes the PHP OPCache. */ public function autoClearOnPluginActivationDeactivation($plugin, $network_wide = false) { if (!$this->applyWpFilters(GLOBAL_NS.'_auto_clear_on_plugin_activation_deactivation', true)) { return 0; // Nothing to do here. } + + add_action('shutdown', [$this, 'wipeOpcacheByForce'], -PHP_INT_MAX); + return $this->{($network_wide ? 'autoWipeCache' : 'autoClearCache')}(); } } diff --git a/src/includes/traits/Plugin/WcpUpdaterUtils.php b/src/includes/traits/Plugin/WcpUpdaterUtils.php index 2eabdf27..81899db8 100644 --- a/src/includes/traits/Plugin/WcpUpdaterUtils.php +++ b/src/includes/traits/Plugin/WcpUpdaterUtils.php @@ -51,6 +51,7 @@ public function autoClearOnUpgraderProcessComplete(\WP_Upgrader $upgrader_instan } if ($upgrading_active_plugin) { $counter += $this->autoClearCache(); + add_action('shutdown', [$this, 'wipeOpcacheByForce'], -PHP_INT_MAX); } break; // Break switch. @@ -91,12 +92,14 @@ public function autoClearOnUpgraderProcessComplete(\WP_Upgrader $upgrader_instan if ($upgrading_active_theme || $upgrading_active_parent_theme) { $counter += $this->autoClearCache(); + add_action('shutdown', [$this, 'wipeOpcacheByForce'], -PHP_INT_MAX); } break; // Break switch. case 'core': // Core upgrade. default: // Or any other sort of upgrade. $counter += $this->autoClearCache(); + add_action('shutdown', [$this, 'wipeOpcacheByForce'], -PHP_INT_MAX); break; // Break switch. } }