Asset
1 month ago
Banner
1 month ago
Colors
1 month ago
MenuGroupFactory
1 month ago
MenuPageFactory
1 month ago
Notice
1 month ago
Page
1 month ago
PageFactory
1 month ago
Preference
1 month ago
Type
1 month ago
View
1 month ago
Admin.php
1 month ago
AdminLoader.php
1 month ago
AdminNetwork.php
1 month ago
AdminScripts.php
1 month ago
HelpTab.php
1 month ago
Helpable.php
1 month ago
Menu.php
1 month ago
MenuFactory.php
1 month ago
MenuFactoryInterface.php
1 month ago
MenuGroupFactory.php
1 month ago
MenuListFactory.php
1 month ago
MenuListItems.php
1 month ago
MenuPageFactory.php
1 month ago
PageFactoryInterface.php
1 month ago
PageNetworkRequestHandler.php
1 month ago
PageNetworkRequestHandlers.php
1 month ago
PageRequestHandler.php
1 month ago
PageRequestHandlers.php
1 month ago
RenderableHead.php
1 month ago
RequestHandlerInterface.php
1 month ago
ScreenOption.php
1 month ago
ScreenOptions.php
1 month ago
Scripts.php
1 month ago
Tooltip.php
1 month ago
UninitializedScreens.php
1 month ago
MenuFactory.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Admin; |
| 4 | |
| 5 | use AC\Admin\Type\MenuItem; |
| 6 | use AC\AdminColumns; |
| 7 | use AC\Asset\Location; |
| 8 | use AC\Deprecated\Hooks; |
| 9 | use AC\Type\Url\Site; |
| 10 | use AC\Type\Url\UtmTags; |
| 11 | |
| 12 | class MenuFactory implements MenuFactoryInterface |
| 13 | { |
| 14 | |
| 15 | protected string $url; |
| 16 | |
| 17 | protected Location $location; |
| 18 | |
| 19 | private Hooks $hooks; |
| 20 | |
| 21 | public function __construct(string $url, AdminColumns $plugin, Hooks $hooks) |
| 22 | { |
| 23 | $this->url = $url; |
| 24 | $this->location = $plugin->get_location(); |
| 25 | $this->hooks = $hooks; |
| 26 | } |
| 27 | |
| 28 | protected function create_menu_link(string $slug): string |
| 29 | { |
| 30 | return add_query_arg( |
| 31 | [ |
| 32 | RequestHandlerInterface::PARAM_PAGE => Admin::NAME, |
| 33 | RequestHandlerInterface::PARAM_TAB => $slug, |
| 34 | ], |
| 35 | $this->url |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | public function create(string $current): Menu |
| 40 | { |
| 41 | $menu = new Menu(); |
| 42 | |
| 43 | $items = [ |
| 44 | Page\Columns::NAME => __('Columns', 'codepress-admin-columns'), |
| 45 | Page\Settings::NAME => __('Settings', 'codepress-admin-columns'), |
| 46 | Page\Addons::NAME => __('Add-ons', 'codepress-admin-columns'), |
| 47 | ]; |
| 48 | |
| 49 | $hook_count = $this->hooks->get_count(); |
| 50 | |
| 51 | if ($hook_count > 0) { |
| 52 | $menu->add_item( |
| 53 | new MenuItem( |
| 54 | Page\Help::NAME, |
| 55 | $this->create_menu_link(Page\Help::NAME), |
| 56 | sprintf( |
| 57 | '%s %s', |
| 58 | __('Help', 'codepress-admin-columns'), |
| 59 | '<span class="ac-badge">' . $hook_count . '</span>' |
| 60 | ), |
| 61 | sprintf('-%s %s', Page\Help::NAME, $current === Page\Help::NAME ? '-active' : ''), |
| 62 | '', |
| 63 | 20 |
| 64 | ) |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | foreach ($items as $slug => $label) { |
| 69 | $menu->add_item( |
| 70 | new MenuItem( |
| 71 | $slug, |
| 72 | $this->create_menu_link($slug), |
| 73 | $label, |
| 74 | sprintf('-%s %s', $slug, $current === $slug ? '-active' : '') |
| 75 | ) |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | $url = (new UtmTags(Site::create_admin_columns_pro(), 'upgrade'))->get_url(); |
| 80 | |
| 81 | $menu->add_item( |
| 82 | new MenuItem( |
| 83 | 'pro', |
| 84 | $url, |
| 85 | sprintf('%s %s', 'Upgrade to Pro', '<span class="dashicons dashicons-external"></span>'), |
| 86 | '-pro', |
| 87 | '_blank', |
| 88 | 30 |
| 89 | ), |
| 90 | ); |
| 91 | |
| 92 | do_action('ac/admin/page/menu', $menu); |
| 93 | |
| 94 | return $menu; |
| 95 | } |
| 96 | |
| 97 | } |