WordPress.org

Make WordPress Core

Ticket #36455: 36455.14.diff

File 36455.14.diff, 4.4 KB (added by ayeshrajans, 2 months ago)
  • src/wp-admin/includes/file.php

    diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
    index cca39895bab..84b08d6886b 100644
    function wp_edit_theme_plugin_file( $args ) { 
    498498        if ( false === $written ) {
    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 ) {
    506504
    function wp_edit_theme_plugin_file( $args ) { 
    608606
    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'] ) ) {
    616612                                $message = __( 'Something went wrong.' );
    function copy_dir( $from, $to, $skip_list = array() ) { 
    17411737                                        return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
    17421738                                }
    17431739                        }
     1740                        wp_opcache_invalidate( $to . $filename );
    17441741                } elseif ( 'd' === $fileinfo['type'] ) {
    17451742                        if ( ! $wp_filesystem->is_dir( $to . $filename ) ) {
    17461743                                if ( ! $wp_filesystem->mkdir( $to . $filename, FS_CHMOD_DIR ) ) {
    function wp_print_request_filesystem_credentials_modal() { 
    22762273        </div>
    22772274        <?php
    22782275}
     2276
     2277/**
     2278 * Attempt to clear the opcode cache for an individual PHP file.
     2279 *
     2280 * This function can be called safely without having to check the file extension
     2281 * or availability of the OPcache extension.
     2282 *
     2283 * Whether or not invalidation is possible is cached to improve performance.
     2284 *
     2285 * @since 5.5
     2286 *
     2287 * @link https://www.php.net/manual/en/function.opcache-invalidate.php
     2288 *
     2289 * @param string $filepath Path to the file, including extension, for which the opcode cache is to be cleared.
     2290 * @param bool   $force    Invalidate even if the modification time is not newer than the file in cache. Default `false`.
     2291 *
     2292 * @return bool `true` if opcache was invalidated for `$filepath`, or there was nothing to invalidate.
     2293 *              `false` if opcache invalidation is not available, or is disabled via filter.
     2294 */
     2295function wp_opcache_invalidate( $filepath, $force = false ) {
     2296        static $can_invalidate = null;
     2297
     2298        /*
     2299         * Check to see if WordPress is able to run `opcache_invalidate()` or not, and cache the value.
     2300         *
     2301         * First, check to see if the function is available to call, then if the host has restricted
     2302         * the ability to run the function to avoid a PHP warning.
     2303         *
     2304         * `opcache.restrict_api` can specify the path for files allowed to call `opcache_invalidate()`.
     2305         *
     2306         * If the host has this set, check whether the path in `opcache.restrict_api` matches
     2307         * the beginning of the path of the current file.
     2308         *
     2309         * See: https://www.php.net/manual/en/opcache.configuration.php
     2310         */
     2311        if ( $can_invalidate === null ) {
     2312                $can_invalidate = function_exists( 'opcache_invalidate' ) &&
     2313                        ( ! ini_get( 'opcache.restrict_api' ) || stripos( __FILE__, ini_get( 'opcache.restrict_api' ) ) === 0 );
     2314        }
     2315
     2316        // If invalidation is not available, return early.
     2317        if ( ! $can_invalidate ) {
     2318                return false;
     2319        }
     2320
     2321        // Verify that file to be invalidated has a PHP-related extension.
     2322        if ( ! preg_match( '/\.(?:php)$/i', $filepath ) ) {
     2323                return false;
     2324        }
     2325
     2326        /**
     2327         * Filters whether to invalidate a file from the opcode cache.
     2328         *
     2329         * @since 5.5
     2330         *
     2331         * @param bool   $will_invalidate Whether WordPress will invalidate `$filename`. Default `true`.
     2332         * @param string $filename        The PHP filename to invalidate.
     2333         */
     2334        if ( apply_filters( 'wp_opcache_invalidate_file', true, $filepath ) ) {
     2335                return opcache_invalidate( $filepath, $force );
     2336        }
     2337
     2338        return false;
     2339}
  • src/wp-admin/includes/update-core.php

    diff --git src/wp-admin/includes/update-core.php src/wp-admin/includes/update-core.php
    index 595ebc053a8..0fe76de8347 100644
    function _copy_dir( $from, $to, $skip_list = array() ) { 
    13521352                                        return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
    13531353                                }
    13541354                        }
     1355                        wp_opcache_invalidate( $to . $filename );
    13551356                } elseif ( 'd' === $fileinfo['type'] ) {
    13561357                        if ( ! $wp_filesystem->is_dir( $to . $filename ) ) {
    13571358                                if ( ! $wp_filesystem->mkdir( $to . $filename, FS_CHMOD_DIR ) ) {