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