GithubHelp home page GithubHelp logo

creunafi / unique-media-file-folders Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 0.0 35 KB

Change the default WordPress upload folder structure to a randomly generated one

License: GNU General Public License v2.0

PHP 100.00%
wordpress-plugin wp-plugin wordpress uuid

unique-media-file-folders's Introduction

Unique Media File Folders

Build Status Packagist

Change the default WordPress upload folder structure to a randomly generated one. Each image and its thumbnails will be given an unique folder with a randomly generated name.

Why?

Because WordPress default media file paths are not very good. You either get year-month folders which may look funny if you are re-using content and is reminiscent of WordPress' blogging engine roots. The other option is to put all files into one folder which does not scale when you start to have a lot of files.

Too many files in a folder can lead to performance issues on filesystems like EXT4. If all your files are in the same folder, you’ll also run into file name conflicts.

How it works

Instead of the following file paths:

https://example.com/wp-content/uploads/2019/01/photo.jpg
https://example.com/wp-content/uploads/2019/01/photo-150x150.jpg
https://example.com/wp-content/uploads/2019/01/photo-300x168.jpg

https://example.com/wp-content/uploads/2019/01/image.png
https://example.com/wp-content/uploads/2019/01/image-150x150.png
https://example.com/wp-content/uploads/2019/01/image-300x168.png

The plugin will generate the following paths:

https://example.com/wp-content/uploads/cnk3nae60p6f3e942b4cpvm8q/photo.jpg
https://example.com/wp-content/uploads/cnk3nae60p6f3e942b4cpvm8q/photo-150x150.jpg
https://example.com/wp-content/uploads/cnk3nae60p6f3e942b4cpvm8q/photo-300x168.jpg

https://example.com/wp-content/uploads/2xv5r4tnlrcodofcq3ageksmb/image.png
https://example.com/wp-content/uploads/2xv5r4tnlrcodofcq3ageksmb/image-150x150.png
https://example.com/wp-content/uploads/2xv5r4tnlrcodofcq3ageksmb/image-300x168.png

How to install

  1. Download latest version from the Releases tab
  2. Unzip the plugin into your wp-content/plugins directory
  3. Activate Unique Media File Folders from your Plugins page

Customizing folder depth

By default, folder depth is 1 so every file will be given its own folder. Customize folder depth using umff_folder_depth filter. For example:

add_filter('umff_folder_depth', function() {
    return 4;
});

Will yield the following folder structure:

https://example.com/wp-content/uploads/c/n/k/3nae60p6f3e942b4cpvm8q/photo.jpg
https://example.com/wp-content/uploads/c/n/k/3nae60p6f3e942b4cpvm8q/photo-150x150.jpg
https://example.com/wp-content/uploads/c/n/k/3nae60p6f3e942b4cpvm8q/photo-300x168.jpg

https://example.com/wp-content/uploads/2/x/v/5r4tnlrcodofcq3ageksmb/image.png
https://example.com/wp-content/uploads/2/x/v/5r4tnlrcodofcq3ageksmb/image-150x150.png
https://example.com/wp-content/uploads/2/x/v/5r4tnlrcodofcq3ageksmb/image-300x168.png

How are paths generated

For all of your files, first a UUID4 will be generated. It will then be encoded into Base36 which means it will contain characters from a to z and 0 to 9. This is used as the folder name. If folder depth option is greater than 1, first n characters of the UUID are used as subfolders.

Further reading

Structuring WordPress’ upload directory to handle lots of files - Ctrl blog

unique-media-file-folders's People

Contributors

joppuyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.