Modify the folder structure used to upload media files into years

Context

ClassicPress by default sorts media uploads into year and month subfolders. This is a remnant of the days when WP was primarily a blog and new posts were being made weekly or monthly. Month folders are also created automatically which results in a lot of empty folders.

For many users, the first thing they do on a new site is to uncheck this and put all media files into one big folder. However, this can become unwieldy and cause issues with ftp when files start to number many thousands.

I think a good compromise is to keep the option but make it years only.

Possible implementation

I have started to implement this on my sites using a few lines of code in my utility plugin. I’ve just been testing it and it seems to work fine. There is no issue with older media that is still there in the previously created month/date folders.

add_filter( 'option_uploads_use_yearmonth_folders', '__return_false', 100 );
$year = date( 'Y' );
define( 'UPLOADS', 'wp-content/uploads/' . $year );

It would probably also make sense to modify the date selector dropdown box in the media library. I’m not sure how this works or how hard it would be, but I imagine it picking up both the previous year/month folders (if they exist) and all the images in the year folder, eg

Or if it’s easier, just pick up the years (ie include all images in the year and its subfolders).

Will you be able to help with the implementation?

I can’t help with coding, but I can test it out.

Your petition might be a good compromise, but your code will only work for one year.
I answered a WP forum question on exactly this. The person wanted to know why they could only access the current year’s stuff.
The date selector is an unrelated topic. Those dates are from the database, not the file system.

1 Like

The date system for images is of no use to me generally and neither would one big folder. I would much prefer to be able to sort them by category.
I find for the business sites that I do, that would have images from the original pages and posts that have been added over several years, finding an image to reuse in a new post is a real pain and sometimes not worth the effort.
There was a plugin I used to use that let you create and name image folders, and move images into these folders.
If the image was already in use, and you moved the image to a new folder it updated the urls in the original posts or pages.

4 Likes

This would be a separate petition.

2 Likes

That sounds like a useful plugin. I’d certainly use it.

4 Likes

The plugin is
Media File Manager | By Atsushi Ueda
You can make sub-directories in the upload directory, and move files into them. At the same time, this plugin modifies the URLs/path names in the database. Also an alternative file-selector is added in the editing post/page screen, so you can pick up media files from the subfolders easily.
The version I have is Version 1.2.1

I have just installed it on a CP site and it seems to work with out issues.
I can not find it in wordpress plugins and authors site is no longer online.

Found this on github

Tried installing it on CP site but could not get it to work, (does not crash, just gives a blank screen)

3 Likes

I used to daydream about setting the uploads media path in a similar way as setting permalinks:

That looks complicated, as an implementation. :grimacing:

Howdy, new around here. One alternative is to use the Nextcellent Gallery plugin to organise media. It won’t, of course, resolve the stuff already in the WP Media library.

The advantages are that you can make folders for whatever division you prefer.

As an example, sometimes I post a single photo, and I might do that several times in a row. Those photos go in a Gallery called 22Singles, which I could also post all of them at once as a Gallery by choosing that option when inserting the shortcode.

Otherwise, a series of images are uploaded to a gallery that today might be called 220428ForestHike. From which I could also post individual images.

While I’m in a Gallery I can rename the file name and caption that will be visible and reorder them drag-and-drop for preferred presentation.

And, if someone decides to hotlink my work, I can simply change the top-level folder containing all of the galleries by adding one letter, then changing the path in Nextcellent’s Admin panel. I typically just add an x or z or make it two of them, but I keep mixing that up and after I’m done those images won’t load elsewhere but my site looks as usual.

Does it use real or virtual folders?

The plugin makes a folder called gallery in wp-content and then makes real folders with all the image versions inside, which are named the same as the gallery in the app. Inside each gallery folder are the original backed-up and the resized version for display. There’s a subfolder called thumbs for those.

e.g. you could rename that top folder tkgallery and then change the path in Nextcellent’s admin panel and it would work the same with all the galleries being found. Not a feature everyone would use, it does make me happier when I can easily deal with the back end.

Real folders means I will check it out. Thanks!

I’m new here, if it’s impossible to find a copy in the wild I can upload a zip somewhere if we do that here.

Just checked, still there…https://wordpress.org/plugins/nextcellent-gallery-nextgen-legacy/#reviews

Also, looking through my plugins, there’s one called Media Library Folders for WordPress, which creates actual folders in your WordPress Media Library:

Actual folders make it easier to organize your WordPress media library while reducing server burden.
Add and build new Media library folders to label and organize as you wish instead of just month/date.
Move, copy, rename and delete files and folders with a nice drag and drop interface
Regenerate thumbnails.
SEO Images to specify ALT and TITLE attributes when uploading.
Sync folders/files when moving or uploading a folder via FTP.
Create a MaxGalleria gallery.

MLF adds to and works with the functionality of WordPress Media Library. It does not replace it.

Here in the WP Plugin listing…https://wordpress.org/plugins/media-library-plus/

I once used one called Foo Gallery, IIRC, can’t find it now. It organised Media images somehow.

Neither of those was as useful and easy to me as Next-Gen/Nextcellent Gallery, which also connect with Media but only one way. Media will select images from NGG and insert them, but not vice-versa.

I tried Nextcellent. It’s not for me. For a start, activating it brought me the following message:

The plugin generated 1054 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

It also has deprecated functions. I could fix them, but, what with the “headers already sent” issue and the fact that I really don’t like the interface, I don’t see the point.

Media Library Folders is a plugin I’ve tried before. Very messy and quite bloated! Although it might currently be the best option for creating real media folders, I dislike it so much that I have stopped using it.

1 Like

I agree with your initial impression. I disliked it at first, even without error messages when it was commercially developed as NextGen Gallery. eventually I have found it indispensable, esp compared to WP’s clunky Media, but it is obscure at first no doubt.