| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace YayMailScoped\YayCommerce\AdminShell\Menu; |
| 4 | 4 | |
| 5 | +use YayMailScoped\YayCommerce\AdminShell\Support\AdminContext; | |
| 5 | 6 | /** |
| 6 | 7 | * Registers the shared YayCommerce top-level admin menu. |
| 7 | 8 | * |
| 8 | 9 | * First-to-register-wins: uses $admin_page_hooks['yaycommerce'] guard so only |
| @@ -15,16 +16,16 @@ | ||
| 15 | 16 | class TopLevelMenu |
| 16 | 17 | { |
| 17 | 18 | public static int $position = 56; |
| 18 | 19 | public static string $capability = 'manage_options'; |
| 19 | - public function init() : void | |
| 20 | + public function init(): void | |
| 20 | 21 | { |
| 21 | - \add_action('admin_menu', [$this, 'register_menu'], 9); | |
| 22 | + AdminContext::bind_menu([$this, 'register_menu'], 9); | |
| 22 | 23 | } |
| 23 | 24 | /** |
| 24 | 25 | * Register top-level menu. Guard ensures only the first plugin wins. |
| 25 | 26 | */ |
| 26 | - public function register_menu() : void | |
| 27 | + public function register_menu(): void | |
| 27 | 28 | { |
| 28 | 29 | global $admin_page_hooks; |
| 29 | 30 | // First-to-register-wins — if another plugin already registered the |
| 30 | 31 | // 'yaycommerce' top-level menu, skip. This replaces the old cross-plugin |
| @@ -31,9 +32,9 @@ | ||
| 31 | 32 | // class_exists() probes that existed in RegisterMenu.php lines 88-105. |
| 32 | 33 | if (isset($admin_page_hooks['yaycommerce'])) { |
| 33 | 34 | return; |
| 34 | 35 | } |
| 35 | - \add_menu_page( | |
| 36 | + add_menu_page( | |
| 36 | 37 | 'yaycommerce', |
| 37 | 38 | 'YayCommerce', |
| 38 | 39 | self::$capability, |
| 39 | 40 | 'yaycommerce', |
| @@ -42,22 +43,24 @@ | ||
| 42 | 43 | self::get_logo_url(), |
| 43 | 44 | self::$position |
| 44 | 45 | ); |
| 45 | 46 | // Remove the auto-created "YayCommerce" submenu AFTER all submenus are registered. |
| 46 | - \add_action('admin_menu', [__CLASS__, 'remove_parent_submenu'], 999); | |
| 47 | + // This runs inside the firing menu hook, so the context is known — bind only | |
| 48 | + // to the current hook (admin_menu or network_admin_menu) rather than both. | |
| 49 | + add_action(AdminContext::hook(), [__CLASS__, 'remove_parent_submenu'], 999); | |
| 47 | 50 | } |
| 48 | 51 | /** |
| 49 | 52 | * WP auto-creates a submenu matching the parent slug. Remove it late |
| 50 | 53 | * so it runs after all plugins have registered their submenus. |
| 51 | 54 | */ |
| 52 | - public static function remove_parent_submenu() : void | |
| 55 | + public static function remove_parent_submenu(): void | |
| 53 | 56 | { |
| 54 | - \remove_submenu_page('yaycommerce', 'yaycommerce'); | |
| 57 | + remove_submenu_page('yaycommerce', 'yaycommerce'); | |
| 55 | 58 | } |
| 56 | 59 | /** |
| 57 | 60 | * Inline base64 SVG logo — copied as-is from YayMail Pro RegisterMenu.php. |
| 58 | 61 | */ |
| 59 | - public static function get_logo_url() : string | |
| 62 | + public static function get_logo_url(): string | |
| 60 | 63 | { |
| 61 | 64 | return 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQ2LjI0NzYgNi40MDg5NkM0Ni4yNDc2IDkuOTQ4MTYgNDMuMzc3OCAxMi44MTc5IDM5LjgzODYgMTIuODE3OUMzNi4yOTk0IDEyLjgxNzkgMzMuNDI5NyA5Ljk0ODE2IDMzLjQyOTcgNi40MDg5NkMzMy40Mjk3IDIuODY5NzYgMzYuMjk4MSAwIDM5LjgzODYgMEM0My4zNzkxIDAgNDYuMjQ3NiAyLjg2OTc2IDQ2LjI0NzYgNi40MDg5NlpNMS4xNjQ3MSAyMi45OTI2Qy0wLjIxODk3MiAyMy4xMzIyIC0wLjQzNzg1MiAyNS4wNTg2IDAuODc5MjY4IDI1LjUwNEM5LjI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