Created
May 26, 2019 14:24
-
-
Save jakubmikita/a47f52b892142a667ac8f6700d92955e to your computer and use it in GitHub Desktop.
Fix for EDD forced download on Bedrock or when wp-content directory is in different location than ABSPATH. Fixes "Sorry, this file could not be downloaded" error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'edd_local_file_location_is_allowed', function( $should_allow, $file_details, $schemas, $requested_file ) { | |
$requested_file = wp_normalize_path( realpath( $requested_file ) ); | |
$normalized_content_dir = wp_normalize_path( WP_CONTENT_DIR ); | |
if ( false !== strpos( $requested_file, $normalized_content_dir ) ) { | |
$should_allow = true; | |
} | |
return $should_allow; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be safer checking for
0
here. This code allows a requested file of/a/b/c/d/e.txt
if the content directory is/b/c/d
.Adding a trailing forward slash to
$normalized_content_dir
also ensures/foo/bar/baz.txt
isn't matched with/foo/ba