PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / vendor-prefixed / src / Menu / TopLevelMenu.php

TopLevelMenu.php in YayMail – WooCommerce Email Customizer trunk, at vendor-prefixed/src/Menu/TopLevelMenu.php

67 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMailScoped\YayCommerce\AdminShell\Menu;
4
5 use YayMailScoped\YayCommerce\AdminShell\Support\AdminContext;
6 /**
7 * Registers the shared YayCommerce top-level admin menu.
8 *
9 * First-to-register-wins: uses $admin_page_hooks['yaycommerce'] guard so only
10 * ONE instance runs across all co-installed plugins. Ported from YayMail Pro
11 * RegisterMenu.php — cross-plugin class_exists() probes removed because
12 * LicenseRegistry now handles plugin discovery.
13 *
14 * Position 56 (after WooCommerce), capability manage_options, slug yaycommerce.
15 */
16 class TopLevelMenu
17 {
18 public static int $position = 56;
19 public static string $capability = 'manage_options';
20 public function init(): void
21 {
22 AdminContext::bind_menu([$this, 'register_menu'], 9);
23 }
24 /**
25 * Register top-level menu. Guard ensures only the first plugin wins.
26 */
27 public function register_menu(): void
28 {
29 global $admin_page_hooks;
30 // First-to-register-wins — if another plugin already registered the
31 // 'yaycommerce' top-level menu, skip. This replaces the old cross-plugin
32 // class_exists() probes that existed in RegisterMenu.php lines 88-105.
33 if (isset($admin_page_hooks['yaycommerce'])) {
34 return;
35 }
36 add_menu_page(
37 'yaycommerce',
38 'YayCommerce',
39 self::$capability,
40 'yaycommerce',
41 null,
42 // no callback — submenus render content
43 self::get_logo_url(),
44 self::$position
45 );
46 // Remove the auto-created "YayCommerce" submenu AFTER all submenus are registered.
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);
50 }
51 /**
52 * WP auto-creates a submenu matching the parent slug. Remove it late
53 * so it runs after all plugins have registered their submenus.
54 */
55 public static function remove_parent_submenu(): void
56 {
57 remove_submenu_page('yaycommerce', 'yaycommerce');
58 }
59 /**
60 * Inline base64 SVG logo — copied as-is from YayMail Pro RegisterMenu.php.
61 */
62 public static function get_logo_url(): string
63 {
64 return 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQ2LjI0NzYgNi40MDg5NkM0Ni4yNDc2IDkuOTQ4MTYgNDMuMzc3OCAxMi44MTc5IDM5LjgzODYgMTIuODE3OUMzNi4yOTk0IDEyLjgxNzkgMzMuNDI5NyA5Ljk0ODE2IDMzLjQyOTcgNi40MDg5NkMzMy40Mjk3IDIuODY5NzYgMzYuMjk4MSAwIDM5LjgzODYgMEM0My4zNzkxIDAgNDYuMjQ3NiAyLjg2OTc2IDQ2LjI0NzYgNi40MDg5NlpNMS4xNjQ3MSAyMi45OTI2Qy0wLjIxODk3MiAyMy4xMzIyIC0wLjQzNzg1MiAyNS4wNTg2IDAuODc5MjY4IDI1LjUwNEM5LjI1NDMxIDI4LjMzNjYgMjEuMzAwNCAzMC45OTUyIDI3LjI0OTggMzIuMjM0MkMyOS4yOTkxIDMyLjY2MDUgMzAuNjIzOSAzNC42NDgzIDMwLjI0MTIgMzYuNzA2NkMyOC41NDUyIDQ1LjgwNjEgMjUuMzc4NSA1NS41Mjc3IDIzLjM2ODkgNjIuMzM0N0MyMi45ODYyIDYzLjYzMTQgMjQuNTk5IDY0LjU3MjIgMjUuNTM4NSA2My42MDA2QzQ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