401 ) ); } $order_id = absint( $_GET['order_id'] ); $nonce = isset( $_GET['_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_nonce'] ) ) : ''; if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'aimslms_invoice_' . $order_id ) ) { wp_die( esc_html__( 'Invalid invoice request.', 'aims-infosoft-lms' ), '', array( 'response' => 403 ) ); } global $wpdb; $table = $wpdb->prefix . 'aimslms_course_orders'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $order = $wpdb->get_row( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $table is derived from $wpdb->prefix, not user input. "SELECT * FROM $table WHERE id = %d", $order_id ) ); $payment_table = $wpdb->prefix . 'aimslms_course_payment'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $payment = $wpdb->get_row( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $payment_table is derived from $wpdb->prefix, not user input. "SELECT * FROM $payment_table WHERE order_id = %d", $order_id ) ); if ( ! $order ) { wp_die( esc_html__( 'Order not found.', 'aims-infosoft-lms' ), '', array( 'response' => 404 ) ); return; } if ( (int) $order->user_id !== get_current_user_id() && ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to access this invoice.', 'aims-infosoft-lms' ), '', array( 'response' => 403 ) ); return; } $user_id = $order->user_id; $u = get_userdata( $user_id ); require_once AIMSLMS_PLUGIN_DIR . 'vendor/autoload.php'; ob_start(); include AIMSLMS_PLUGIN_DIR . 'public/templates/invoice/invoice-template.php'; $html = ob_get_clean(); $dompdf = new \Dompdf\Dompdf( array( 'isRemoteEnabled' => true, ) ); $dompdf->loadHtml( $html ); $dompdf->setPaper( 'A4', 'portrait' ); $dompdf->render(); $dompdf->stream( 'Invoice-' . $order->id . '.pdf', array( 'Attachment' => false ) ); exit; } }