Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Created October 12, 2015 13:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/9f0c3a7164544244b525 to your computer and use it in GitHub Desktop.
Save JudeRosario/9f0c3a7164544244b525 to your computer and use it in GitHub Desktop.
Custom Upload Dirs
/*
Plugin Name: Custom Upload Dirs
Description: Changes the upload directory to what we would like, instead of what WordPress likes.
Author: Mark
Version: 1.0
Author URI: http://google.com
*/
add_action( 'init', 'change_upload_dir' ) ;
function change_upload_dir() {
add_filter('upload_dir', 'ml_media_upload_dir');
}
/**
* Changes the upload directory to what we would like, instead of what WordPress likes.
*/
function ml_media_upload_dir($upload) {
global $user_ID;
$blog_id = get_current_blog_id();
if ((int)$user_ID > 0) {
$upload['subdir'] = "/wp-content/uploads/sites/".$blog_id."/". get_the_time('Y'). "/" .get_the_time('m');
$upload['path'] .= $upload['subdir'];
$upload['url'] .= $upload['subdir'];
}
return $upload;
}
@MarkLimmage
Copy link

"/". get_the_time('Y'). "/" .get_the_time('m') results in //

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment