devuri / wp-filename-hasher
Automatically renames uploaded files/images in WordPress to a unique hashed filename.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 2
Type:wordpress-plugin
Requires
- php: ^7.3 || ^7.4 || ^8.0 || ^8.1
- ext-curl: *
- ext-json: *
Requires (Dev)
- 10up/phpcs-composer: dev-master
- ergebnis/composer-normalize: ^2.42
- fakerphp/faker: ^1.23
- phpstan/phpstan: ^1.10
- symfony/var-dumper: ^5.4
- szepeviktor/phpstan-wordpress: ^1.3
- vimeo/psalm: ^5.25
- yoast/phpunit-polyfills: ^2.0
This package is auto-updated.
Last update: 2024-12-02 22:30:33 UTC
README
Description
The File Name Hasher
plugin automatically renames uploaded files (images and PDFs) in WordPress to unique, hashed filenames. This helps to avoid conflicts with existing filenames and enhances security by generating unpredictable names for uploaded files.
Features
- Automatically renames uploaded images and PDFs to hashed filenames.
- Ensures unique filenames for each uploaded file.
- Enhances security by making filenames unpredictable.
- Only hashes specific file types (images and PDFs), leaving other file types with their original names.
Installation
- Download the
File Name Hasher
plugin. - Extract the plugin files to the
wp-content/plugins/
directory of your WordPress installation. - Activate the plugin through the 'Plugins' menu in WordPress.
Usage
Once activated, the plugin will automatically rename any image or PDF uploaded through the WordPress media uploader. No further configuration is required.
How It Works
- Initialization: The plugin hooks into the
wp_handle_upload_prefilter
filter during its construction. - File Type Check: When a file is uploaded, the plugin checks the file's extension to see if it matches one of the allowed file types (images and PDFs).
- Renaming Process: If the file type is allowed:
- The plugin generates a unique ID using
random_bytes
. - The unique ID is hashed using the SHA-256 algorithm.
- The hashed ID is combined with the original file extension to create the new filename.
- The original filename is replaced with the new hashed filename.
- The plugin generates a unique ID using
- File Upload: The file is uploaded with the new hashed filename.
- Tracking Hashed Files: The plugin keeps track of all hashed filenames during the current session, allowing you to check if a file has already been renamed.
Example
An image uploaded with the original name example.jpg
might be renamed to something like 3d4b2f4c8d9e1a6b2f3a123456789abc123456789abc123456789abc12345678.jpg
.
License
This plugin is open-source and licensed under the GPL-2.0-or-later license.
Support
For any issues or feature requests, please open an issue on the plugin's GitHub repository.