wp-hash-filename.php
701 字节
<?php
/**
* Plugin Name: Hash Filename
* Plugin URI: goodao.cn
* Description: goodao.cn
* Version: 1.0
* Author: goodao.cn
* Author URI: http://www.goodao.cn/
* License: goodao.cn
* License URI: goodao.cn
*/
if ( ! defined( 'ABSPATH' ) ) exit;
//过滤中文字符
function make_filename_hash($filename) {
if(!preg_match("/^[A-Za-z0-9`~!@#$%^&*()_\-+=<>?:{}|,.\/;'\\[\]·]+$/u",$filename)){
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
return substr(md5($name),6,8) . $ext;
}else{
return $filename;
}
}
add_filter('sanitize_file_name', 'make_filename_hash', 10);