Site(fav)-icon editor (SVG), missing Drop Cropping

by Mac   Last Updated February 08, 2018 11:08 AM

I have added support for uploading of SVG files to my WP theme, and got it mostly working. When editing the Logo i can choose the "Drop Cropping" option, on the media editor - but when trying to edit/change the site(fav)-icon, i cant choose to drop cropping.

add_action('upload_mimes', 'add_file_types_to_uploads');
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_filter('wp_prepare_attachment_for_js', 'svg_media_thumbnails', 10, 3);
function 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  = 50;
                $height = 50;

                //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;
}

and finally add_theme_support:

    'flex-height' => true,
    'flex-width'  => true,


Related Questions


How to destroy or dispose wordpress uploder/manager?

Updated February 26, 2017 18:08 PM


Get attachments by user

Updated June 07, 2015 10:03 AM


Adding wp_enqueue_media(); causes problem

Updated September 24, 2016 09:03 AM