Skip to content

Commit

Permalink
Clear the PHP OPCache when a plugin is upgraded/activated/deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Apr 28, 2016
1 parent 9bbecb4 commit c4328eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/includes/traits/Plugin/WcpOpcacheUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down
5 changes: 5 additions & 0 deletions src/includes/traits/Plugin/WcpPluginUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')}();
}
}
3 changes: 3 additions & 0 deletions src/includes/traits/Plugin/WcpUpdaterUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
}
}
Expand Down

0 comments on commit c4328eb

Please sign in to comment.