Skip to content

Instantly share code, notes, and snippets.

@giucu91
Last active December 21, 2022 14:09
Show Gist options
  • Save giucu91/6bd0e2bd25122a9c8b5c83ea43e83bae to your computer and use it in GitHub Desktop.
Save giucu91/6bd0e2bd25122a9c8b5c83ea43e83bae to your computer and use it in GitHub Desktop.
change-dlm-upload-folder.php
<?php
add_filter( 'upload_dir', 'change_upload_dir_for_dlm', 30 );
function change_upload_dir_for_dlm( $pathdata ){
if ( isset( $_POST['type'] ) && 'dlm_download' === $_POST['type'] ) {
if ( empty( $pathdata['subdir'] ) ) {
$pathdata['path'] = $pathdata['path'] . '/private';
$pathdata['url'] = $pathdata['url'] . '/private';
$pathdata['subdir'] = '/private';
} else {
$new_subdir = '/private' . $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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment