I use a filter (in my custom plugin for my website) to force upload of files loaded with an Ultimate Member plugin form in a directory different from the default 'uploads' one. The filter works perfectly, but it loads also in the custom dir all the files generated by wordpress for the preview of the document (somefile-150x150.jpg and so on). How may I upload the original file to the custom dir and let preview automatic generated file to be uploaded in the default dir they would be uploaded without this custom code (the deafult 'uploads/year/whatever')?

add_filter('upload_dir', 'documents_dir');
function documents_dir( $param ){
    if (isset( $_POST['um_document_nonce'] )) { // if the file is uploaded via um form
        $first_name=preg_replace("/[^A-Za-z ]/", '', um_user('first_name'));

        $mydir = '/mydir/'.$first_name; // custom dir with name of the user who uploaded the file           

        $param['path'] = '/web/htdocs/www.mywebsite.com/home/wp-content/uploads/' . $mydir;
        $param['url'] = $param['url'] . $mydir;
        return $param;

   return $param;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.