解除管理員的上傳文件格式限制:
在主題目錄下的functions.php
文件內添加如下代碼:
add_filter('map_meta_cap', 'wbox_upload_cap', 10, 3);
function wbox_upload_cap($caps, $cap, $user_id) {
if ($cap == 'unfiltered_upload' && is_super_admin($user_id)) {
$caps = array($cap);
}
return $caps;
}
開放中文檔名上傳且不亂碼
在主題目錄下的functions.php
文件內添加如下代碼:
/*
* All custom functions go here
* 上傳中文檔名
*/
function wp37989_fix_encoded_attachment_titles( $data ) {
if (empty( $_FILES )) {
return $data;
}
$file = current( $_FILES );
$ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
$name = wp_basename( $file['name'], ".$ext" );
$data['post_title'] = sanitize_text_field( $name );
return $data;
}
add_filter('wp_insert_attachment_data', 'wp37989_fix_encoded_attachment_titles' );