WP_CLI\Utils
expand_globs()
Expand within paths to their matching paths.
Has no effect on paths which do not use glob patterns.
No Hooks.
Returns
Array
Usage
expand_globs( $paths, $flags );
- $paths(string|array
) (required) - Single path as a string, or an array of paths.
- $flags(int|'default')
- Flags to pass to glob.
Default:GLOB_BRACE
expand_globs() expand globs code WP-CLI 2.13.0-alpha
function expand_globs( $paths, $flags = 'default' ) {
// Compatibility for systems without GLOB_BRACE.
$glob_func = 'glob';
if ( 'default' === $flags ) {
if ( ! defined( 'GLOB_BRACE' ) || getenv( 'WP_CLI_TEST_EXPAND_GLOBS_NO_GLOB_BRACE' ) ) {
$glob_func = 'WP_CLI\Utils\glob_brace';
} else {
$flags = GLOB_BRACE;
}
}
$expanded = [];
foreach ( (array) $paths as $path ) {
$matching = [ $path ];
if ( preg_match( '/[' . preg_quote( '*?[]{}!', '/' ) . ']/', $path ) ) {
$matching = $glob_func( $path, $flags ) ?: [];
}
$expanded = array_merge( $expanded, $matching );
}
return array_values( array_unique( $expanded ) );
}