diff --git a/custom-file-organizer.php b/custom-file-organizer.php index 1674016..4044f00 100644 --- a/custom-file-organizer.php +++ b/custom-file-organizer.php @@ -11,15 +11,44 @@ Text Domain: custom-file-organizer Domain Path: /languages Requires at least: 5.0 -Tested up to: 5.8 -Requires PHP: 7.0 +Requires PHP: 7.4 */ -if (! defined('ABSPATH') ) { +if (!defined('ABSPATH')) { exit; // Exit if accessed directly. } -if (defined('WP_CLI') && WP_CLI ) { +add_filter('upload_dir', 'wpb_custom_upload_directory'); + +/** + * Change custom upload directory pattern. + */ +function wpb_custom_upload_directory($param) +{ + $uploadPattern = get_current_upload_pattern(); + $param['path'] = $param['basedir'] . $uploadPattern; + $param['url'] = $param['baseurl'] . $uploadPattern; + return $param; +} + + +/** + * Get the current upload directory pattern. + * + * @return string The upload directory pattern. + */ +function get_current_upload_pattern() +{ + $time = current_time('mysql'); + $y = substr($time, 0, 4); + $m = substr($time, 5, 2); + $d = substr($time, 8, 2); + return "/$y/$m/$d"; +} + + + +if (defined('WP_CLI') && WP_CLI) { include_once __DIR__ . '/includes/class-custom-file-organizer-cli.php'; WP_CLI::add_command('file-organizer', 'Custom_File_Organizer_CLI'); } @@ -40,39 +69,26 @@ function custom_file_organizer_admin_menu() function custom_file_organizer_admin_page() { - ?> -
' . esc_html__('Before', 'custom-file-organizer') . ' | ' . esc_html__('After', 'custom-file-organizer') . ' |
---|---|
' . esc_html__('Path/Before.jpg', 'custom-file-organizer') . ' | ' . esc_html__('Path/After.jpg', 'custom-file-organizer') . ' |