| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMailScoped\YayCommerce\AdminShell\Menu; |
| 4 |
|
| 5 |
use YayMailScoped\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 |
*/ |
| 12 |
class ExternalPluginMenuAdapter |
| 13 |
{ |
| 14 |
private string $parent_menu; |
| 15 |
private string $menu_title; |
| 16 |
private string $menu_capability; |
| 17 |
private string $menu_slug; |
| 18 |
public function __construct(array $config) |
| 19 |
{ |
| 20 |
$this->parent_menu = $config['parent_menu'] ?? ''; |
| 21 |
$this->menu_title = 'Recommended Plugins'; |
| 22 |
$this->menu_capability = $config['menu_capability'] ?? 'manage_options'; |
| 23 |
$this->menu_slug = $config['menu_slug'] ?? ''; |
| 24 |
} |
| 25 |
public function init(): void |
| 26 |
{ |
| 27 |
RecommendedPluginsPage::get_instance(); |
| 28 |
if (!is_admin()) { |
| 29 |
return; |
| 30 |
} |
| 31 |
add_action('admin_menu', [$this, 'register_other_plugins_submenu'], 20); |
| 32 |
} |
| 33 |
public function register_other_plugins_submenu(): void |
| 34 |
{ |
| 35 |
$page_id = add_submenu_page($this->parent_menu, $this->menu_title, $this->menu_title, $this->menu_capability, $this->menu_slug, [RecommendedPluginsPage::class, 'render']); |
| 36 |
add_action('load-' . $page_id, function () { |
| 37 |
RecommendedPluginsPage::load_data(); |
| 38 |
}); |
| 39 |
} |
| 40 |
} |
| 41 |
|