Skip to content

Instantly share code, notes, and snippets.

@jakubmikita
Created May 26, 2019 14:24
Show Gist options
  • Save jakubmikita/a47f52b892142a667ac8f6700d92955e to your computer and use it in GitHub Desktop.
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.
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 );
@jamieburchell
Copy link

jamieburchell commented Nov 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment