Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created May 25, 2012 17:41
Show Gist options
  • Save pippinsplugins/2789419 to your computer and use it in GitHub Desktop.
Save pippinsplugins/2789419 to your computer and use it in GitHub Desktop.
<?php
function edd_change_downloads_upload_dir() {
global $pagenow;
if ( ! empty( $_POST['post_id'] ) && ( 'async-upload.php' == $pagenow || 'media-upload.php' == $pagenow ) ) {
if ( 'download' == get_post_type( $_REQUEST['post_id'] ) ) {
$wp_upload_dir = wp_upload_dir();
$upload_path = $wp_upload_dir['basedir'] . '/edd' . $wp_upload_dir['subdir'];
if (wp_mkdir_p($upload_path) && !file_exists($upload_path.'/.htaccess')) {
if ($file_handle = @fopen( $upload_path . '/.htaccess', 'w' )) {
fwrite($file_handle, 'deny from all');
fclose($file_handle);
}
}
add_filter( 'upload_dir', 'edd_set_upload_dir' );
}
}
}
add_action('admin_init', 'edd_change_downloads_upload_dir', 999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment