Skip to content

Instantly share code, notes, and snippets.

@felixarntz
Last active January 21, 2020 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixarntz/cc2a33e9dc01874c6a4cffffc1b19efb to your computer and use it in GitHub Desktop.
Save felixarntz/cc2a33e9dc01874c6a4cffffc1b19efb to your computer and use it in GitHub Desktop.
Clears PHP OpCache when visiting the Plugins admin screen (wp-admin/plugins.php).
<?php
/**
* Clear OpCache Simple.
*
* @author Felix Arntz, Google
* @license Apache 2.0
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Clear OpCache Simple
* Description: Clears PHP OpCache when visiting the Plugins admin screen (wp-admin/plugins.php).
* Plugin URI: https://gist.github.com/felixarntz/cc2a33e9dc01874c6a4cffffc1b19efb
* Version: 0.1.0
* Author: Felix Arntz, Google
* Author URI: https://felix-arntz.me
* License: Apache License 2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
*/
add_action(
'current_screen',
function( $screen ) {
if ( 'plugins' !== $screen->id ) {
return;
}
if ( ! function_exists( 'opcache_reset' ) ) {
return;
}
opcache_reset();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment