• Resolved mrmocha

    (@mrmocha)


    Hello,

    Is it possible to change the default upload path so that files are uploaded in the usual way to wp-contents/uploads/*year*/*month* rather than wp-contents/uploads/dlm_uploads//*year*/*month*

    Basically I need the files unprotected by default.

    I know the files could simply be added via the regular WordPress media upload area and then selected on a Download page, but this is for a client and I would like to make it so they don’t have to visit multiple areas of the admin to get a download published.

    Thanks for any advice.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter mrmocha

    (@mrmocha)

    Just to shine a bit more light on this – I just want the downloads to be freely accessible. I have added add_filter( 'dlm_do_not_force', '__return_true' ); to my functions file so the files open directly in the browser. But they all result in 404s unless I edit the htaccess file in the dlm_uploads folder to remove the deny from all directive….which feels wrong…

    Hey @mrmocha,

    I regret to say this falls under custom development and I would suggest contacting a 3rd party developer. Also, please note that the filter you used is useful when you are using the “Redirect to File” feature.

    Thread Starter mrmocha

    (@mrmocha)

    Ok. Thank you for getting back to me

    dangrimes

    (@damonmaldonado)

    I know this is marked as resolved but in case anyone finds this going forward you can change the upload location using the ‘upload_dir’ filter.

    The following function is modified from the method used in the plugin to set the directory.

    The value for $new_upload_directory sets the folder, if you want to use the WordPress default set this to an empty string.

    function override_dl_upload_dir( $pathdata ) {
    		$new_upload_directory = '/new_upload_directory';
    		if ( isset( $_POST['type'] ) && 'dlm_download' === $_POST['type'] ) {
    			//if no subdirectory set add one
    			if ( empty( $pathdata['subdir'] ) ) {
    				$pathdata['path']   = $pathdata['path'] . $new_upload_directory;
    				$pathdata['url']    = $pathdata['url'] . $new_upload_directory;
    				$pathdata['subdir'] = $new_upload_directory;
    			} else {
    				//if subdirectory is set, replace '/dlm_uploads' 
    				$new_subdir = $new_upload_directory . str_replace('/dlm_uploads', '', $pathdata['subdir'] );
    
    				$pathdata['path']   = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
    				$pathdata['url']    = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
    				$pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
    
    			}
    		}
    
    		return $pathdata;
    	}
    
        add_filter('upload_dir', 'override_dl_upload_dir', 99);
    Plugin Contributor Barry Kooij

    (@barrykooij)

    Thanks a lot for sharing this @damonmaldonado. I hope this will help people!

    Thread Starter mrmocha

    (@mrmocha)

    Thank you for taking the time to reply @damonmaldonado. This looks very helpful ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change Default Upload Path’ is closed to new replies.