Skip to content

Commit f09da6b

Browse files
Merge pull request #147 from alleyinteractive/feature/TECH-195/alphabetize-site-health-panel
Sorts features in site health panel alphabetically
2 parents 1829d58 + 2488fd9 commit f09da6b

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/alley/wp/alleyvate/class-site-health-panel.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@ final class Site_Health_Panel implements Feature {
1818
*/
1919
public function boot(): void {
2020
add_filter( 'debug_information', [ $this, 'add_debug_panel' ], 0 );
21+
add_filter( 'debug_information', [ $this, 'sort_debug_panel_features' ], PHP_INT_MAX );
2122
}
2223

2324
/**
2425
* Add debug information for the feature.
2526
*
26-
* @param array<string, array{label: string, description: string, fields: array<int, mixed>}> $info Debug information.
27-
* @return array<string, array{label: string, description: string, fields: array<int, mixed>}> Debug information.
27+
* @param array<string, array{label: string, description: string, fields: array<int, array<string, mixed>>}> $info Debug information.
28+
* @return array<string, array{label: string, description: string, fields: array<int, array<string, mixed>>}> Debug information.
2829
*/
29-
public function add_debug_panel( $info ): array {
30-
if ( ! \is_array( $info ) ) {
31-
$info = [];
32-
}
33-
30+
public function add_debug_panel( array $info ): array {
3431
$info['wp-alleyvate'] = [
3532
'label' => __( 'Alleyvate', 'alley' ),
3633
'description' => __( 'Diagnostic information about the Alleyvate plugin and which features are enabled.', 'alley' ),
@@ -39,4 +36,35 @@ public function add_debug_panel( $info ): array {
3936

4037
return $info;
4138
}
39+
40+
/**
41+
* Sorts the Alleyvate features in the Site Health panel alphabetically.
42+
*
43+
* @param array<string, array{label: string, description: string, fields: array<int, array<string, mixed>>}> $info Debug information.
44+
* @return array<string, array{label: string, description: string, fields: array<int, array<string, mixed>>}> Debug information.
45+
*/
46+
public function sort_debug_panel_features( array $info ): array {
47+
$panel = 'wp-alleyvate';
48+
49+
$fields = $info[ $panel ]['fields'] ?? [];
50+
51+
uasort(
52+
$fields,
53+
/**
54+
* Sorts the fields alphabetically by their labels.
55+
*
56+
* @param array<string, mixed> $a
57+
* @param array<string, mixed> $b
58+
*/
59+
static function ( array $a, array $b ): int {
60+
$label_a = isset( $a['label'] ) && is_string( $a['label'] ) ? $a['label'] : '';
61+
$label_b = isset( $b['label'] ) && is_string( $b['label'] ) ? $b['label'] : '';
62+
return strnatcasecmp( $label_a, $label_b );
63+
}
64+
);
65+
66+
$info[ $panel ]['fields'] = $fields;
67+
68+
return $info;
69+
}
4270
}

0 commit comments

Comments
 (0)