PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.5
YayMail – WooCommerce Email Customizer v4.4.5
4.4.6 4.4.5 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 All 57 releases
yaymail / vendor-prefixed / src / Menu / MenuSuppressor.php

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

66 lines 2.1 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 * Strategy (a) — removes legacy per-plugin top-level menu slugs before
8 * the shared YayCommerce menu is registered.
9 *
10 * NOTE: In practice, the real protection against duplicate top-level menus
11 * is the isset($admin_page_hooks['yaycommerce']) guard in TopLevelMenu.
12 * This class is a safety backstop for edge cases where other plugins register
13 * a top-level menu under a DIFFERENT slug that conflicts with our nav tree.
14 *
15 * The one known legacy slug is 'yaycommerce' itself — handled by TopLevelMenu's
16 * guard. The suppressor list here exists for future-proofing.
17 *
18 * Fallback path: if strategy (a) causes problems in Phase 02 pilot,
19 * disable this suppressor and coexist with legacy menus (strategy b).
20 */
21 class MenuSuppressor
22 {
23 /**
24 * Known legacy top-level menu slugs that should be suppressed.
25 * Add slugs here if future plugins register conflicting top-level menus.
26 *
27 * @var string[]
28 */
29 private array $slugs_to_suppress;
30 /**
31 * @param string[]|null $slugs Override the default list (mainly for testing).
32 */
33 public function __construct(?array $slugs = null)
34 {
35 // Default: empty — the 'yaycommerce' slug is already handled by
36 // TopLevelMenu's first-to-register guard. Keep this list explicit.
37 $this->slugs_to_suppress = $slugs ?? [];
38 }
39 /**
40 * Register hooks. Runs on admin_menu / network_admin_menu priority 5
41 * (before standard priority 10).
42 */
43 public function init(): void
44 {
45 AdminContext::bind_menu([$this, 'suppress_legacy_menus'], 5);
46 }
47 /**
48 * Remove any legacy top-level menus from the slug list.
49 */
50 public function suppress_legacy_menus(): void
51 {
52 foreach ($this->slugs_to_suppress as $slug) {
53 remove_menu_page($slug);
54 }
55 }
56 /**
57 * Return the list of slugs this suppressor will remove.
58 *
59 * @return string[]
60 */
61 public function get_slugs(): array
62 {
63 return $this->slugs_to_suppress;
64 }
65 }
66