init_hooks(); } /** * Initialize hooks. */ private function init_hooks() { add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 6 ); // Priority 6 to run after main menu but before other submenus. } /** * Add admin menu. */ public function add_admin_menu() { $menu_manager = AfriDirect_Payment_Admin_Menu::instance(); $parent_slug = $menu_manager->get_menu_slug(); // Add the Dashboard as the first submenu. add_submenu_page( $parent_slug, __( 'Dashboard', 'afridirect-payment' ), __( 'Dashboard', 'afridirect-payment' ), $menu_manager->get_capability(), $parent_slug, // Use parent slug so it's the first submenu. array( $this, 'render_page' ) ); } /** * Render overview page. */ public function render_page() { $menu_manager = AfriDirect_Payment_Admin_Menu::instance(); if ( ! current_user_can( $menu_manager->get_capability() ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'afridirect-payment' ) ); } // Check if checkout was just switched. This only toggles a one-time admin // notice after redirecting from the (nonce-verified) switch action in // class-admin-actions.php; it does not itself perform any action. // phpcs:ignore WordPress.Security.NonceVerification.Recommended $switched = isset( $_GET['afridirect_switched'] ) && '1' === $_GET['afridirect_switched']; // Check if blocks are active. $blocks_active = function_exists( 'afridirect_is_checkout_blocks_active' ) && afridirect_is_checkout_blocks_active(); $woocommerce_active = class_exists( 'WooCommerce' ); // Dashboard data. $stats = AfriDirect_Payment_Dashboard_Data::get_stats(); $queue = AfriDirect_Payment_Dashboard_Data::get_review_queue( 5 ); $steps = AfriDirect_Payment_Dashboard_Data::get_setup_steps(); $forms = AfriDirect_Payment_Dashboard_Data::get_forms( 5 ); $setup_done = count( array_filter( wp_list_pluck( $steps, 'done' ) ) ); // Money summary filters. They only change what is displayed and nothing is saved. $range_options = AfriDirect_Payment_Dashboard_Data::get_range_options(); // phpcs:disable WordPress.Security.NonceVerification.Recommended $range = isset( $_GET['afd_range'] ) ? sanitize_key( wp_unslash( $_GET['afd_range'] ) ) : 'all'; $currency = isset( $_GET['afd_currency'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_GET['afd_currency'] ) ) ) : ''; // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( ! isset( $range_options[ $range ] ) ) { $range = 'all'; } $money = AfriDirect_Payment_Dashboard_Data::get_money_summary( $range, $currency ); include AFRIDIRECT_PAYMENT_PLUGIN_DIR . 'admin/views/overview.php'; } }