Codex tools: Log in
This hook allows you to change the directory where files are uploaded to. The keys and values in the array are used by the wp_upload_dir function in wordpress core, which is doing the work.
This goes into your plugin.
add_filter('upload_dir', 'awesome_wallpaper_dir');
function awesome_wallpaper_dir( $param ){
$mydir = '/awesome';
$param['path'] = $param['path'] . $mydir;
$param['url'] = $param['url'] . $mydir;
error_log("path={$param['path']}");
error_log("url={$param['url']}");
error_log("subdir={$param['subdir']}");
error_log("basedir={$param['basedir']}");
error_log("baseurl={$param['baseurl']}");
error_log("error={$param['error']}");
return $param;
}
If your plugin is written as a class, you'll want to hook to it like so:
add_filter('upload_dir', array(&$this,'awesome_wallpaper_dir'));
Using this, in conjunction with the wp_handle_upload_prefilter, you can dynamically determine which directory to upload to, based on the files you upload.