base_dir() . basename( $file ); if ( ! file_exists( $path ) || ! $storage->validate_path( $path ) ) { wp_die( 'File not found.' ); } nocache_headers(); header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename="' . basename( $path ) . '"' ); header( 'Content-Length: ' . (string) filesize( $path ) ); if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; if ( ! $wp_filesystem ) { wp_die( 'Storage unavailable.' ); } $contents = $wp_filesystem->get_contents( $path ); if ( false === $contents ) { wp_die( 'File not readable.' ); } echo $contents; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- binary file output. exit; } add_action( 'admin_post_aiaas_download', 'aiaas_secure_download' );