From ae983c3f99723b1a36619375c2e92d6edf8a3e7c Mon Sep 17 00:00:00 2001 From: Mike Schroder Date: Tue, 2 Mar 2021 17:11:35 +0000 Subject: [PATCH] Upgrade/Install: Invalidate OPcache for `version.php` during update. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Invalidate OPcache for `wp-content/version.php` on update individually, since it’s copied separately. Props stodorovic, krstarica, cenay, desrosj, pbiron, sergeybiryukov, mikeschroder. Fixes #51686, #51281. See #36455. git-svn-id: https://develop.svn.wordpress.org/trunk@50475 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/update-core.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index 6d9d243ddd..9d0452dbcb 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -946,6 +946,15 @@ function update_core( $from, $to ) { } $wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE ); + + /* + * `wp_opcache_invalidate()` only exists in WordPress 5.5 or later, + * so don't run it when upgrading from older versions. + */ + if ( function_exists( 'wp_opcache_invalidate' ) ) { + wp_opcache_invalidate( $versions_file ); + } + require WP_CONTENT_DIR . '/upgrade/version-current.php'; $wp_filesystem->delete( $versions_file ); @@ -1117,6 +1126,14 @@ function update_core( $from, $to ) { $result = new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' ); } $wp_filesystem->chmod( $to . 'wp-includes/version.php', FS_CHMOD_FILE ); + + /* + * `wp_opcache_invalidate()` only exists in WordPress 5.5 or later, + * so don't run it when upgrading from older versions. + */ + if ( function_exists( 'wp_opcache_invalidate' ) ) { + wp_opcache_invalidate( $to . 'wp-includes/version.php' ); + } } // Check to make sure everything copied correctly, ignoring the contents of wp-content.