| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\Handlers; |
| 4 |
|
| 5 |
use FluentCart\App\Services\URL; |
| 6 |
use FluentCart\App\Vite; |
| 7 |
use FluentCart\Api\StoreSettings; |
| 8 |
use FluentCart\App\Services\Permission\PermissionManager; |
| 9 |
|
| 10 |
class AdminMenuBarHandler |
| 11 |
{ |
| 12 |
|
| 13 |
public function register() |
| 14 |
{ |
| 15 |
add_action('admin_bar_menu', [$this, 'init'], 100); |
| 16 |
} |
| 17 |
|
| 18 |
public function init($wp_admin_bar) |
| 19 |
{ |
| 20 |
$isSuperAdmin = PermissionManager::userCan('is_super_admin'); |
| 21 |
if (!$isSuperAdmin) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$storeSettings = new StoreSettings(); |
| 26 |
$id = 'fluent_cart_live_mode'; |
| 27 |
$menuTitle = __('Live Mode', 'fluent-cart'); |
| 28 |
$color = 'color: #189877;'; |
| 29 |
|
| 30 |
if ($storeSettings->get('order_mode') === 'test') { |
| 31 |
$id = 'fluent_cart_test_mode'; |
| 32 |
$menuTitle = __('Test Mode', 'fluent-cart'); |
| 33 |
$color = 'color: #F58E07;'; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
$logo = Vite::getAssetUrl('images/logo/logo-white.svg'); |
| 38 |
$title = '<div style="display: inline-flex;align-items: center;' . esc_attr($color) . '"><img src="' . esc_url($logo ?? '') . '" alt="Logo" style="width:20px; height:16px; vertical-align:middle; margin-right:6px;">' . $menuTitle . '</div>'; |
| 39 |
|
| 40 |
|
| 41 |
// Parent node (with class) |
| 42 |
|
| 43 |
|
| 44 |
$wp_admin_bar->add_node([ |
| 45 |
'id' => $id, |
| 46 |
'title' => $title, |
| 47 |
'href' => false, // disables direct link to act as dropdown |
| 48 |
'meta' => [ |
| 49 |
'class' => $id, |
| 50 |
'title' => __('FluentCart', 'fluent-cart') |
| 51 |
] |
| 52 |
]); |
| 53 |
|
| 54 |
// Child: Store Settings |
| 55 |
$wp_admin_bar->add_node([ |
| 56 |
'id' => $id . '_orders', |
| 57 |
'title' => __('View Orders', 'fluent-cart'), |
| 58 |
'href' => URL::getDashboardUrl('orders'), |
| 59 |
'parent' => $id |
| 60 |
]); |
| 61 |
|
| 62 |
$wp_admin_bar->add_node([ |
| 63 |
'id' => $id . '_products', |
| 64 |
'title' => __('View Products', 'fluent-cart'), |
| 65 |
'href' => URL::getDashboardUrl('products'), |
| 66 |
'parent' => $id |
| 67 |
]); |
| 68 |
|
| 69 |
$wp_admin_bar->add_node([ |
| 70 |
'id' => $id . '_settings', |
| 71 |
'title' => __('Store Settings', 'fluent-cart'), |
| 72 |
'href' => URL::getDashboardUrl('settings/store-settings/'), |
| 73 |
'parent' => $id |
| 74 |
]); |
| 75 |
|
| 76 |
// Child: View Orders |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
|