Skip to content

Commit

Permalink
Fixed the file download bug #805
Browse files Browse the repository at this point in the history
  • Loading branch information
zahardev committed Nov 9, 2021
1 parent 30dc8f1 commit f29c5c0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions php/classes/controllers/class-frontend-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit f29c5c0

Please sign in to comment.