Created
May 25, 2012 17:41
-
-
Save pippinsplugins/2789419 to your computer and use it in GitHub Desktop.
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
<?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