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
ExternalPluginMenuAdapter.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WhatsappScoped\YayCommerce\AdminShell\Menu; |
| 4 | |
| 5 | use WhatsappScoped\YayCommerce\AdminShell\Pages\RecommendedPluginsPage; |
| 6 | \defined('ABSPATH') || exit; |
| 7 | /** |
| 8 | * Registers an "Other Plugins" submenu under an external plugin's own top-level menu. |
| 9 | * Used for plugins (e.g. whatsapp, filester) that own their own menu hierarchy |
| 10 | * and should NOT appear under the shared YayCommerce menu. |
| 11 | * @internal |
| 12 | */ |
| 13 | class ExternalPluginMenuAdapter |
| 14 | { |
| 15 | private string $parent_menu; |
| 16 | private string $menu_title; |
| 17 | private string $menu_capability; |
| 18 | private string $menu_slug; |
| 19 | public function __construct(array $config) |
| 20 | { |
| 21 | $this->parent_menu = $config['parent_menu'] ?? ''; |
| 22 | $this->menu_title = 'Recommended Plugins'; |
| 23 | $this->menu_capability = $config['menu_capability'] ?? 'manage_options'; |
| 24 | $this->menu_slug = $config['menu_slug'] ?? ''; |
| 25 | } |
| 26 | public function init() : void |
| 27 | { |
| 28 | RecommendedPluginsPage::get_instance(); |
| 29 | if (!\is_admin()) { |
| 30 | return; |
| 31 | } |
| 32 | add_action('admin_menu', [$this, 'register_other_plugins_submenu'], 20); |
| 33 | } |
| 34 | public function register_other_plugins_submenu() : void |
| 35 | { |
| 36 | $page_id = add_submenu_page($this->parent_menu, $this->menu_title, $this->menu_title, $this->menu_capability, $this->menu_slug, [RecommendedPluginsPage::class, 'render']); |
| 37 | add_action('load-' . $page_id, function () { |
| 38 | RecommendedPluginsPage::load_data(); |
| 39 | }); |
| 40 | } |
| 41 | } |
| 42 |