@@ -23,9 +23,10 @@ trait IterableCodeExtractor {
2323 * @param array $options {
2424 * Optional. An array of options passed down to static::fromString()
2525 *
26- * @type bool $wpExtractTemplates Extract 'Template Name' headers in theme files. Default 'false'.
27- * @type bool $wpExtractPatterns Extract 'Title' and 'Description' headers in pattern files. Default 'false'.
28- * @type array $restrictFileNames Skip all files which are not included in this array.
26+ * @type bool $wpExtractTemplates Extract 'Template Name' headers in theme files. Default 'false'.
27+ * @type bool $wpExtractPatterns Extract 'Title' and 'Description' headers in pattern files. Default 'false'.
28+ * @type array $restrictFileNames Skip all files which are not included in this array.
29+ * @type array $restrictDirectories Skip all directories which are not included in this array.
2930 * }
3031 * @return null
3132 */
@@ -38,8 +39,18 @@ public static function fromFile( $file_or_files, Translations $translations, arr
3839 }
3940 }
4041
42+ $ relative_file_path = ltrim ( str_replace ( static ::$ dir , '' , Utils \normalize_path ( $ file ) ), '/ ' );
43+
4144 // Make sure a relative file path is added as a comment.
42- $ options ['file ' ] = ltrim ( str_replace ( static ::$ dir , '' , Utils \normalize_path ( $ file ) ), '/ ' );
45+ $ options ['file ' ] = $ relative_file_path ;
46+
47+ if ( ! empty ( $ options ['restrictDirectories ' ] ) ) {
48+ $ top_level_dirname = explode ( '/ ' , $ relative_file_path )[0 ];
49+
50+ if ( ! in_array ( $ top_level_dirname , $ options ['restrictDirectories ' ], true ) ) {
51+ continue ;
52+ }
53+ }
4354
4455 $ text = file_get_contents ( $ file );
4556
0 commit comments