plugin = $plugin; $this->html = $html; $this->acf = $acf; $this->options = $options; } private function getUrl(string $page = ''): string { $pageArg = $page ? '&page=' . $page : ''; return sprintf('/wp-admin/edit.php?post_type=%s%s', CPT::NAME, $pageArg); } protected function getProBanner(): array { return $this->html->getProBanner(Plugin::PRO_MAIL_TO, $this->plugin->getAssetsUrl('pro.png')); } public function setHooks(): void { $pluginSlug = $this->plugin->getSlug(); add_action('admin_menu', [$this, 'addPages']); add_action('current_screen', function (WP_Screen $screen) { if (! isset($screen->post_type) || CPT::NAME !== $screen->post_type) { return; } add_action('in_admin_header', [$this, 'getHeader']); }); add_filter("plugin_action_links_{$pluginSlug}", [$this, 'addOverviewLink']); register_activation_hook($pluginSlug, function () { $this->options->updateOption(Options::IS_JUST_ACTIVATED, true, true); }); add_action('admin_init', [$this, 'redirectToOverviewAfterActivation']); } public function addPages(): void { add_submenu_page( sprintf('edit.php?post_type=%s', CPT::NAME), 'Overview', 'Overview', 'edit_posts', self::PAGE_OVERVIEW, [$this, 'getOverviewPage'] ); // todo /*add_submenu_page( sprintf('edit.php?post_type=%s', CPT::NAME), 'Demo import', 'Demo import', 'edit_posts', self::PAGE_DEMO_IMPORT, [$this, 'getImportPage'] );*/ } public function getHeader(): void { $tabs = [ [ 'isActive' => false, 'url' => $this->getUrl(), 'label' => 'ACF Views', ], [ 'isActive' => false, 'url' => $this->getUrl(self::PAGE_OVERVIEW), 'label' => 'Overview', ], /*[ 'isActive' => false, 'url' => $this->getUrl(self::PAGE_DEMO_IMPORT), 'label' => 'Demo Import', ],*/ ]; $currentUrl = add_query_arg(null, null); foreach ($tabs as &$tab) { if ($currentUrl !== $tab['url']) { continue; } $tab['isActive'] = true; break; } echo $this->html->dashboardHeader($this->plugin->getName(), $tabs); } public function getOverviewPage($isWith): void { $createAcfViewLink = sprintf('/wp-admin/post-new.php?post_type=%s', CPT::NAME); echo $this->html->dashboardOverview( $createAcfViewLink, $this->acf->getGroupedFieldTypes(), [], [], $this->plugin->getVersion(), $this->getProBanner() ); } public function getImportPage(): void { echo 'test'; } public function addOverviewLink(array $links): array { $settings_link = sprintf( 'Overview', $this->getUrl(self::PAGE_OVERVIEW) ); array_unshift($links, $settings_link); return $links; } public function redirectToOverviewAfterActivation(): void { if (! $this->options->getOption(Options::IS_JUST_ACTIVATED)) { return; } $this->options->deleteOption(Options::IS_JUST_ACTIVATED); wp_redirect($this->getUrl(self::PAGE_OVERVIEW)); exit; } }