init_hooks(); } /** * Initialize hooks. */ private function init_hooks() { add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); } /** * Add admin menu. * Note: Dashboard is now handled by AfriDirect_Payment_Admin_Menu. * This method is kept for backward compatibility but does nothing. */ public function add_admin_menu() { // Menu is now created by AfriDirect_Payment_Admin_Menu. // This method is kept for compatibility but does nothing. } /** * Render dashboard. */ public function render_dashboard() { $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' ) ); } // Handle bulk actions. $this->handle_bulk_actions(); // Get orders pending review (only afridirect-proof status). $orders = wc_get_orders( array( 'status' => array( 'adp-proof' ), 'payment_method' => 'afridirect_payment', 'limit' => 100, 'orderby' => 'date', 'order' => 'DESC', ) ); include AFRIDIRECT_PAYMENT_PLUGIN_DIR . 'admin/views/dashboard.php'; } /** * Handle bulk actions. */ private function handle_bulk_actions() { if ( ! isset( $_POST['afridirect_bulk_action'] ) || ! isset( $_POST['afridirect_order_ids'] ) ) { return; } check_admin_referer( 'afridirect-bulk-actions', 'afridirect_bulk_nonce' ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'Unauthorized access.', 'afridirect-payment' ) ); } $action = sanitize_text_field( wp_unslash( $_POST['afridirect_bulk_action'] ) ); $order_ids = array_map( 'absint', $_POST['afridirect_order_ids'] ); if ( empty( $order_ids ) ) { return; } $processed = 0; foreach ( $order_ids as $order_id ) { $order = wc_get_order( $order_id ); if ( ! $order || 'adp-proof' !== $order->get_status() ) { continue; } if ( 'approve' === $action ) { $this->process_approve( $order_id, '' ); $processed++; } elseif ( 'reject' === $action ) { $note = isset( $_POST['afridirect_bulk_reject_note'] ) ? sanitize_textarea_field( wp_unslash( $_POST['afridirect_bulk_reject_note'] ) ) : ''; if ( $note ) { $this->process_reject( $order_id, $note ); $processed++; } } } if ( $processed > 0 ) { add_action( 'admin_notices', function() use ( $processed, $action ) { echo '
'; /* translators: 1: Number of orders, 2: Action verb (e.g., "approved", "rejected") */ echo esc_html( sprintf( _n( '%1$d order %2$s successfully.', '%1$d orders %2$s successfully.', $processed, 'afridirect-payment' ), $processed, $action . 'ed' ) ); echo '