plugin = $plugin; $this->html = $html; $this->demoImport = $demoImport; $this->acfIntegration = $acfIntegration; } protected function getProBanner(): array { return $this->html->getProBanner(Plugin::PRO_VERSION_URL, $this->plugin->getAssetsUrl('pro.png')); } protected function getVideoReview(): string { return 'https://www.youtube.com/embed/0Vv23bmYzzo'; } protected function getPages(): array { return [ [ 'isLeftBlock' => true, 'url' => $this->plugin->getAdminUrl(), 'label' => __('Views', 'acf-views'), 'isActive' => false, 'isSecondary' => false, ], [ 'isLeftBlock' => true, 'url' => $this->plugin->getAdminUrl('', CardsCpt::NAME), 'label' => __('Cards', 'acf-views'), 'isActive' => false, 'isSecondary' => false, ], [ 'isLeftBlock' => true, 'url' => $this->plugin->getAdminUrl(SettingsPage::SLUG), 'label' => __('Settings', 'acf-views'), 'isActive' => false, 'isSecondary' => false, ], [ 'isLeftBlock' => true, 'url' => $this->plugin->getAdminUrl(Tools::SLUG), 'label' => __('Tools', 'acf-views'), 'isActive' => false, 'isSecondary' => false, ], [ 'isLeftBlock' => true, 'url' => Plugin::PRO_VERSION_URL, 'isBlank' => true, 'label' => __('Get PRO', 'acf-views'), 'isActive' => false, 'icon' => '', 'isSecondary' => false, ], [ 'isRightBlock' => true, 'url' => $this->plugin->getAdminUrl(self::PAGE_DEMO_IMPORT), 'label' => __('Demo Import', 'acf-views'), 'isActive' => false, 'isSecondary' => true, ], [ 'isRightBlock' => true, 'url' => $this->plugin->getAdminUrl(self::PAGE_DOCS), 'label' => __('Docs', 'acf-views'), 'isActive' => false, 'isSecondary' => false, ], [ 'isRightBlock' => true, // static to be overridden in child 'url' => static::URL_SUPPORT, 'label' => __('Support', 'acf-views'), 'isActive' => false, 'isSecondary' => false, 'icon' => '', 'isBlank' => true, ], ]; } protected function getCurrentAdminUrl(): string { $uri = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : ''; $uri = preg_replace('|^.*/wp-admin/|i', '', $uri); if (!$uri) { return ''; } return admin_url($uri); } protected function getPlugin(): Plugin { return $this->plugin; } public function addPages(): void { add_submenu_page( sprintf('edit.php?post_type=%s', ViewsCpt::NAME), __('Demo import', 'acf-views'), __('Demo import', 'acf-views'), 'edit_posts', self::PAGE_DEMO_IMPORT, [$this, 'getImportPage'] ); add_submenu_page( sprintf('edit.php?post_type=%s', ViewsCpt::NAME), __('Docs', 'acf-views'), __('Docs', 'acf-views'), 'edit_posts', self::PAGE_DOCS, function () { printf( '', Plugin::DOCS_URL ); } ); add_submenu_page( sprintf('edit.php?post_type=%s', ViewsCpt::NAME), __('Survey', 'acf-views'), __('Survey', 'acf-views'), 'edit_posts', self::PAGE_SURVEY, function () { printf( '', Plugin::SURVEY_URL ); } ); } public function getHeader(): void { $tabs = $this->getPages(); $currentUrl = $this->getCurrentAdminUrl(); $acfViewsListUrl = $this->plugin->getAdminUrl(); $acfCardsListUrl = $this->plugin->getAdminUrl('', CardsCpt::NAME); $currentScreen = get_current_screen(); $isEditScreen = $currentScreen && 'post' === $currentScreen->base && !$currentScreen->action; $isAddScreen = $currentScreen && 'post' === $currentScreen->base && 'add' === $currentScreen->action; $isActiveChild = ($isEditScreen || $isAddScreen); $isActiveAcfViewsChild = $isActiveChild && $currentScreen && $currentScreen->post_type === ViewsCpt::NAME; $isActiveAcfCardsChild = $isActiveChild && $currentScreen && $currentScreen->post_type === CardsCpt::NAME; foreach ($tabs as &$tab) { $isAcfViewsListPage = $tab['url'] === $acfViewsListUrl; $isAcfCardsListPage = $tab['url'] === $acfCardsListUrl; $isActiveChild = $isAcfViewsListPage && $isActiveAcfViewsChild; $isActiveChild = $isActiveChild || ($isAcfCardsListPage && $isActiveAcfCardsChild); if ($currentUrl !== $tab['url'] && !$isActiveChild) { continue; } $tab['isActive'] = true; break; } echo $this->html->dashboardHeader($this->plugin->getName(), $this->plugin->getVersion(), $tabs); } public function getImportPage(): void { $isWithDeleteButton = false; $formMessage = ''; if ($this->demoImport->isProcessed()) { if (!$this->demoImport->isHasError()) { $message = $this->demoImport->isImportRequest() ? __("Import was successful. You’re all set!", 'acf-views') : __('All demo objects have been deleted.', 'acf-views'); $formMessage .= sprintf('
%s
', $message); } else { $message = __('Request is failed.', 'acf-views'); $formMessage .= sprintf( '%s
%s
', __('Imported items', 'acf-views') ); $formMessage .= sprintf( '%s
', __("Display page's ACF fields on the same page", 'acf-views') ); $formMessage .= sprintf( '%s%s
', __('Display a specific post, page or CPT item with its fields', 'acf-views') ); $formMessage .= sprintf( '%s%s
%s