Cass-E Design

Design, Experiments, Games, Resources

Upload Directory Fix WordPress Plugin

So around a week ago, every image on my site broke.

TL;DR

This plugin should allow you to hardcode your upload directory in the event that the UPLOADS constant doesn't work. This is a quick, and incredibly dirty fix. You can find it on github:

Fix-uploads-dir on github
(Sidenote: this is the Github Embed plugin by Lee Willis in action!)

Backstory

WordPress, by default, uses /wp-content/uploads for uploads, usually images. You can customize this and other directories using PHP constants, usually set in wp-config.php. WordPress briefly documents these constants here.

I use the UPLOADS constant to put my uploads in /media instead because I like it more. Until about a week ago.

I'm not sure if it was a wordpress update, a plugin, or a change with my hosting behind the scenes. I was working on developing a plugin at the time, I suspected that I'd just broken something. I tried disabling 99% of my plugins, with no dice. I triple checked the database. Etcetera. For one reason or another, wordpress started ignoring the UPLOADS constant.

Fix Uploads Dir uses the WordPress filter upload_dir to manually ater the url WordPress fetches for attachments. It's messy and far from perfect, but functional for me. I've also created a basic settings page (an act that took twice the code of the original plugin) to allow you to configure it without just hardcoding.

I guiltily hope that this has ever been an issue for someone else, so that this proves useful. I know there were approximately 0 helpful results when I started looking into this. And it'd be neat to be that helpful person once.

Previous Post

p5.js

Next Post

Uplaod