我以前曾在我的职能范围内使用过这段代码。php文件,用于为上传到我的网站的SVG启用和创建缩略图:
// ALLOW SVG
function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes[\'svg\'] = \'image/svg+xml\';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
}
add_action(\'upload_mimes\', \'add_file_types_to_uploads\');
function common_svg_media_thumbnails($response, $attachment, $meta){
if($response[\'type\'] === \'image\' && $response[\'subtype\'] === \'svg+xml\' && class_exists(\'SimpleXMLElement\'))
{
try {
$path = get_attached_file($attachment->ID);
if(@file_exists($path))
{
$svg = new SimpleXMLElement(@file_get_contents($path));
$src = $response[\'url\'];
$width = (int) $svg[\'width\'];
$height = (int) $svg[\'height\'];
//media gallery
$response[\'image\'] = compact( \'src\', \'width\', \'height\' );
$response[\'thumb\'] = compact( \'src\', \'width\', \'height\' );
//media single
$response[\'sizes\'][\'full\'] = array(
\'height\' => $height,
\'width\' => $width,
\'url\' => $src,
\'orientation\' => $height > $width ? \'portrait\' : \'landscape\'
);
}
}
catch(Exception $e){}
}
return $response;
}
add_filter(\'wp_prepare_attachment_for_js\', \'common_svg_media_thumbnails\', 10, 3);
// END ALLOW SVG
我正在尝试将此代码复制到新站点,但仍收到错误:
"logo.svg” has failed to upload.
Sorry, this file type is not permitted for security reasons.
此网站位于非WordPress网站的子目录中,如:
www.example.co.uk/SITE_DIRECTORY/wp-content/themes/THEME_NAME/functions.php
我是不是错过了让这一切正常运转的一步?
~请不要引用插件。
~请帮我获取这段代码片段,该代码片段之前已被证明在其他网站上有效;在这个新网站上工作。
谢谢,杰森。