lonelyplanet/append-file-hash

Append a file hash to file names for media library uploads.

Installs: 141

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 0

Type:wordpress-plugin

1.0.2 2018-01-31 20:45 UTC

This package is auto-updated.

Last update: 2022-05-11 09:36:52 UTC


README

This WordPress plugin will append a file hash to file names for media library uploads.

Installation

composer require lonelyplanet/append-file-hash

Filters

Customize the file hash

By default, this plugin will use the md5_file hash and append it to the filename. If you'd like to customize the hash, you can use the afh-file-hash filter.

In this example, the sha1 file hash is returned.

function sha1FileHash($hash, $data, $filepath, $filename, $mimes)
{
    return sha1_file($filepath);
}

add_filter('afh-file-hash', 'sha1FileHash', 10, 5);

Customize the proper filename

function customProperFilename($properFilename, $cleanFilename, $hash, $ext, $filepath, $mimes)
{
    // Build your filename here.

    return $properFilename;
}

add_filter('afh-proper-filename', 'customProperFilename', 10, 6);