2017-05-24 5 views
-3

私はfunction.phpのWordPress Codexからこのフィルタを使用して、svg、svgz、およびdxfファイルのアップロードを許可しています。しかし、私がアップロードしたすべてのアップロードされたテストファイルは、WordPressのセキュリティ上の理由で拒否されました。これを稼働させるために注意を払わなければならないことはもうありますか?コードと参照アーロンのためアップロードママのためのWordpressフィルタのデバッグ

function my_custom_mime_types($mimes) { 

    // New allowed mime types. 
    $mimes['svg'] = 'image/svg+xml'; 
    $mimes['svgz'] = 'image/svg+xml'; 
    $mimes['dxf'] = 'application/dxf'; 


return $mimes; 
} 
add_filter('upload_mimes', 'my_custom_mime_types'); 
+0

はそれがスパムの方法のいくつかの新しい種類のですか?私は自分の時間を失うことを好まない – Kaddath

答えて

1

As of wordpress 4.7.1 this is a fix

// Allow SVG 
add_filter('wp_check_filetype_and_ext', function($data, $file, $filename, 
$mimes) { 

    global $wp_version; 
    if ($wp_version !== '4.7.1') { 
    return $data; 
    } 

    $filetype = wp_check_filetype($filename, $mimes); 

    return [ 
     'ext'    => $filetype['ext'], 
     'type'   => $filetype['type'], 
     'proper_filename' => $data['proper_filename'] 
    ]; 

}, 10, 4); 

function cc_mime_types($mimes){ 
    $mimes['svg'] = 'image/svg+xml'; 
    $mimes['svgz'] = 'image/svg+xml'; 
    $mimes['dxf'] = 'application/dxf'; 
    return $mimes; 
} 
add_filter('upload_mimes', 'cc_mime_types'); 

function fix_svg() { 
    echo '<style type="text/css"> 
    .attachment-266x266, .thumbnail img { 
     width: 100% !important; 
     height: auto !important; 
    } 
    </style>'; 
} 
add_action('admin_head', 'fix_svg'); 
1

ありがとう!

私はあなたが手動でWPのバージョンを変更する必要はありませんので、私はcodepenに見つけることができるいくつかの適応を取っ:

function relationship_options_filter($options, $field, $the_post) { 
    $options[‘post_status’] = array(‘publish’); 
    return $options; 
} 
add_filter('acf/fields/post_object/query/key=field_59074524ac92e', 'relationship_options_filter', 10, 3); 


// Allow SVG 
add_filter('wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) { 

    global $wp_version; if($wp_version == '4.7' || ((float) $wp_version < 4.7)) { return $data; } 

    $filetype = wp_check_filetype($filename, $mimes); 

    return [ 'ext' => $filetype['ext'], 'type' => $filetype['type'], 'proper_filename' => $data['proper_filename'] ]; 

}, 10, 4); 

function cc_mime_types($mimes){ 
    $mimes['svg'] = 'image/svg+xml'; 
    $mimes['svgz'] = 'image/svg+xml'; 
    $mimes['dxf'] = 'image/x-dwg'; 

    return $mimes; 
} 
add_filter('upload_mimes', 'cc_mime_types'); 

function fix_svg() { 
    echo '<style type="text/css"> 
    .attachment-266x266, .thumbnail img { 
     width: 100% !important; 
     height: auto !important; 
    } 
    </style>'; 
} 
add_action('admin_head', 'fix_svg'); 
関連する問題