Skip to content

Commit 9ecb11a

Browse files
Iterate modules folder using slugs from perflab_get_focus_areas
1 parent 448426b commit 9ecb11a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

‎admin/load.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,9 @@ function perflab_get_modules( $modules_root = null ) {
202202

203203
// Modules are organized as {focus}/{module-slug} in the modules folder.
204204
if ( $modules_dir ) {
205-
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
206-
while ( ( $focus = readdir( $modules_dir ) ) !== false ) {
207-
if ( '.' === substr( $focus, 0, 1 ) ) {
208-
continue;
209-
}
205+
// Load modules from each focus area folder.
206+
$focus_areas = perflab_get_focus_areas();
207+
foreach ( array_keys( $focus_areas ) as $focus ) {
210208

211209
// Each focus area must be a directory.
212210
if ( ! is_dir( $modules_root . '/' . $focus ) ) {
@@ -215,6 +213,7 @@ function perflab_get_modules( $modules_root = null ) {
215213

216214
$focus_dir = @opendir( $modules_root . '/' . $focus );
217215
if ( $focus_dir ) {
216+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
218217
while ( ( $file = readdir( $focus_dir ) ) !== false ) {
219218
// Unlike plugins, modules must be in a directory.
220219
if ( ! is_dir( $modules_root . '/' . $focus . '/' . $file ) ) {
@@ -244,8 +243,6 @@ function perflab_get_modules( $modules_root = null ) {
244243
closedir( $focus_dir );
245244
}
246245
}
247-
248-
closedir( $modules_dir );
249246
}
250247

251248
foreach ( $module_files as $module_file ) {
@@ -286,7 +283,6 @@ function perflab_get_module_data( $module_file ) {
286283
$default_headers = array(
287284
'name' => 'Module Name',
288285
'description' => 'Description',
289-
'focus' => 'Focus',
290286
'experimental' => 'Experimental',
291287
);
292288

@@ -304,5 +300,11 @@ function perflab_get_module_data( $module_file ) {
304300
$module_data['experimental'] = false;
305301
}
306302

303+
// Extract the module focus from its filename.
304+
preg_match( '/.*\/modules\/([^\/]*)\/.*/', $module_file, $matches );
305+
if (isset( $matches[1] ) ) {
306+
$module_data['focus'] = $matches[1];
307+
}
308+
307309
return $module_data;
308310
}

0 commit comments

Comments
 (0)