'Overview', 'export_import' => 'Export & Import', 'migrator' => 'Migration', ]; /** @var Export_Import */ private $export_import; /** @var Migrator */ private $migrator; /** @var Quick_Start */ private $quick_start; /** @var object|null Pro's License infrastructure service, when available. */ private $license; /** * Construct the infrastructure services this screen composes, add the * License nav item when Pro's License runtime is available, and filter * this Section's notification message. */ public function __construct() { $this->export_import = new Export_Import(); $this->migrator = new Migrator(); $this->quick_start = new Quick_Start(); $license_class = Module_Registry::get_runtime_target( 'license' ); if ( null !== $license_class && class_exists( $license_class ) ) { $this->nav_modules['license'] = 'License'; $this->license = new $license_class(); } add_filter( 'adminoptim_notification_message_' . self::SECTION_ID, static function ( string $message, string $display ): string { if ( 'banner' === $display ) { return $message; } return $message; }, 10, 2 ); add_filter( 'adminoptim_notification_banner_content_' . self::SECTION_ID, static function (): array { $content = [ [ 'message' => sprintf( /* translators: 1: Opening strong tag, 2: Closing strong tag. */ __( '%1$sFinding Admin Optimizer useful?%2$s Leave a ★★★★★ review on WordPress.org and help others to simplify WordPress management and save time.', 'admin-optimizer' ), '', '' ), 'cta_type' => 'review', ], [ 'message' => sprintf( /* translators: 1: Opening strong tag, 2: Closing strong tag. */ __( '%1$sHaving issues with Admin Optimizer?%2$s', 'admin-optimizer' ), '', '' ), 'cta_type' => 'support', ], ]; return $content[ wp_rand( 0, 1 ) ]; }, ); } /** * Section-oriented card metadata (title/description) shown on the * Overview dashboard, keyed by canonical Section ID. * * @return array */ private function sections(): array { return [ 'performance' => [ 'title' => __( 'Performance', 'admin-optimizer' ), 'description' => __( 'Optimize WordPress performance and reduce unnecessary overhead.', 'admin-optimizer' ), ], 'security' => [ 'title' => __( 'Security', 'admin-optimizer' ), 'description' => __( 'Harden login, reduce fingerprinting, and manage access.', 'admin-optimizer' ), ], 'seo' => [ 'title' => __( 'SEO', 'admin-optimizer' ), 'description' => __( 'Manage metadata, sitemaps, and search-engine visibility.', 'admin-optimizer' ), ], 'content' => [ 'title' => __( 'Content', 'admin-optimizer' ), 'description' => __( 'Manage content workflows.', 'admin-optimizer' ), ], 'media' => [ 'title' => __( 'Media', 'admin-optimizer' ), 'description' => __( 'Manage media library.', 'admin-optimizer' ), ], 'post-types-fields' => [ 'title' => __( 'Post Types & Fields', 'admin-optimizer' ), 'description' => __( 'Manage post types, taxonomies, custom fields, and content structure.', 'admin-optimizer' ), ], 'users' => [ 'title' => __( 'Users', 'admin-optimizer' ), 'description' => __( 'Manage user accounts, access, and activity.', 'admin-optimizer' ), ], 'system' => [ 'title' => __( 'System Tools', 'admin-optimizer' ), 'description' => __( 'System-level tools and integrations.', 'admin-optimizer' ), ], ]; } /** * Register submenu/asset hooks for the Overview screen. * * @return void */ public function init(): void { add_action( 'adminoptimizer_add_submenu_page', [ $this, 'add_submenu' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); } /** * Register the top-level Optimize page's own submenu entry (the * Overview route) and its admin-screen hook suffix with Module_Registry. * Fired on `adminoptimizer_add_submenu_page`. * * @return void */ public function add_submenu(): void { $page_hook = add_submenu_page( ADMINOPTIMIZER_MODULES_MENU_SLUG, $this->screen_title(), $this->screen_title(), 'manage_options', ADMINOPTIMIZER_MODULES_MENU_SLUG, [ $this, 'render' ] ); if ( is_string( $page_hook ) ) { Module_Registry::register_admin_screen( self::SECTION_ID, $page_hook ); } } /** * The screen/menu title. * * @return string */ protected function screen_title(): string { return __( 'Overview', 'admin-optimizer' ); } /** * Enqueue Overview screen assets on its own screen only. * * @param string $hook_suffix Current admin page hook suffix. * * @return void */ public function enqueue_assets( string $hook_suffix ): void { if ( 'toplevel_page_' . ADMINOPTIMIZER_MODULES_MENU_SLUG !== $hook_suffix ) { return; } wp_enqueue_style( 'adminoptim-sections', ADMINOPTIMIZER_ADMIN_URI . 'assets/css/sections.min.css', [], ADMINOPTIMIZER_VERSION ); wp_enqueue_style( 'adminoptim-overview', ADMINOPTIMIZER_ADMIN_URI . 'assets/css/overview.min.css', [], ADMINOPTIMIZER_VERSION ); wp_enqueue_style( 'adminoptim-quick-start', ADMINOPTIMIZER_ADMIN_URI . 'assets/css/quick-start.min.css', [], ADMINOPTIMIZER_VERSION ); wp_enqueue_script( 'adminoptim-module-activation', ADMINOPTIMIZER_ADMIN_URI . 'assets/js/module-activation.min.js', [], ADMINOPTIMIZER_VERSION, true ); wp_enqueue_script( 'adminoptim-overview', ADMINOPTIMIZER_ADMIN_URI . 'assets/js/overview.min.js', [ 'adminoptim-module-activation' ], ADMINOPTIMIZER_VERSION, true ); wp_enqueue_script( 'adminoptim-module-jump', ADMINOPTIMIZER_ADMIN_URI . 'assets/js/module-jump.min.js', [], ADMINOPTIMIZER_VERSION, true ); wp_enqueue_script( 'adminoptim-quick-start', ADMINOPTIMIZER_ADMIN_URI . 'assets/js/quick-start.min.js', [], ADMINOPTIMIZER_VERSION, true ); wp_localize_script( 'adminoptim-module-activation', 'AdminOptimizerModuleActivation', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'action' => Module_Activation::ACTION, 'nonce' => wp_create_nonce( Module_Activation::NONCE_ACTION ), ] ); wp_localize_script( 'adminoptim-quick-start', 'AdminOptimizerQuickStart', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'toggleAction' => Quick_Start::TOGGLE_HIDDEN_ACTION, 'popupAction' => Quick_Start::GET_POPUP_ACTION, 'applyAction' => Quick_Start::APPLY_ACTION, 'strings' => [ 'selectAtLeastOne' => __( 'Select at least one change.', 'admin-optimizer' ), 'alreadyOn' => __( 'Already on.', 'admin-optimizer' ), /* translators: %d: number of settings changes to apply. */ 'applyN' => __( 'Apply %d changes', 'admin-optimizer' ), 'title' => __( 'Review recommended settings', 'admin-optimizer' ), 'subtitle' => __( 'Recommended settings are selected. Optional settings may affect compatibility.', 'admin-optimizer' ), 'footerNote' => __( 'Nothing changes until you click Apply.', 'admin-optimizer' ), 'cancel' => __( 'Cancel', 'admin-optimizer' ), 'recommendedHeading' => __( 'Recommended', 'admin-optimizer' ), 'recommendedNote' => __( 'Low risk on almost any site.', 'admin-optimizer' ), 'optionalHeading' => __( 'Optional', 'admin-optimizer' ), 'optionalNote' => __( 'Check your plugins and theme first.', 'admin-optimizer' ), ], ] ); } /** * Render the Overview screen: header, Pro upsell strip, the product-wide * infrastructure navigation, and the selected view (Section cards, * Export & Import, Migration, or License). * * @return void */ public function render(): void { $current_view = $this->current_view(); ?>


quick_start->render_restore_link(); ?>
export_import->render_settings_page(); ?> migrator->render_settings_page(); ?> license ) : ?> license->render_settings_page(); ?> quick_start->render_card(); ?>
build_section_cards() as $section_id => $card ) : ?> render_section_card( $section_id, $card ); ?> render_automations_card(); ?>
nav_modules ) ? $requested_view : 'overview'; } /** * Render the Overview screen and return the output instead of echoing it. * * @return string */ public function render_to_string(): string { ob_start(); $this->render(); return (string) ob_get_clean(); } /** * Build the Section-card data set for the Overview grid: each Section's * title/description plus its non-retired, non-container capabilities and * enabled/available module counts. * * @return array */ private function build_section_cards(): array { $container_ids = array_unique( array_filter( array_column( Module_Registry::get_modules(), 'parent' ) ) ); $cards = []; foreach ( $this->sections() as $section_id => $meta ) { $capabilities = array_filter( Module_Registry::get_modules_by_section( $section_id ), static function ( $capability ) use ( $container_ids ) { if ( ! empty( $capability['retired'] ) ) { return false; } // NATIVE presentation containers (e.g. Content Management) are holding // identities for their children, not capabilities of their own; see // ARCHITECTURE_V3.md §4.2. if ( Module_Registry::NATIVE === $capability['classification'] && in_array( $capability['id'], $container_ids, true ) ) { return false; } return true; } ); $module_total = 0; $enabled_count = 0; foreach ( $capabilities as $capability ) { if ( Module_Registry::MODULE === $capability['classification'] && Module_Registry::is_available( $capability['id'] ) ) { ++$module_total; if ( Module_Registry::is_enabled( $capability['id'] ) ) { ++$enabled_count; } } } $cards[ $section_id ] = [ 'title' => $meta['title'], 'description' => $meta['description'], 'capabilities' => $capabilities, 'module_total' => $module_total, 'enabled_count' => $enabled_count, ]; } return $cards; } /** * Render one Section card: title, description, its ordinary modules, * its lightweight SECTION_FEATUREs, and a link to the Section's own page. * * @param string $section_id Canonical Section ID. * @param array $card Card data built by build_section_cards(). * * @return void */ private function render_section_card( string $section_id, array $card ): void { $features = array_filter( $card['capabilities'], static function ( $capability ) { return Module_Registry::SECTION_FEATURE === $capability['classification']; } ); $modules = array_diff_key( $card['capabilities'], $features ); ?>

render_capability( $capability ); ?> maybe_render_form_builder( $section_id ); ?>

render_module_row( $capability ); break; case Module_Registry::NATIVE: $this->render_native_row( $capability ); break; } } /** * Render one ordinary MODULE row with its activation toggle or * unavailable/Pro-only state. * * @param array $capability Normalized MODULE definition. * * @return void */ private function render_module_row( array $capability ): void { $available = Module_Registry::is_available( $capability['id'] ); $enabled = Module_Registry::is_enabled( $capability['id'] ); ?>