add_action('admin_post_hfmh_download', function () { if (!current_user_can('manage_options')) { wp_die('Unauthorized'); } if (empty($_GET['hfmh_download'])) { wp_die('Missing file'); } $encoded = (string) $_GET['hfmh_download']; $path = base64_decode(rawurldecode($encoded), true); if (!$path || !file_exists($path) || !is_readable($path)) { wp_die('File not found'); } while (ob_get_level()) { ob_end_clean(); } nocache_headers(); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Length: ' . filesize($path)); readfile($path); exit; });