PluginProbe ʕ •ᴥ•ʔ
WP Chat App / trunk
WP Chat App vtrunk
3.8.1 3.8.2 trunk 2.6 3.4 3.4.1 3.4.2 3.4.4 3.4.5 3.4.6 3.5 3.6 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0
wp-whatsapp / vendor-prefixed / src / Menu / MenuSuppressor.php
wp-whatsapp / vendor-prefixed / src / Menu Last commit date
ExternalPluginMenuAdapter.php 4 months ago MenuSuppressor.php 4 months ago PagesRouter.php 4 months ago PluginSubmenu.php 3 months ago TopLevelMenu.php 4 months ago
MenuSuppressor.php
65 lines
1 <?php
2
3 namespace WhatsappScoped\YayCommerce\AdminShell\Menu;
4
5 /**
6 * Strategy (a) — removes legacy per-plugin top-level menu slugs before
7 * the shared YayCommerce menu is registered.
8 *
9 * NOTE: In practice, the real protection against duplicate top-level menus
10 * is the isset($admin_page_hooks['yaycommerce']) guard in TopLevelMenu.
11 * This class is a safety backstop for edge cases where other plugins register
12 * a top-level menu under a DIFFERENT slug that conflicts with our nav tree.
13 *
14 * The one known legacy slug is 'yaycommerce' itself — handled by TopLevelMenu's
15 * guard. The suppressor list here exists for future-proofing.
16 *
17 * Fallback path: if strategy (a) causes problems in Phase 02 pilot,
18 * disable this suppressor and coexist with legacy menus (strategy b).
19 * @internal
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 priority 5 (before standard priority 10).
41 */
42 public function init() : void
43 {
44 add_action('admin_menu', [$this, 'suppress_legacy_menus'], 5);
45 }
46 /**
47 * Remove any legacy top-level menus from the slug list.
48 */
49 public function suppress_legacy_menus() : void
50 {
51 foreach ($this->slugs_to_suppress as $slug) {
52 remove_menu_page($slug);
53 }
54 }
55 /**
56 * Return the list of slugs this suppressor will remove.
57 *
58 * @return string[]
59 */
60 public function get_slugs() : array
61 {
62 return $this->slugs_to_suppress;
63 }
64 }
65