WordPress 常用 Function

// WordPress 檔案上傳後自動改名 
function make_filename_hash($filename) {
    $info = pathinfo($filename);
    $ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
    // $name = basename($filename, $ext);
    // return md5($name) . $ext;
    return date("Ymd_His") . $ext;
}
add_filter('sanitize_file_name', 'make_filename_hash', 10);
// 停用自動新增分割圖片功能
function chnage_filter_image_sizes($sizes){
    $sizes = array();
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'chnage_filter_image_sizes');
// 修改 WordPress 過期時間(TimeOut)的設定
 function keep_me_logged_in_for_times( $expirein )
 {
     return 31556926;
 }
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_times' );
// WordPress使用兩種模組來處理你上傳的圖片
// 分別是GD Library以及Imagick。這兩個不會同時使用,WP會使用任何一個取決於當時誰有空就找誰。
 function wpb_image_editor_default_to_gd( $editors ) {
    $gd_editor = 'WP_Image_Editor_GD';
    $editors = array_diff( $editors, array( $gd_editor ) );
    array_unshift( $editors, $gd_editor );
    return $editors;
}
add_filter( 'wp_4_image_editors', 'wpb_image_editor_default_to_gd' );

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *