Skip to content

Instantly share code, notes, and snippets.

@kgoedecke
Last active August 13, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgoedecke/abe4ded0fcb31c5e13e02454f64b9514 to your computer and use it in GitHub Desktop.
Save kgoedecke/abe4ded0fcb31c5e13e02454f64b9514 to your computer and use it in GitHub Desktop.
Create subdirectory in WordPress uploads directory using plugin
<?php
class SomePlugin {
const CUSTOM_DIR = '/custom_dir';
static function install() {
$uploads_dir = wp_upload_dir();
$custom_uploads_dir = $uploads_dir['basedir'] . self::CUSTOM_DIR;
if( ! file_exists($custom_uploads_dir) ) {
wp_mkdir_p($custom_uploads_dir);
}
}
}
register_activation_hook( __FILE__, array( 'SomePlugin', 'install' ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment