[wp-hackers] filtering uploads_dir

Chris McCoy chris at lod.com
Fri Feb 28 21:22:52 UTC 2014

What would be the proper way to filter uploads dir, even though a plugin is
already doing it, download monitor runs a filter on uploads_dir, which
stores the dir to write files, when I run a filter it adds the prefix before
the download directory specified by the plugin filter, I want to replace it.

I do want to keep the date intact.

function expire_upload_filter() {
    if ( isset( $_POST['type'] ) && $_POST['type'] == 'dlm_download' ) {
            add_filter( 'upload_dir', 'expire_set_upload_dir' );

add_action('admin_init', 'expire_upload_filter');

function expire_set_upload_dir($upload) {
    $upload['subdir']   = '/expire' . $upload['subdir'];
    $upload['path'] = $upload['basedir'] . $upload['subdir'];
    $upload['url'] = $upload['baseurl'] . $upload['subdir'];
    return $upload;

This will just prefix /expire/dlm_uploads

Since the uploaddir function is already prefixing dlm_uploads


More information about the wp-hackers mailing list