brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: MEDIA_TRASH gives the WordPress media library a trash bin

WordPress
~/tips/tip-wordpress-media-trash-constant

define( 'MEDIA_TRASH', true );

Makes deleted media go to the trash first instead of disappearing with its files.

Delete a post and it goes to the trash. Delete an image from the media library and it is gone right away, file and all. One constant changes that.

define( 'MEDIA_TRASH', true );

WordPress defines MEDIA_TRASH as false by default. With it set to true, the media library gets a Trash view and a “Move to Trash” link instead of “Delete Permanently”. Trashed media can be restored like a post. The files stay on disk until the trash is emptied, either by hand or automatically after EMPTY_TRASH_DAYS, which is 30 days by default.

I think it is worth turning on for any site where several people manage images. Deleting the wrong photo is an easy mistake in the grid view, and without this the only way back is a backup.

It only works when EMPTY_TRASH_DAYS is not 0. Setting that to 0 turns off the trash for everything, media included, and then this constant does nothing.

Because the files stay on disk, trashing does not free any space, and a post that embeds a trashed image keeps loading it from its old URL. Space comes back only when the trash is emptied.

Further reading: wp_delete_attachment(), wp-config: Empty trash

More WordPress tips wp user application-password create anna backup-script --porcelain wp cli check-update wp theme delete --all wp media image-size wp server --host=127.0.0.1 --port=8080 All WordPress tips (85) All topics

Link