From f29c5c03d9899f10204e76e093c3c50220ca70da Mon Sep 17 00:00:00 2001 From: Sergey Zakharchenko Date: Tue, 9 Nov 2021 12:23:24 +0200 Subject: [PATCH] Fixed the file download bug #805 --- .../controllers/class-frontend-controller.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/php/classes/controllers/class-frontend-controller.php b/php/classes/controllers/class-frontend-controller.php index 3d78192a..274f76d5 100644 --- a/php/classes/controllers/class-frontend-controller.php +++ b/php/classes/controllers/class-frontend-controller.php @@ -1160,13 +1160,9 @@ public function download_file() { // Ensure that $file is a valid URL $file = filter_var( $file, FILTER_VALIDATE_URL ); - // Ensure that $file is either audio or video type - $allowed_types = array( 'mp3|m4a' => 'audio/mpeg', 'mp4' => 'video/mp4' ); - $filetype = wp_check_filetype( $file, $allowed_types ); - // Exit if no file is found - if ( ! $file || ! $filetype['type'] ) { - return; + if ( ! $file ) { + $this->send_404(); } // Get file referrer @@ -1251,6 +1247,17 @@ public function download_file() { } } + /** + * Show the 404 not found page content. + */ + protected function send_404() { + global $wp_query; + $wp_query->set_404(); + status_header( 404 ); + get_template_part( 404 ); + exit(); + } + /** * Get the ID of an attachment from its image URL. *