*/ public static function get_tabs(): array { $tabs = array( 'automations' => [ 'label' => __( 'Workflows', 'afroit-messaging-workflows' ), 'page' => AutomationsPage::class, ], 'create_automation' => [ 'label' => __( 'Create Workflow', 'afroit-messaging-workflows' ), 'page' => CreateAutomationPage::class, 'exclude_menu' => true, ], 'templates' => [ 'label' => __( 'WhatsApp Templates', 'afroit-messaging-workflows' ), 'page' => MessageTemplatesPage::class, ], 'new_template' => [ 'label' => __( 'Create WhatsApp Template', 'afroit-messaging-workflows' ), 'page' => NewMessageTemplatePage::class, 'exclude_menu' => true, ], 'email' => [ 'label' => __( 'Email Templates', 'afroit-messaging-workflows' ), 'url' => admin_url( 'admin.php?page=wc-settings&tab=email' ), ], 'settings' => [ 'label' => __( 'Settings', 'afroit-messaging-workflows' ), 'page' => SettingsPage::class, ], 'documentation' => [ 'label' => __( 'Documentation', 'afroit-messaging-workflows' ), 'url' => 'https://messaging-workflows.com/documentation/', 'external' => true, ], 'privacy_policy' => [ 'label' => __( 'Privacy Policy', 'afroit-messaging-workflows' ), 'url' => 'https://messaging-workflows.com/privacy/', 'external' => true, ], ); /** * Filter primary hub tabs (GET `tab`). * * @param array> $tabs Tab definitions keyed by slug. */ $tabs = apply_filters( 'afromewo_hub_tabs', $tabs ); return is_array( $tabs ) ? $tabs : array(); } /** * Settings sub-sections (GET `section`) when `tab=settings` — same keys as legacy SettingsPage `tab`. * * @return array */ public static function get_settings_sections(): array { $sections = array( 'prerequisites' => [ 'label' => __( 'Prerequisites', 'afroit-messaging-workflows' ), 'page' => PrerequisitesPage::class, ], 'facebook_app' => [ 'label' => __( 'Meta App', 'afroit-messaging-workflows' ), 'page' => FacebookAppPage::class, ], 'facebook_business' => [ 'label' => __( 'WhatsApp Account', 'afroit-messaging-workflows' ), 'page' => MetaBusinessPage::class, ], 'twilio' => [ 'label' => __( 'Twilio Account', 'afroit-messaging-workflows' ), 'page' => TwilioSettingsPage::class, ], ); /** * Filter Settings tab sub-sections (GET `section`). * * @param array $sections Section map. */ $sections = apply_filters( 'afromewo_hub_settings_sections', $sections ); return is_array( $sections ) ? $sections : array(); } /** * Automation sub-sections (GET `section`) when `tab=automations`. * * @return array */ public static function get_automations_sections(): array { $sections = array( 'listing' => [ 'label' => __( 'Listing', 'afroit-messaging-workflows' ), 'page' => AutomationsPage::class, ], 'executed' => [ 'label' => __( 'Executions', 'afroit-messaging-workflows' ), 'page' => ExecutionsPage::class, ], ); /** * Filter Workflows tab sub-sections (GET `section`). * * @param array $sections Section map. */ $sections = apply_filters( 'afromewo_hub_automations_sections', $sections ); return is_array( $sections ) ? $sections : array(); } /** * Sub-sections for any hub tab (GET `section`). * * Built-in Settings and Workflows tabs keep their dedicated filters. * Add-ons can pass `sections` on a tab from `afromewo_hub_tabs`, and/or * use this filter for an arbitrary tab slug. * * @param string $tab Tab slug. * @return array */ public static function get_tab_sections( string $tab ): array { if ( 'settings' === $tab ) { return self::get_settings_sections(); } if ( 'automations' === $tab ) { return self::get_automations_sections(); } $tabs = self::get_tabs(); $sections = array(); if ( isset( $tabs[ $tab ]['sections'] ) && is_array( $tabs[ $tab ]['sections'] ) ) { $sections = $tabs[ $tab ]['sections']; } /** * Filter sub-sections for a hub tab. * * @param array $sections Section map. * @param string $tab Tab slug. */ $sections = apply_filters( 'afromewo_hub_tab_sections', $sections, $tab ); return is_array( $sections ) ? $sections : array(); } /** * Base admin URL for this hub. * * @param array $args Query args (`tab`, `section`, …). * @return string */ public static function url( array $args = array() ): string { $args = array_merge( array( 'page' => \AFROMEWO_PLUGIN_SLUG ), $args ); return add_query_arg( $args, admin_url( 'admin.php' ) ); } /** * Render the hub shell (preview content only — legacy screens use hidden menu slugs until migrated). * * @return void */ public function render(): void { $tabs = self::get_tabs(); $current_tab = sanitize_key( Request::get( 'tab', 'automations' ) ); if ( ! isset( $tabs[ $current_tab ] ) ) { $current_tab = 'automations'; } $tab_def = $tabs[ $current_tab ]; $display_page = isset( $tab_def['page'] ) ? $tab_def['page'] : ''; $tab_sections = self::get_tab_sections( $current_tab ); $current_section = ''; if ( ! empty( $tab_sections ) ) { $default_section = (string) array_key_first( $tab_sections ); $current_section = sanitize_key( Request::get( 'section', $default_section ) ); if ( ! isset( $tab_sections[ $current_section ] ) ) { $current_section = $default_section; } if ( isset( $tab_sections[ $current_section ]['page'] ) ) { $display_page = $tab_sections[ $current_section ]['page']; } } if ( 'templates' === $current_tab ) { if ( Request::has_get( 'id' ) ) { $display_page = ViewTemplatePage::class; } else { $display_page = MessageTemplatesPage::class; } } $page_slug = \AFROMEWO_PLUGIN_SLUG; require AFROMEWO_PLUGIN_DIR . 'includes/Admin/Hub/Views/hub-preview.php'; } }