Description
This function can be called safely without having to check the file extension or availability of the OPcache extension.
Whether or not invalidation is possible is cached to improve performance.
Parameters
- $filepath
-
(string) (Required) Path to the file, including extension, for which the opcode cache is to be cleared.
- $force
-
(bool) (Optional) Invalidate even if the modification time is not newer than the file in cache.
Default value: false
Return
(bool) True if opcache was invalidated for $filepath
, or there was nothing to invalidate. False if opcache invalidation is not available, or is disabled via filter.
Source
File: wp-admin/includes/file.php
function wp_opcache_invalidate( $filepath, $force = false ) {
static $can_invalidate = null;
if ( null === $can_invalidate
&& function_exists( 'opcache_invalidate' )
&& ( ! ini_get( 'opcache.restrict_api' )
|| stripos( realpath( $_SERVER['SCRIPT_FILENAME'] ), ini_get( 'opcache.restrict_api' ) ) === 0 )
) {
$can_invalidate = true;
}
if ( ! $can_invalidate ) {
return false;
}
if ( '.php' !== strtolower( substr( $filepath, -4 ) ) ) {
return false;
}
if ( apply_filters( 'wp_opcache_invalidate_file', true, $filepath ) ) {
return opcache_invalidate( $filepath, $force );
}
return false;
}
Changelog
Version | Description |
5.5.0 | Introduced. |