添加媒体自动按日期重命名:
function rename_wp_handle_upload_prefilter($file){ $time=date("Y-m-d"); $file['name'] = $time."".mt_rand(1,100).".".pathinfo($file['name'] , PATHINFO_EXTENSION); return $file; } add_filter('wp_handle_upload_prefilter', 'rename_wp_handle_upload_prefilter');
添加媒体自动按 Hash 重命名:
function make_filename_hash($filename) { $info = pathinfo($filename); $ext = empty($info['extension']) ? '' : '.' . $info['extension']; $name = basename($filename, $ext); return md5($name) . $ext; } add_filter('sanitize_file_name', 'make_filename_hash', 10);
发表回复