Code generated by Bing to use year/month/day directories instead of year/month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Custom Upload Directory | |
Description: A plugin that stores uploaded files in year/month/day directories | |
Version: 1.0 | |
Author: Bing | |
*/ | |
// Define a function that modifies the upload directory | |
function custom_upload_dir( $params ) { | |
// Get the current date | |
$date = getdate(); | |
// Append the day to the subdirectory | |
$params['subdir'] = $params['subdir'] . '/' . $date['mday']; | |
// Update the path and url accordingly | |
$params['path'] = $params['basedir'] . $params['subdir']; | |
$params['url'] = $params['baseurl'] . $params['subdir']; | |
// Return the modified parameters | |
return $params; | |
} | |
// Add the filter to change the upload directory | |
add_filter( 'upload_dir', 'custom_upload_dir' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment