WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/25/2020 07:13:22 AM (7 months ago)
Author:
mikeschroder
Message:

Upgrade/Install: Invalidate OPcache for PHP files during updates.

When files are copied into place, check whether opcode invalidation is available and attempt to invalidate to avoid unintended behavior or fatal errors from themes, plugins, or core.

Introduces wp_opcache_invalidate() to allow safe invalidation of PHP files from opcode cache, and a filter, wp_opcache_invalidate_file to override the behavior.

Replaces the existing calls to opcache_invalidate() in the plugin and theme editors to use the new function.

Thanks to jnylen0 for porting over a patch from ClassicPress that provided much of the approach for what is being committed.

Props nigro.simone, dd32, JasWSInc, szepe.viktor, swissspidy, JanR, asalce, Garavani, pavelevap, pputzer, GregLone, benoitchantre, jadonn, doc987, kraftbj, Krstarica, jnylen0, nextendweb, williampatton, ayeshrajans, joostdevalk, stevenkussmaul, boogah, jorbin, mikeschroder.
Fixes #36455, #50354.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/update-core.php

    r48067 r48160  
    13191319 * Assumes that WP_Filesystem() has already been called and setup.
    13201320 *
    1321  * This is a temporary function for the 3.1 -> 3.2 upgrade, as well as for those
    1322  * upgrading to 3.7+.
     1321 * This is a standalone copy of the `copy_dir()` function that is used to
     1322 * upgrade the core files. It is placed here so that the version of this
     1323 * function from the *new* WordPress version will be called.
     1324 *
     1325 * It was initially added for the 3.1 -> 3.2 upgrade.
    13231326 *
    13241327 * @ignore
     
    13271330 *
    13281331 * @see copy_dir()
     1332 * @link https://core.trac.wordpress.org/ticket/17173
    13291333 *
    13301334 * @global WP_Filesystem_Base $wp_filesystem
     
    13551359                    return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
    13561360                }
     1361            }
     1362
     1363            // `wp_opcache_invalidate()` only exists in WordPress 5.5, so don't run it when upgrading to 5.5.
     1364            if ( function_exists( 'wp_opcache_invalidate' ) ) {
     1365                wp_opcache_invalidate( $to . $filename );
    13571366            }
    13581367        } elseif ( 'd' === $fileinfo['type'] ) {
Note: See TracChangeset for help on using the changeset viewer.