Generate a Random File Name when Uploading Files in WordPress

The passage is telling you how to rename the file name automatically by WordPress (without using any plugins).

A Word of Warning

Warning: To apply this hack, you’ll have to edit one of WordPress’s core files. Keep in mind that it is never recommended. This hack should be redone if you upgrade WordPress.

Editing the Upload Handler

Open the wp-admin/includes/files.php file, and go to line 324 (approximately here). You’ll see the following:

$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );

Change it as follows:

$time_filename = "";
if ($time) {
    $time_filename = $time;
    $time_filename = str_replace(["-", " ", ":"], "", $time_filename);
} else {
    $time_filename = date("YmdHis");
}
$filename = $time_filename . dechex(mt_rand(65536, 1048575)) . "." . $ext;

The Result

And the file you upload will automatically be renamed as 20130218180059a1b2c.ext.

A Modern Alternative

Editing a core file is fragile, since the change is lost on every WordPress upgrade. On modern WordPress you can do the same thing without touching core by hooking into wp_handle_upload_prefilter from your theme’s functions.php (or a small plugin):

add_filter('wp_handle_upload_prefilter', function ($file) {
    $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
    $file['name'] = date('YmdHis') . dechex(mt_rand(65536, 1048575)) . '.' . $ext;
    return $file;
});

This runs before the file is moved into place, so the rest of the upload pipeline picks up the new name automatically.