• Resolved esctab

    (@esctab)


    Hello @interfacelab,

    Great plugin! I really like the prefixes you added, but I have one question.
    Is there a possibility to set different upload paths for different custom post type?

    I mean if there exist any wp filter/hook inside your plugin which I can use to change upload path from the “Storage Settings/UPLOAD HANDLING”.

    I have tried to find any documentation but without luck ??

Viewing 1 replies (of 1 total)
  • Plugin Author interfacelab

    (@interfacelab)

    There isn’t, but you can just hook into WordPress’s filter for this (which is what Media Cloud does). Make sure you do it at a priority higher than 10000 though. I would do something like this in your functions.php:

    
    // We only want to generate the custom upload dir during an
    // actual upload
    add_filter('wp_handle_upload_prefilter', function($file){
        add_filter('upload_dir', 'customUploadDir', 10001);
        return $file;
    });
    
    // Upload has been handled, so remove our custom filter
    add_filter('wp_handle_upload', function($fileinfo){
        remove_filter('upload_dir', 'customUploadDir');
        return $fileinfo;
    });
    
    // do whatever you need to do here to customize the path
    function customUploadDir($params) {
        $newPath = '/nice/'.date('Y/m/d/G/i/s');
        $params['path'] = str_replace($params['subdir'], $newPath, $params['path']);
        $params['url'] = str_replace($params['subdir'], $newPath, $params['url']);
        $parms['subdir'] = $newPath;
        return $params;
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘Custom upload paths’ is closed to new replies.