-
-
Save Lewiscowles1986/44f059876ec205dd4d27 to your computer and use it in GitHub Desktop.
<?php | |
// Please see https://github.com/Lewiscowles1986/WordPressSVGPlugin from now on |
I have the same problem. Jpg's can't be uploaded for some reason. Any suggestions? Thanks!
Hello, same here, and for png's too. Here a solution that seems to work
add_action('admin_init', 'add_svg_upload');
function add_svg_upload() {
add_filter('upload_mimes', 'svg_upload_mimes');
ob_start();
add_action('shutdown', function() {
$final = '';
$ob_levels = count(ob_get_level());
for ($i = 0; $i < $ob_levels; $i++) {
$final .= ob_get_clean();
}
echo apply_filters('final_output', $final);
}, 0);
add_filter('final_output', function($content) {
$content = str_replace('<# } else if ( 'image' === data.type && data.sizes && data.sizes.full ) { #>',
'<# } else if ( 'svg+xml' === data.subtype ) { #>
<# } else if ( 'image' === data.type && data.sizes && data.sizes.full ) { #>',
$content
);
$content = str_replace(
'<# } else if ( 'image' === data.type && data.sizes ) { #>',
'<# } else if ( 'svg+xml' === data.subtype ) { #>
<# } else if ( 'image' === data.type && data.sizes ) { #>',
$content
);
return $content;
});
}
function svg_upload_mimes($existing_mimes=array()){
$existing_mimes['svg'] = 'image/svg+xml';
return $existing_mimes;
}
Oh hey guys, didn't see your comments there. JPG and PNG work from 4.1.2 until the most recent version, please check your other plugins and theme first ;)
Also I noticed the only mod was to existing_mimes being passed to the function, please link code in gists, you can fork them and it looks much better. I Have added it in as it does look like $mimes is appearing from nowhere, but it seems to work... strange.
hey lewis,
great plugin!
still there are things need to be done to make it perfect:
– if i add a svg to the tinymce field like a normal picture the height is 1 x 1 px
i tried many things with the first point but somehow my admin css does not grab the image in the tinymce at all.
Hey buddy,
weird for sure, just checked it out, the 1px x 1px error is WP internal, but I'll see what I can do to remit.
any news on this?
hey lewis did you check on this issue, it not a small one if you want to use svg in your site content.
@telemarker, the 1px x 1px is probably a problem with your CSS rules, you may need to pass new rules to tinyMCE about your grid or container CSS
Update to give multiple 🖕 to WP 4.5+ new custom logo incompatibility
Umm, I tried to activate and got this exception:
Plugin could not be activated because it triggered a fatal error.
Parse error: syntax error, unexpected '[' in /nas/content/staging/cpsbop/wp-content/plugins/lc-svg-upload.php on line 15
Advice?
Yes, Goldnate, I have the same problem. I had to revert back to plugin version 1.4.
Just weighing in here -- I decided to remove the sanitization from my plugin mentioned above. The goal of the plugin is to enable the easy utilization of SVG, not to provide safety.
I think security plugins could do a better job about scanning files and such for that. I've chosen to narrow the focus of my plugin 😃
@grok, thanks for the update, I really do like what you have done with your plugin. Checkout the GitHub repo for some third-party contributed code (merge maybe?)
This is a great! Just what I needed. I did notice something and I am not sure if it is just me, but when enable the plugin I can upload SVG, but then I can't upload jpg's giving me an error message "Sorry, this file type is not permitted for security reasons". Is there something that I am missing?
Thanks, in advance