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. Built from https://develop.svn.wordpress.org/trunk@40301 git-svn-id: http://core.svn.wordpress.org/trunk@40208 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fc631ffa00
commit
503d42fe6b
|
@ -1155,11 +1155,21 @@ final class WP_Theme implements ArrayAccess {
|
||||||
$results = scandir( $path );
|
$results = scandir( $path );
|
||||||
$files = array();
|
$files = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the array of excluded directories and files while scanning theme folder.
|
||||||
|
*
|
||||||
|
* @since 4.7.4
|
||||||
|
*
|
||||||
|
* @param array $exclusions Array of excluded directories and files.
|
||||||
|
*/
|
||||||
|
$exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules' ) );
|
||||||
|
|
||||||
foreach ( $results as $result ) {
|
foreach ( $results as $result ) {
|
||||||
if ( '.' == $result[0] )
|
if ( '.' == $result[0] || in_array( $result, $exclusions, true ) ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if ( is_dir( $path . '/' . $result ) ) {
|
if ( is_dir( $path . '/' . $result ) ) {
|
||||||
if ( ! $depth || 'CVS' == $result )
|
if ( ! $depth )
|
||||||
continue;
|
continue;
|
||||||
$found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
|
$found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
|
||||||
$files = array_merge_recursive( $files, $found );
|
$files = array_merge_recursive( $files, $found );
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.8-alpha-40300';
|
$wp_version = '4.8-alpha-40301';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue