get_option( 'admin_email' ), 'csvNonce' => wp_create_nonce( 'soderlind_aivalve_export_csv' ), 'adminPostUrl' => admin_url( 'admin-post.php' ), ) ); } /* ------------------------------------------------------------------ * Page renderer — React root container * ----------------------------------------------------------------*/ public function render_page(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } ?>
sanitize_key( wp_unslash( $_GET['filter_plugin'] ?? '' ) ), 'provider_id' => sanitize_key( wp_unslash( $_GET['filter_provider'] ?? '' ) ), 'model_id' => sanitize_text_field( wp_unslash( $_GET['filter_model'] ?? '' ) ), 'context' => sanitize_key( wp_unslash( $_GET['filter_context'] ?? '' ) ), 'status' => sanitize_text_field( wp_unslash( $_GET['filter_status'] ?? '' ) ), 'per_page' => 10000, 'page' => 1, ); $date_from = sanitize_text_field( wp_unslash( $_GET['filter_date_from'] ?? '' ) ); $date_to = sanitize_text_field( wp_unslash( $_GET['filter_date_to'] ?? '' ) ); if ( $date_from && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date_from ) ) { $filters['date_from'] = $date_from . ' 00:00:00'; } if ( $date_to && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date_to ) ) { $filters['date_to'] = $date_to . ' 23:59:59'; } $result = $repo->query( $filters ); $filename = 'soderlind-aivalve-logs-' . gmdate( 'Y-m-d' ) . '.csv'; header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); $output = fopen( 'php://output', 'w' ); fputcsv( $output, array( 'Time', 'Plugin', 'Provider', 'Model', 'Capability', 'Context', 'Prompt Tokens', 'Completion Tokens', 'Total Tokens', 'Duration (ms)', 'Status' ) ); foreach ( $result['items'] as $row ) { fputcsv( $output, array( $row->created_at ?? '', $row->plugin_slug ?? '', $row->provider_id ?? '', $row->model_id ?? '', $row->capability ?? '', $row->context ?? '', $row->prompt_tokens ?? 0, $row->completion_tokens ?? 0, $row->total_tokens ?? 0, $row->duration_ms ?? 0, $row->status ?? '', ) ); } exit; } }