Make WordPress Core

Changeset 48160

Timestamp:
06/25/2020 07:13:22 AM (4 years 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.

Location:
trunk/src/wp-admin/includes
Files:
3 edited

Legend:

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

    r47808 r48160  
    162162        $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE );
    163163
     164
    164165        require_once ABSPATH . 'wp-admin/includes/update-core.php';
    165166
  • trunk/src/wp-admin/includes/file.php

    r48115 r48160  
    499499        return new WP_Error( 'unable_to_write', __( 'Unable to write to file.' ) );
    500500    }
    501     if ( 'php' === $extension && function_exists( 'opcache_invalidate' ) ) {
    502         opcache_invalidate( $real_file, true );
    503     }
     501    wp_opcache_invalidate( $real_file, true );
    504502
    505503    if ( $is_active && 'php' === $extension ) {
     
    609607            // Roll-back file change.
    610608            file_put_contents( $real_file, $previous_content );
    611             if ( function_exists( 'opcache_invalidate' ) ) {
    612                 opcache_invalidate( $real_file, true );
    613             }
     609            wp_opcache_invalidate( $real_file, true );
    614610
    615611            if ( ! isset( $result['message'] ) ) {
     
    17441740                }
    17451741            }
     1742
    17461743        } elseif ( 'd' === $fileinfo['type'] ) {
    17471744            if ( ! $wp_filesystem->is_dir( $to . $filename ) ) {
     
    22782275    <?php
    22792276}
     2277
     2278
     2279
     2280
     2281
     2282
     2283
     2284
     2285
     2286
     2287
     2288
     2289
     2290
     2291
     2292
     2293
     2294
     2295
     2296
     2297
     2298
     2299
     2300
     2301
     2302
     2303
     2304
     2305
     2306
     2307
     2308
     2309
     2310
     2311
     2312
     2313
     2314
     2315
     2316
     2317
     2318
     2319
     2320
     2321
     2322
     2323
     2324
     2325
     2326
     2327
     2328
     2329
     2330
     2331
     2332
     2333
     2334
     2335
     2336
     2337
     2338
     2339
     2340
     2341
     2342
     2343
     2344
     2345
     2346
     2347
     2348
  • 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
    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
     1364
     1365
    13571366            }
    13581367        } elseif ( 'd' === $fileinfo['type'] ) {
Note: See TracChangeset for help on using the changeset viewer.