Skip to content

Commit 0ca2f57

Browse files
committed
Add adminBarMenuItems option
- Add a new "adminBarMenuItems" option. This is a JSON object that defines the menu items to display in the admin bar.
1 parent 48dc7ca commit 0ca2f57

4 files changed

Lines changed: 59 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
- Fix an error when applying an option's default blob_value.
55
- Fix a missing import on the logs-page that was breaking the
66
"Delete Logs" button.
7+
- Add an "object" option type.
8+
This is used for the new "adminBarMenuItems" option.
9+
- Add a new "adminBarMenuItems" option.
10+
This is a JSON object that defines the menu items to display in the
11+
admin bar.
712

813
## Static Deploy 9.0.1 (2025-07-16)
914

src/AdminBar.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,27 @@ public static function adminBarMenuHook( \WP_Admin_Bar $wp_admin_bar ): void {
4646
];
4747
$wp_admin_bar->add_node( $node );
4848

49-
$node = [
50-
'id' => 'static-deploy-github',
51-
'parent' => 'static-deploy-status',
52-
'title' => '<a href="https://github.com/staticweb-io/static-deploy" ' .
53-
' target="_blank">GitHub</a>',
54-
];
55-
$wp_admin_bar->add_node( $node );
56-
57-
$node = [
58-
'id' => 'static-deploy-news',
59-
'parent' => 'static-deploy-status',
60-
'title' => '<a href="https://staticweb.io/news/" target="_blank">News</a>',
61-
];
62-
$wp_admin_bar->add_node( $node );
49+
$menu_items = Options::getBlobValue( 'adminBarMenuItems' );
50+
$menu_items = (array) json_decode( $menu_items );
51+
52+
// Sort alphabetically by label
53+
uasort(
54+
$menu_items,
55+
function ( $a, $b ) {
56+
return strcmp( $a->label, $b->label );
57+
}
58+
);
6359

64-
$node = [
65-
'id' => 'static-deploy-platform',
66-
'parent' => 'static-deploy-status',
67-
'title' => '<a href="https://staticweb.io/platform/" target="_blank">Platform</a>',
68-
];
69-
$wp_admin_bar->add_node( $node );
60+
foreach ( $menu_items as $id => $item ) {
61+
$label = sanitize_text_field( $item->label );
62+
$href = esc_url( $item->href );
63+
$node = [
64+
'id' => $id,
65+
'parent' => 'static-deploy-status',
66+
'title' => '<a href="' . $href . '" target="_blank">' . $label . '</a>',
67+
];
68+
$wp_admin_bar->add_node( $node );
69+
}
7070
}
7171

7272
public static function afterAdminBarRender(): void {

src/Options.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,30 @@ public static function optionSpecs(): array {
5656
return self::$cached_option_specs;
5757
}
5858

59+
$default_admin_bar_menu_items = [
60+
'static-deploy-github' => [
61+
'href' => 'https://github.com/staticweb-io/static-deploy',
62+
'label' => 'GitHub',
63+
],
64+
'static-deploy-news' => [
65+
'href' => 'https://staticweb.io/news/',
66+
'label' => 'News',
67+
],
68+
'static-deploy-platform' => [
69+
'href' => 'https://staticweb.io/platform/',
70+
'label' => 'Platform',
71+
],
72+
];
73+
5974
$specs = [
75+
new OptionSpec(
76+
'object',
77+
'adminBarMenuItems',
78+
'1',
79+
'Admin Bar Menu Items',
80+
'',
81+
json_encode( $default_admin_bar_menu_items ),
82+
),
6083
new OptionSpec(
6184
'boolean',
6285
'detectCustomPostTypes',
@@ -730,6 +753,7 @@ public static function savePosted( string $screen = 'core' ): void {
730753
break;
731754
case 'advanced':
732755
$names = [
756+
'adminBarMenuItems',
733757
'crawlConcurrency',
734758
'crawledSitePath',
735759
'debugLogging',

views/advanced-options-page.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474

7575
<p/>
7676

77+
<h2>UI Options</h2>
78+
79+
<table class="widefat striped">
80+
<tbody>
81+
<?php echo $row( 'adminBarMenuItems' ); ?>
82+
</tbody>
83+
</table>
84+
85+
<p/>
86+
7787
<?php wp_nonce_field( strval( $view['nonce_action'] ) ); ?>
7888
<input name="action" type="hidden" value="<?php echo Controller::getHookName( 'ui_save_advanced_options' ); ?>" />
7989

0 commit comments

Comments
 (0)