日度归档:2017-02-20

wordpress上传文件自动按日期更名

<?php
/*
Plugin Name: Uploaded Filename Sanitizer
Plugin URI: http://jerry.red/143.html
Description: 将所有上传的文件使用“日期_时间_三位随机数”方式重命名
Version: 1.0
Author: jerry
Author URI: http://jerry.red/
*/

function custom_upload_filter($name)
{
    $time = date('Ymd_His');
    $rand = sprintf('%03d', mt_rand(0, 999));
    $ext  = pathinfo($name, PATHINFO_EXTENSION);
    return "{$time}_{$rand}.{$ext}";
}

add_filter('sanitize_file_name', 'custom_upload_filter');

把这段代码另存为 uploaded-filename-sanitizer.php,上传到 wp-content/plugins 目录下,然后在后台启用这个插件即可。
如果不想以插件的形式使用,可以把这段代码粘贴到当前 WordPress 主题的 functions.php 中。请去掉本代码第一行的 <?php 和注释。

WordPress禁用自动更新邮件通知

将下面的代码添加到当前主题的 functions.php 中:

add_filter( 'auto_core_update_send_email', 'wpb_stop_auto_update_emails', 10, 4 );
function wpb_stop_update_emails( $send, $type, $core_update, $result ) {
if ( ! emptyempty( $type ) && $type == 'success' ) {
return false;
}
return true;
}

以上代码通过添加一个过滤器禁用自动更新邮件通知功能。