Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Created April 5, 2023 16:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jazzsequence/8f3c388c26eca5fc3abc31190a5fef2f to your computer and use it in GitHub Desktop.
Code generated by Bing to use year/month/day directories instead of year/month
<?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