Created
May 2, 2012 19:41
-
-
Save pippinsplugins/2579659 to your computer and use it in GitHub Desktop.
Trying to change upload directory on "download" post type
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_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; | |
} |
Not sure if this will help, but just in case I didn't misinterpret what you're trying to do, give this a shot:
<?php
function edd_load_upload_filter() {
global $pagenow;
if ( ! empty( $_POST['post_id'] ) && ( 'async-upload.php' == $pagenow || 'media-upload.php' == $pagenow ) ) {
if ( 'download' == get_post_type( $_REQUEST['post_id'] ) ) {
add_filter( 'upload_dir', 'edd_set_upload_dir' );
}
}
}
add_action('admin_init', 'edd_load_upload_filter');
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;
}
?>
Aha! That appears to work perfectly. I didn't think about the fact that the media uploader has a different $pagenow id . . .that makes a lot more sense now. Props dude!
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. :-)
@thomasgriffin, whoops, yeah, should have mentioned that. The solution Brady suggested above works perfectly.
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
Trying a different approach now:
I've confirmed that the basic checks (I know they are no where complete) work, in terms of limiting the filter to when editing a download, but what is really strange is that the
upload_dir
filter doesn't work, except when I remove the $pagenow checks . . .