get_contents( $path ); header( 'Content-Type: text/plain; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="' . $file . '"' ); header( 'Content-Length: ' . strlen( $contents ) ); header( 'Cache-Control: no-cache' ); echo $contents; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit; } public static function export_csv(): void { Common::checkCapability( 'manage_options' ); Common::verifyNonce(); global $wpdb; $table = TableName::ADFUZ_AUDIT_LOGS( true ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery $rows = DB::get( TableName::ADFUZ_AUDIT_LOGS() ) ->orderBy( 'created_at', 'DESC' ) ->get(); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="adfuz-audit-logs-' . gmdate( 'Ymd' ) . '.csv"' ); header( 'Cache-Control: no-cache' ); $out = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( ! empty( $rows ) ) { fputcsv( $out, array_keys( $rows[0] ) ); foreach ( $rows as $row ) { fputcsv( $out, $row ); } } fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose exit; } public static function prune_audit_logs(): void { $settings = get_option( SettingsController::OPTION_KEY, array() ); $prune_days = absint( $settings['auto_prune_days'] ?? 0 ); if ( $prune_days <= 0 ) { return; } DB::get( TableName::ADFUZ_AUDIT_LOGS() ) ->where( 'created_at', '<', gmdate( 'Y-m-d H:i:s', strtotime( "-{$prune_days} days" ) ) ) ->delete(); } }