WordPress.org

Make WordPress Core

Ticket #42573: 42573.3.patch

File 42573.3.patch, 2.2 KB (added by mariovalney, 6 months ago)

Allow developers to flush files cache

  • wp-includes/class-wp-theme.php

    diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php
    index 171d8b6..b2331e1 100644
    a b final class WP_Theme implements ArrayAccess { 
    985985         */
    986986        public function get_files( $type = null, $depth = 0, $search_parent = false ) {
    987987                // get and cache all theme files to start with.
    988                 $label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) );
    989                 $transient_key = substr( $label, 0, 29 ) . md5( $label );
     988                $transient_key = $this->get_files_transient_key();
     989
     990                $all_files = false;
     991
     992                if ( ! WP_DEBUG ) {
     993                        $all_files = get_transient( $transient_key );
     994                }
    990995
    991                 $all_files = get_transient( $transient_key );
    992996                if ( false === $all_files ) {
    993997                        $all_files = (array) self::scandir( $this->get_stylesheet_directory(), null, -1 );
    994998
    final class WP_Theme implements ArrayAccess { 
    9961000                                $all_files += (array) self::scandir( $this->get_template_directory(), null, -1 );
    9971001                        }
    9981002
    999                         set_transient( $transient_key, $all_files, HOUR_IN_SECONDS );
     1003                        if ( ! WP_DEBUG ) {
     1004                                set_transient( $transient_key, $all_files, HOUR_IN_SECONDS );
     1005                        }
    10001006                }
    10011007
    10021008                // Filter $all_files by $type & $depth.
    final class WP_Theme implements ArrayAccess { 
    11101116        }
    11111117
    11121118        /**
     1119         * Clear the cache of files in the theme's directory.
     1120         *
     1121         * @since 4.9.1
     1122         *
     1123         * @return bool True if successful, false otherwise.
     1124         */
     1125        public function flush_files_cache() {
     1126                $transient_key = $this->get_files_transient_key();
     1127                return delete_transient( $transient_key );
     1128        }
     1129
     1130        /**
    11131131         * Scans a directory for files of a certain extension.
    11141132         *
    11151133         * @since 3.4.0
    final class WP_Theme implements ArrayAccess { 
    14951513                // Don't mark up; Do translate.
    14961514                return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
    14971515        }
     1516
     1517        /**
     1518         * Return a transient key used to cache the files in the theme's directory
     1519         *
     1520         * @since 4.9.1
     1521         * @return string The transient key used into WP_Theme::get_files.
     1522         */
     1523        private function get_files_transient_key() {
     1524                $label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) );
     1525                return substr( $label, 0, 29 ) . md5( $label );
     1526        }
    14981527}