bit-part / craft-asset-trash
A Craft CMS plugin that intercepts asset deletion and moves files to a trash directory for later restoration or permanent deletion.
Package info
github.com/bit-part/craft-asset-trash
Type:craft-plugin
pkg:composer/bit-part/craft-asset-trash
Requires
- php: ^8.2
- craftcms/cms: ^5.0.0
Requires (Dev)
- phpunit/phpunit: ^10.5
README
A Craft CMS 5 plugin that provides a trash/recycle bin for deleted assets. When an asset is deleted, the file is copied to a .trash/ directory within the volume, and a database record is kept so it can be restored or permanently deleted later from the control panel.
Requirements
- Craft CMS 5.0.0 or later
- PHP 8.2 or later
Installation
Via Composer (recommended)
composer require bit-part/craft-asset-trash
Then install the plugin from the Craft control panel under Settings > Plugins, or via the CLI:
php craft plugin/install asset-trash
Manual Installation
- Download the release from GitHub
- Place the contents in a directory and add a path repository to your project's
composer.json - Run
composer require bit-part/craft-asset-trash - Install via the control panel or CLI
How It Works
When you delete an asset in Craft:
- The plugin intercepts the deletion event
- The file is copied to a
.trash/directory inside the same volume (e.g.,uploads/.trash/) - A database record is created with metadata (filename, size, volume, path, who deleted it, and element references at the time of deletion)
- Craft's normal deletion proceeds (the original asset element is removed)
The trashed file remains in .trash/ until you restore or permanently delete it.
Features
Trash Listing
A dedicated Asset Trash section appears in the control panel's primary navigation. The listing shows:
- Filename (links to detail view)
- File size
- Who deleted it
- When it was deleted
- Number of element references at the time of deletion
Volume Filtering
If you have multiple volumes, a dropdown filter lets you view trash items from a specific volume or all volumes at once.
Detail View
Click a filename to see full metadata:
- Filename, kind, and file size
- Volume name and original path (volume base path + filename)
- Title and alt text (if set)
- Deleted-by user and deletion date
- Original asset element ID
- Internal trash path
- A table of element references at the time of deletion (source element ID, type, and field ID)
Restore
Restore a trashed item to its original volume and folder. The plugin creates a new asset element and moves the file back from .trash/ to the original location. If a file with the same name already exists, a unique suffix is added automatically.
Permanent Delete
Remove a trashed item permanently. This deletes the file from .trash/ and removes the database record. This action cannot be undone.
Bulk Actions
Select multiple items using the checkboxes, then use Restore Selected or Delete Selected to act on them all at once.
Empty Trash
The Empty Trash button permanently deletes all items in the trash (or all items in the currently filtered volume). A confirmation dialog is shown before proceeding.
Auto-Purge
Expired items can be automatically purged during Craft's garbage collection. Configure the retention period and enable/disable auto-purge in the plugin settings.
Settings
Navigate to Settings > Plugins > Asset Trash to configure:
| Setting | Default | Description |
|---|---|---|
| Retention Days | 30 |
Number of days to keep trashed items before auto-purge. Set to 0 to keep items indefinitely. |
| Auto Purge | On |
When enabled, expired items are automatically deleted during Craft's garbage collection. |
| Trash Directory Name | .trash |
The directory name within each volume where trashed files are stored. Must contain only letters, numbers, dots, hyphens, and underscores. |
Permissions
The plugin registers four permissions under Asset Trash:
| Permission | Description |
|---|---|
| View trash | Access the Asset Trash section in the control panel |
| Restore assets | Restore trashed items back to their original location |
| Permanently delete assets | Permanently delete individual trashed items |
| Empty trash | Use the "Empty Trash" button to delete all items at once |
Permissions are nested: the three action permissions require the "View trash" permission to be granted first.
Translations
The plugin includes translations for:
- English (
en) - Japanese (
ja)
Support
License
This plugin is licensed under the MIT License.
Built by bit part LLC