pages = array( 'dashboard' => new Dashboard(), 'analytics' => new AnalyticsPage(), 'tools' => new Tools(), 'settings' => new Settings(), ); // Settings needs its own admin_init + action links regardless of menu. $this->pages['settings']->register_setting_only(); add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_filter( 'parent_file', array( $this, 'highlight_parent' ) ); add_filter( 'submenu_file', array( $this, 'highlight_submenu' ) ); } /** * Keep the Accordion FAQ menu open on FAQ post/taxonomy screens. * * @param string $parent_file Parent file. * @return string */ public function highlight_parent( $parent_file ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen && \AccordionFaq\Setup\PostType::POST_TYPE === $screen->post_type ) { return self::SLUG; } return $parent_file; } /** * Highlight the correct submenu item on FAQ screens. * * @param string|null $submenu_file Submenu file. * @return string|null */ public function highlight_submenu( $submenu_file ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || \AccordionFaq\Setup\PostType::POST_TYPE !== $screen->post_type ) { return $submenu_file; } if ( \AccordionFaq\Setup\Taxonomy::TAXONOMY === $screen->taxonomy ) { return 'edit-tags.php?taxonomy=' . \AccordionFaq\Setup\Taxonomy::TAXONOMY . '&post_type=' . \AccordionFaq\Setup\PostType::POST_TYPE; } if ( 'post' === $screen->base && 'add' === $screen->action ) { return 'post-new.php?post_type=' . \AccordionFaq\Setup\PostType::POST_TYPE; } return 'edit.php?post_type=' . \AccordionFaq\Setup\PostType::POST_TYPE; } /** * Build the menu. * * @return void */ public function add_menu() { add_menu_page( __( 'Accordion FAQ', 'accordion-faq-plugin' ), __( 'Accordion FAQ', 'accordion-faq-plugin' ), 'edit_posts', self::SLUG, array( $this->pages['dashboard'], 'render' ), 'dashicons-editor-help', 25 ); add_submenu_page( self::SLUG, __( 'Dashboard', 'accordion-faq-plugin' ), __( 'Dashboard', 'accordion-faq-plugin' ), 'edit_posts', self::SLUG, array( $this->pages['dashboard'], 'render' ) ); // All FAQs + Add New + Categories (native screens, surfaced in our menu). add_submenu_page( self::SLUG, __( 'All FAQs', 'accordion-faq-plugin' ), __( 'All FAQs', 'accordion-faq-plugin' ), 'edit_posts', 'edit.php?post_type=' . \AccordionFaq\Setup\PostType::POST_TYPE ); add_submenu_page( self::SLUG, __( 'Add New FAQ', 'accordion-faq-plugin' ), __( 'Add New', 'accordion-faq-plugin' ), 'edit_posts', 'post-new.php?post_type=' . \AccordionFaq\Setup\PostType::POST_TYPE ); add_submenu_page( self::SLUG, __( 'FAQ Categories', 'accordion-faq-plugin' ), __( 'Categories', 'accordion-faq-plugin' ), 'manage_categories', 'edit-tags.php?taxonomy=' . \AccordionFaq\Setup\Taxonomy::TAXONOMY . '&post_type=' . \AccordionFaq\Setup\PostType::POST_TYPE ); add_submenu_page( self::SLUG, __( 'Analytics', 'accordion-faq-plugin' ), __( 'Analytics', 'accordion-faq-plugin' ), 'edit_posts', self::SLUG . '-analytics', array( $this->pages['analytics'], 'render' ) ); add_submenu_page( self::SLUG, __( 'AI & Tools', 'accordion-faq-plugin' ), __( 'AI & Tools', 'accordion-faq-plugin' ), 'manage_options', self::SLUG . '-tools', array( $this->pages['tools'], 'render' ) ); add_submenu_page( self::SLUG, __( 'Settings', 'accordion-faq-plugin' ), __( 'Settings', 'accordion-faq-plugin' ), 'manage_options', self::SLUG . '-settings', array( $this->pages['settings'], 'render' ) ); } }