}|null */ private $section_feature_group; /** @var Runtime_Loader */ private $runtime_loader; /** * @param string $section_id Canonical Module_Registry `section` value. * @param string $page_slug Menu-owned `admin.php?page=` slug for this Section. * @param array $nav_modules Ordinary module IDs mapped to their nav labels. * @param Runtime_Loader $runtime_loader Shared loader used to fetch already-running modules. * @param array{label?:string,description?:string,members?:array}|null $section_feature_group Optional Section-owned SECTION_FEATURE presentation group. */ public function __construct( $section_id, $page_slug, $nav_modules, Runtime_Loader $runtime_loader, ?array $section_feature_group = null ) { $this->section_id = $section_id; $this->page_slug = $page_slug; $this->nav_modules = $nav_modules; $this->runtime_loader = $runtime_loader; $this->section_feature_group = $section_feature_group; } /** * Render the Section's horizontal navigation and the currently selected * module or feature-group view. * * @return void */ public function render_section() { $current_module = $this->current_module_id(); ?> nav_modules ) ) : ?> is_section_feature_group_overview_selected( $current_module ) ) : $this->render_section_feature_group(); else : $this->render_module( $current_module ); endif; ?> section_id !== $capability['section'] ) { return; } $selected_id = $this->current_module_id(); $is_selected = $capability['id'] === $selected_id; $module_url = Module_Registry::get_module_url( $capability['id'] ); ?>
  • >
  • grouped_capabilities(); if ( empty( $capabilities ) ) { return; } $representative = reset( $capabilities ); $label = ! empty( $this->section_feature_group['label'] ) ? (string) $this->section_feature_group['label'] : (string) $representative['name']; $this->render_section_feature_group_nav_link( $representative, $label, isset( $capabilities[ $selected_id ] ) ); } /** * Render a single top-level navigation link for a presentation group. * * @param array $representative Capability whose URL represents the group. * @param string $label Navigation label. * @param bool $is_selected Whether this group owns the current view. * * @return void */ private function render_section_feature_group_nav_link( array $representative, string $label, bool $is_selected ): void { $module_url = Module_Registry::get_module_url( $representative['id'] ); ?>
  • >
  • section_id !== $capability['section'] || Module_Registry::MODULE !== $capability['classification'] ) { return; } ?>

    render_module_activation_control( $capability ); ?> render_module_pin_control( $capability ); ?>

    runtime_loader->get( $capability['id'] ); if ( null !== $module ) { $settings = $module->get_settings(); if ( is_callable( [ $settings, 'render_settings_page' ] ) ) : $settings->render_settings_page(); else : ?>

    current_module_id(); if ( '' === $module_id ) { return; } if ( $this->is_section_feature_group_overview_selected( $module_id ) ) { return; } $module = $this->runtime_loader->get( $module_id ); if ( null !== $module ) { $module->enqueue_section_settings_assets( $hook_suffix ); } } /** * Resolve the requested navigation item, falling back to the first item. * * @return string */ private function current_module_id(): string { $requested_module = isset( $_GET['module'] ) && is_string( $_GET['module'] ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only navigation state. : ''; $nav_modules = is_array( $this->nav_modules ) ? $this->nav_modules : []; $nav_module_ids = []; foreach ( array_keys( $nav_modules ) as $nav_module_id ) { $capability = Module_Registry::get_module( (string) $nav_module_id ); if ( null !== $capability && empty( $capability['retired'] ) && $this->section_id === $capability['section'] ) { $nav_module_ids[] = (string) $nav_module_id; } } $grouped_capabilities = $this->grouped_capabilities(); $group_ids = array_keys( $grouped_capabilities ); $valid_ids = array_merge( $nav_module_ids, $group_ids ); $fallback_id = ! empty( $nav_module_ids ) ? (string) reset( $nav_module_ids ) : (string) array_key_first( $grouped_capabilities ); return in_array( $requested_module, $valid_ids, true ) ? $requested_module : $fallback_id; } /** * Render a toggleable capability's activation surface from canonical * registry identity and state. Ordinary MODULE capabilities must have a * runnable target; SECTION_FEATURE capabilities are executed directly by * their Section and therefore do not use MODULE runtime availability. * * @param array $capability Normalized MODULE or SECTION_FEATURE definition. * * @return void */ private function render_module_activation_control( array $capability ): void { if ( ! Module_Registry::is_toggleable( $capability['id'] ) || ! current_user_can( Module_Registry::get_activation_capability( $capability['id'] ) ) ) { return; } $available = Module_Registry::SECTION_FEATURE === $capability['classification'] || Module_Registry::is_available( $capability['id'] ); $enabled = Module_Registry::is_enabled( $capability['id'] ); ?> is_pinned( $module_id ); $label = $is_pinned ? __( 'Unpin from Optimize menu', 'admin-optimizer' ) : __( 'Pin to the Optimize sidebar menu for quick access', 'admin-optimizer' ); ?> grouped_capabilities(); $label = ! empty( $this->section_feature_group['label'] ) ? (string) $this->section_feature_group['label'] : ''; $description = isset( $this->section_feature_group['description'] ) ? (string) $this->section_feature_group['description'] : ''; if ( empty( $capabilities ) ) { return; } ?>

    render_capability_cards( $capabilities ); ?> $capabilities Capabilities to render. * * @return void */ private function render_capability_cards( array $capabilities ): void { ?>

    render_module_activation_control( $capability ); ?>
    */ private function grouped_capabilities(): array { if ( null === $this->section_feature_group || ! isset( $this->section_feature_group['members'] ) || ! is_array( $this->section_feature_group['members'] ) ) { return []; } $capabilities = []; foreach ( $this->section_feature_group['members'] as $module_id ) { if ( ! is_string( $module_id ) ) { continue; } $capability = Module_Registry::get_module( $module_id ); if ( null !== $capability && empty( $capability['retired'] ) && $this->section_id === $capability['section'] && in_array( $capability['classification'], [ Module_Registry::MODULE, Module_Registry::SECTION_FEATURE ], true ) ) { $capabilities[ $module_id ] = $capability; } } return $capabilities; } /** * Whether the given module ID resolves to a configured feature-group member. * * @param string $module_id Canonical module ID to check. * * @return bool */ private function is_section_feature_group_overview_selected( string $module_id ): bool { return isset( $this->grouped_capabilities()[ $module_id ] ); } /** * Display labels for every Section, in Overview's own display order. * Module_Registry only carries the canonical Section ID on each * navigable module, not a label -- this mirrors the private title list * Overview already keeps for the same purpose (see * `Overview::sections()`), rather than inventing a second module * catalogue. * * @return array */ private static function section_labels(): array { $labels = [ 'performance' => __( 'Performance', 'admin-optimizer' ), 'security' => __( 'Security', 'admin-optimizer' ), 'seo' => __( 'SEO', 'admin-optimizer' ), 'content' => __( 'Content', 'admin-optimizer' ), 'media' => __( 'Media', 'admin-optimizer' ), 'post-types-fields' => __( 'Post Types & Fields', 'admin-optimizer' ), 'users' => __( 'Users', 'admin-optimizer' ), 'system' => __( 'System Tools', 'admin-optimizer' ), ]; if ( Module_Registry::is_pro_active() ) { $labels['automations'] = __( 'Automations', 'admin-optimizer' ); } return $labels; } /** * Public entry point for any Section screen to render the "Jump to * module" dropdown. Static and stateless so screens without a * Section_Renderer instance (e.g. Overview) can call it directly. * * @return void */ public static function render_module_jump(): void { self::render_module_jump_dropdown(); } /** * Render the "Jump to module" dropdown: a trigger button plus a * search-filterable panel listing every navigable module, grouped by * Section. Reuses `Module_Registry::get_navigable_modules_for_commands()` * -- the same projection the Command Palette renders -- rather than a * second catalogue. Each item is a real `` to the module's * resolved URL so the feature degrades to plain navigation if JS fails * to load; `module-jump.js` only layers show/hide/filter/keyboard * behavior on top. * * @return void */ private static function render_module_jump_dropdown(): void { $modules = array_values( array_filter( Module_Registry::get_navigable_modules_for_commands(), static function ( array $module ): bool { return current_user_can( Module_Registry::get_settings_capability( $module['id'] ) ); } ) ); if ( empty( $modules ) ) { return; } $labels = self::section_labels(); $grouped = []; foreach ( $modules as $module ) { $grouped[ $module['section'] ][] = $module; } ?>