Make WordPress Core

Changeset 40326


Ignore:
Timestamp:
03/24/2017 06:43:13 PM (7 years ago)
Author:
swissspidy
Message:

Themes: Add filter for excluding directories from being scanned for template files.

Exclude 'node_modules' directories from paths searched in WP_Theme::scandir(). Introduces the theme_scandir_exclusions filter to allow sites to
exclude any other paths like bower_components or vendor from being searched for template files.

Props lukasbesch, dd32, swisspidy, rachelbaker.
Fixes #38292.

Merges [40301] to the 4.7 branch.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/class-wp-theme.php

    r39809 r40326  
    11401140        $files = array();
    11411141
     1142        /**
     1143         * Filters the array of excluded directories and files while scanning theme folder.
     1144         *
     1145         * @since 4.7.4
     1146         *
     1147         * @param array $exclusions Array of excluded directories and files.
     1148         */
     1149        $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules' ) );
     1150
    11421151        foreach ( $results as $result ) {
    1143             if ( '.' == $result[0] )
     1152            if ( '.' == $result[0] || in_array( $result, $exclusions, true ) ) {
    11441153                continue;
     1154            }
    11451155            if ( is_dir( $path . '/' . $result ) ) {
    1146                 if ( ! $depth || 'CVS' == $result )
     1156                if ( ! $depth )
    11471157                    continue;
    11481158                $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
Note: See TracChangeset for help on using the changeset viewer.