Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created May 2, 2012 19:41
Show Gist options
  • Save pippinsplugins/2579659 to your computer and use it in GitHub Desktop.
Save pippinsplugins/2579659 to your computer and use it in GitHub Desktop.
Trying to change upload directory on "download" post type
<?php
function edd_load_upload_filter() {
add_action('load-edit.php', 'edd_change_downloads_upload_dir');
add_action('load-post.php', 'edd_change_downloads_upload_dir');
}
add_action('admin_init', 'edd_load_upload_filter');
function edd_change_downloads_upload_dir() {
$current_screen = get_current_screen();
if($current_screen->post_type !== 'download') { return; }
add_filter('upload_dir', 'edd_set_upload_dir');
}
function edd_set_upload_dir($upload) {
$upload['subdir'] = '/edd' . $upload['subdir'];
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
}
@thomasgriffin
Copy link

Ahh, I didn't know you were dealing with the media uploader. :-P In that case, check out the Media.php class file in Soliloquy to see how it is done there - it may be helpful for you in your case as well. :-)

@pippinsplugins
Copy link
Author

@thomasgriffin, whoops, yeah, should have mentioned that. The solution Brady suggested above works perfectly.

@thomasgriffin
Copy link

Sweet deal - glad you got it working. :-)

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