plugin = $plugin; $this->html = $html; $this->acf = $acf; $this->options = $options; $this->demoImport = $demoImport; } protected function getUrl(string $page = ''): string { $pageArg = $page ? '&page=' . $page : ''; return sprintf('/wp-admin/edit.php?post_type=%s%s', AcfViews::NAME, $pageArg); } 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/UaxdVYupmok'; } protected function getPages(): array { return [ [ 'isLeftBlock' => true, 'url' => $this->getUrl(), 'label' => 'ACF Views', 'isActive' => false, ], [ 'isLeftBlock' => true, 'url' => sprintf('/wp-admin/edit.php?post_type=%s', AcfCards::NAME), 'label' => 'ACF Cards', 'isActive' => false, ], [ 'isLeftBlock' => true, 'url' => $this->getUrl(self::PAGE_OVERVIEW), 'label' => 'Overview', 'isActive' => false, ], [ 'isRightBlock' => true, 'url' => $this->getUrl(self::PAGE_DEMO_IMPORT), 'label' => 'Demo Import', 'isActive' => false, ], [ 'isRightBlock' => true, 'url' => Plugin::DOCS_URL, 'isBlank' => true, 'label' => 'Docs', 'isActive' => false, ], [ 'isRightBlock' => true, 'url' => Plugin::VIDEO_TUTORIALS_URL, 'isBlank' => true, 'label' => 'Video tutorials', 'isActive' => false, ], ]; } 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) || ! in_array($screen->post_type, [AcfViews::NAME, AcfCards::NAME,])) { return; } add_action('in_admin_header', [$this, 'getHeader']); }); add_filter("plugin_action_links_{$pluginSlug}", [$this, 'addUpgradeToProLink']); // Overview should be later than the Pro link add_filter("plugin_action_links_{$pluginSlug}", [$this, 'addOverviewLink']); add_action('admin_menu', [$this, 'removeImportSubmenuLink']); } public function addPages(): void { add_submenu_page( sprintf('edit.php?post_type=%s', AcfViews::NAME), 'Overview', 'Overview', 'edit_posts', self::PAGE_OVERVIEW, [$this, 'getOverviewPage'] ); add_submenu_page( sprintf('edit.php?post_type=%s', AcfViews::NAME), 'Demo import', 'Demo import', 'edit_posts', self::PAGE_DEMO_IMPORT, [$this, 'getImportPage'] ); } public function getHeader(): void { $tabs = $this->getPages(); $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(): void { $createAcfViewLink = sprintf('/wp-admin/post-new.php?post_type=%s', AcfViews::NAME); $createAcfCardLink = sprintf('/wp-admin/post-new.php?post_type=%s', AcfCards::NAME); echo $this->html->dashboardOverview( $createAcfViewLink, $createAcfCardLink, $this->acf->getGroupedFieldTypes(), [], [], $this->plugin->getVersion(), $this->getUrl(self::PAGE_DEMO_IMPORT), $this->getVideoReview(), $this->getProBanner() ); } public function getImportPage(): void { $isWithDeleteButton = false; $formMessage = ''; if ($this->demoImport->isProcessed()) { if (! $this->demoImport->isHasError()) { $formMessage .= $this->demoImport->isImportRequest() ? '

Import was successful. You’re all set!

' : '

All demo objects have been deleted.

'; } else { $formMessage .= '

Request is failed.



' . $this->demoImport->getError(); } } else { $this->demoImport->readIDs(); } if ($this->demoImport->isHasData() && ! $this->demoImport->isHasError()) { $isWithDeleteButton = true; $formMessage .= '

Imported items

'; $formMessage .= '

Display page\'s ACF fields on the same page

'; $formMessage .= sprintf( '"Samsung Galaxy A53" Page

', $this->demoImport->getSamsungLink() ); $formMessage .= sprintf( '"Nokia X20" Page

', $this->demoImport->getNokiaLink() ); $formMessage .= sprintf( '"Xiaomi 12T" Page

', $this->demoImport->getXiaomiLink() ); $formMessage .= sprintf( '"Phone" Field Group

', $this->demoImport->getAcfGroupLink() ); $formMessage .= sprintf( '"Phone" ACF View

', $this->demoImport->getPhoneAcfViewLink() ); $formMessage .= '

Display a specific post, page or CPT item with its fields

'; $formMessage .= sprintf( '"Article about Samsung" page

', $this->demoImport->getSamsungArticleLink() ); $formMessage .= '

Display specific posts, pages or CPT items and their fields by using filters
or by manually assigning items

'; $formMessage .= sprintf( '"Phones" ACF Card

', $this->demoImport->getPhonesAcfCardLink() ); $formMessage .= sprintf( '"Most popular phones in 2022" page

', $this->demoImport->getPhonesArticleLink() ); } $formNonce = wp_create_nonce('_av-demo-import'); echo $this->html->dashboardImport($isWithDeleteButton, $formNonce, $formMessage); } public function addOverviewLink(array $links): array { $settings_link = sprintf( 'Overview', $this->getUrl(self::PAGE_OVERVIEW) ); array_unshift($links, $settings_link); return $links; } public function addUpgradeToProLink(array $links): array { $settings_link = sprintf( 'Get Pro', Plugin::PRO_VERSION_URL ); array_unshift($links, $settings_link); return $links; } public function removeImportSubmenuLink(): void { $url = sprintf('edit.php?post_type=%s', AcfViews::NAME); global $submenu; if (! $submenu[$url]) { $submenu[$url] = []; } foreach ($submenu[$url] as $itemKey => $item) { if (4 !== count($item) || $item[2] !== self::PAGE_DEMO_IMPORT) { continue; } unset($submenu[$url][$itemKey]); break; } } }