Before 5.5, WordPress relied on hosting provider or user settings and plugins to handle purging or invalidating of core Core is the set of software required to run WordPress. The Core Development Team builds WordPress., plugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party, and theme PHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher changes. This resulted in problems for users like PHP fatal errors when a cached file included a file that had been deleted during an update.
As of [48160], WordPress attempts to invalidate PHP files when Core, Plugins, or Themes are updated.
To help with this, a new function is available, wp_opcache_invalidate()
, a safe-to-call-directly wrapper for PHP’s native opcache_invalidate()
. In order to avoid PHP warnings, the function handles the checks necessary to see whether OPcache is available, and whether invalidation is allowed by the current PHP settings.
function wp_opcache_invalidate( $filepath, $force = false )
The function includes a new filter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output., wp_opcache_invalidate_file
, which allows disabling WordPress’ invalidation by file, in case it is necessary due to platform concerns, or there are certain files that a user wants to keep from being invalidated.
You can skip invalidation for one file like this:
// Disable opcode cache invalidation for `/path/to/myfile.php`.
function disable_myfile_invalidation( $will_invalidate, $filename ) {
if ( '/path/to/myfile.php' === $filename ) {
return false;
}
return true;
}
add_filter( 'wp_opcache_invalidate_file', 'disable_myfile_invalidation', 10, 3 );
Or disable it entirely:
// Disable all of WordPress' opcode cache invalidation:
add_filter( 'wp_opcache_invalidate_file', '__return_false' );
Does this change fix the issues you’ve been having with opcode cache invalidation?
Please test and leave a comment here or open a ticket if you run into problems, have concerns, or need additional hooks In WordPress theme and development, hooks are functions that can be applied to an action or a Filter in WordPress. Actions are functions performed when a certain event occurs in WordPress. Filters allow you to modify certain functions. Arguments used to hook both filters and actions look the same. for your use-case.
Thanks to @aaroncampbell for review!
#5-5, #dev-notes