I am trying to rename images during upload to avoid problems with image file names containig special characters and file names with non-latin characters.
I found this function to rename images in WordPress:
function sanitize_file_uploads( $file ){
$file['name'] = sanitize_file_name($file['name']);
$file['name'] = preg_replace("/[^a-zA-Z0-9\_\-\.]/", "", $file['name']);
$file['name'] = strtolower($file['name']);
add_filter('sanitize_file_name', 'remove_accents');
return $file;
}
add_filter('wp_handle_upload_prefilter', 'sanitize_file_uploads');
It will remove special unaccepted characters, converts name to lowercase, and remove accents. But, for example if image has only non latin characters it will create image file name like this: jpg-width-heigh.jpg (width and height are dimensions of image).
I would like to have image file name based on current date and time like: year-month-day-hour-minute-second.jpg
I know there is plug which can do that file renaming on upload, but I do not wish to use plugin just for that.
Does anyone have solution, idea?