You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
\\WP_Parser\Importer::import_file() provides the wp_parser_pre_import_file filter to skip importing a particular file.
It would improve efficiency if there were a similar filter earlier in the pipeline, e.g., in \\WP_Parser\get_wp_files(). For example,
functionget_wp_files( $directory ) {
$iterableFiles = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $directory )
);
$files = array();
try {
foreach ( $iterableFilesas$file ) {
if ( 'php' !== $file->getExtension() ) {
continue;
}
if ( ! apply_filters( 'wp_parser_pre_get_wp_file', true, $file->getPathname(), $directory ) ) {
continue;
}
$files[] = $file->getPathname();
}
} catch ( \UnexpectedValueException$exc ) {
returnnew \WP_Error(
'unexpected_value_exception',
sprintf( 'Directory [%s] contained a directory we can not recurse into', $directory )
);
}
return$files;
}
I use this plugin to produce developer documentation for plugins/themes I create for clients, and currently hook into wp_parser_pre_import_file to skip importing anything in tests/ or vendor/ sub-dirs of a plugin/theme. Having the proposed wp_parser_pre_get_wp_file hook would allow avoiding the overhead of parsing all those files, only to skip them later in the pipeline.
Here is an example of a func I would hook into the proposed filter, to show why the proposed filter takes the additional $directory param that wp_parser_pre_import_file does not:
+1 for this feature. I also have a plugin parsing plugins where I exclude directories. For filtering directories we should use a RecursiveCallbackFilterIterator so the directories (and its files) are not traversed recursively. This saves a lot of computing power.
\\WP_Parser\Importer::import_file()
provides thewp_parser_pre_import_file
filter to skip importing a particular file.It would improve efficiency if there were a similar filter earlier in the pipeline, e.g., in
\\WP_Parser\get_wp_files()
. For example,I use this plugin to produce developer documentation for plugins/themes I create for clients, and currently hook into
wp_parser_pre_import_file
to skip importing anything intests/
orvendor/
sub-dirs of a plugin/theme. Having the proposedwp_parser_pre_get_wp_file
hook would allow avoiding the overhead of parsing all those files, only to skip them later in the pipeline.Here is an example of a func I would hook into the proposed filter, to show why the proposed filter takes the additional
$directory
param thatwp_parser_pre_import_file
does not:The text was updated successfully, but these errors were encountered: