init_hooks(); } /** * Initialize hooks. */ private function init_hooks() { add_action( 'admin_menu', array( $this, 'create_main_menu' ), 5 ); // Priority 5 to run before other menus. } /** * Create main admin menu. */ public function create_main_menu() { // Create top-level menu always. // The first submenu will be added by AfriDirect_Payment_Admin_Overview. add_menu_page( __( 'AfriDirect Payment', 'afridirect-payment' ), __( 'AfriDirect Payment', 'afridirect-payment' ), $this->get_capability(), $this->menu_slug, '', // Empty callback - Overview will handle it. 'dashicons-money-alt', 56 ); } /** * Render dashboard page. */ public function render_dashboard() { if ( ! current_user_can( $this->get_capability() ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'afridirect-payment' ) ); } // If WooCommerce is active, show WC dashboard, otherwise show standalone overview. if ( class_exists( 'WooCommerce' ) ) { // Check if Admin_Dashboard class exists and has render_dashboard method. if ( class_exists( 'AfriDirect_Payment_Admin_Dashboard' ) ) { $dashboard = AfriDirect_Payment_Admin_Dashboard::instance(); if ( method_exists( $dashboard, 'render_dashboard' ) ) { $dashboard->render_dashboard(); return; } } } // Standalone overview (fallback for both WC and non-WC). include AFRIDIRECT_PAYMENT_PLUGIN_DIR . 'admin/views/dashboard-standalone.php'; } /** * Get menu slug. * * @return string */ public function get_menu_slug() { return $this->menu_slug; } /** * Get required capability. * * @return string */ public function get_capability() { if ( class_exists( 'WooCommerce' ) ) { return 'manage_woocommerce'; } return 'manage_options'; } }