SVG Support - Version 2.3.16

Version Description

  • Fix for files that have the XML declaration.
  • Fix for PHP warnings from image widget.
  • Some small CSS changes to the frontend when displaying SVG media attachments.
Download this release

Release Info

Developer Benbodhi
Plugin Icon 128x128 SVG Support
Version 2.3.16
Comparing to
See all releases

Code changes from version 2.3.15 to 2.3.16

css/svgs-attachment.css CHANGED
@@ -1 +1 @@
1
- .attachment img[src$=".svg"],.widget_media_image img[src$=".svg"]{width:100%}.attachment img[src$=".svg"],.widget_media_image img[src$=".svg"]{width:100%}.attachment svg,.widget_media_image svg{max-width:100%;height:auto}
1
+ .attachment svg,.widget_media_image svg{max-width:100%;height:auto}
functions/attachment-modal.php DELETED
@@ -1,57 +0,0 @@
1
- <?php
2
- /**
3
- * Display SVG in attachment modal
4
- */
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit; // Exit if accessed directly
7
- }
8
-
9
- function bodhi_svgs_response_for_svg( $response, $attachment, $meta ) {
10
-
11
- if ( $response['mime'] == 'image/svg+xml' && empty( $response['sizes'] ) ) {
12
-
13
- $svg_path = get_attached_file( $attachment->ID );
14
-
15
- if ( ! file_exists( $svg_path ) ) {
16
- // If SVG is external, use the URL instead of the path
17
- $svg_path = $response['url'];
18
- }
19
-
20
- $dimensions = bodhi_svgs_get_dimensions( $svg_path );
21
-
22
- $response['sizes'] = array(
23
- 'full' => array(
24
- 'url' => $response['url'],
25
- 'width' => $dimensions->width,
26
- 'height' => $dimensions->height,
27
- 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait'
28
- )
29
- );
30
-
31
- }
32
-
33
- return $response;
34
-
35
- }
36
- add_filter( 'wp_prepare_attachment_for_js', 'bodhi_svgs_response_for_svg', 10, 3 );
37
-
38
- function bodhi_svgs_get_dimensions( $svg ) {
39
-
40
- $svg = simplexml_load_file( $svg );
41
-
42
- if ( $svg === FALSE ) {
43
-
44
- $width = '0';
45
- $height = '0';
46
-
47
- } else {
48
-
49
- $attributes = $svg->attributes();
50
- $width = (string) $attributes->width;
51
- $height = (string) $attributes->height;
52
-
53
- }
54
-
55
- return (object) array( 'width' => $width, 'height' => $height );
56
-
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
functions/attachment.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Display SVG in attachment modal
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit; // Exit if accessed directly
7
+ }
8
+
9
+ function bodhi_svgs_response_for_svg( $response, $attachment, $meta ) {
10
+
11
+ if ( $response['mime'] == 'image/svg+xml' && empty( $response['sizes'] ) ) {
12
+
13
+ $svg_path = get_attached_file( $attachment->ID );
14
+
15
+ if ( ! file_exists( $svg_path ) ) {
16
+ // If SVG is external, use the URL instead of the path
17
+ $svg_path = $response['url'];
18
+ }
19
+
20
+ $dimensions = bodhi_svgs_get_dimensions( $svg_path );
21
+
22
+ $response['sizes'] = array(
23
+ 'full' => array(
24
+ 'url' => $response['url'],
25
+ 'width' => $dimensions->width,
26
+ 'height' => $dimensions->height,
27
+ 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait'
28
+ )
29
+ );
30
+
31
+ }
32
+
33
+ return $response;
34
+
35
+ }
36
+ add_filter( 'wp_prepare_attachment_for_js', 'bodhi_svgs_response_for_svg', 10, 3 );
37
+
38
+ function bodhi_svgs_get_dimensions( $svg ) {
39
+
40
+ $svg = simplexml_load_file( $svg );
41
+
42
+ if ( $svg === FALSE ) {
43
+
44
+ $width = '0';
45
+ $height = '0';
46
+
47
+ } else {
48
+
49
+ $attributes = $svg->attributes();
50
+ $width = (string) $attributes->width;
51
+ $height = (string) $attributes->height;
52
+
53
+ }
54
+
55
+ return (object) array( 'width' => $width, 'height' => $height );
56
+
57
+ }
58
+
59
+ /**
60
+ * Generate attachment metadata (Thanks @surml)
61
+ *
62
+ * Fixes Illegal String Offset Warning for Height & Width
63
+ */
64
+ function bodhi_svgs_generate_svg_attachment_metadata( $metadata, $attachment_id ) {
65
+
66
+ $mime = get_post_mime_type( $attachment_id );
67
+
68
+ if ( $mime == 'image/svg+xml' ) {
69
+
70
+ $svg_path = get_attached_file( $attachment_id );
71
+ $upload_dir = wp_upload_dir();
72
+ // get the path relative to /uploads/ - found no better way:
73
+ $relative_path = str_replace($upload_dir['basedir'], '', $svg_path);
74
+ $filename = basename( $svg_path );
75
+
76
+ $dimensions = bodhi_svgs_get_dimensions( $svg_path );
77
+
78
+ $metadata = array(
79
+ 'width' => intval($dimensions->width),
80
+ 'height' => intval($dimensions->height),
81
+ 'file' => $relative_path
82
+ );
83
+
84
+ // Might come in handy to create the sizes array too - But it's not needed for this workaround! Always links to original svg-file => Hey, it's a vector graphic! ;)
85
+ $sizes = array();
86
+ foreach ( get_intermediate_image_sizes() as $s ) {
87
+ $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false );
88
+ if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
89
+ $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
90
+ else
91
+ $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
92
+ if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
93
+ $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
94
+ else
95
+ $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
96
+ if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
97
+ $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
98
+ else
99
+ $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
100
+
101
+ $sizes[$s]['file'] = $filename;
102
+ $sizes[$s]['mime-type'] = 'image/svg+xml';
103
+ }
104
+ $metadata['sizes'] = $sizes;
105
+ }
106
+
107
+ return $metadata;
108
+ }
109
+ add_filter( 'wp_generate_attachment_metadata', 'bodhi_svgs_generate_svg_attachment_metadata', 10, 3 );
110
+
111
+ // Fix image widget PHP warnings
112
+ function bodhi_svgs_get_attachment_metadata( $data ) {
113
+
114
+ $res = $data;
115
+
116
+ if ( !isset( $data['width'] ) || !isset( $data['height'] ) ) {
117
+ $res = false;
118
+ }
119
+
120
+ return $res;
121
+
122
+ }
123
+ add_filter( 'wp_get_attachment_metadata' , 'bodhi_svgs_get_attachment_metadata' );
functions/mime-types.php CHANGED
@@ -3,7 +3,7 @@
3
  * Add SVG mime types to WordPress
4
  *
5
  * Allows you to upload SVG files to the media library like any other image.
6
- * Additionally provides a fix for WP 4.7.1 - 4.7.2 upload issues.
7
  */
8
  if ( ! defined( 'ABSPATH' ) ) {
9
  exit; // Exit if accessed directly
@@ -31,8 +31,31 @@ function bodhi_svgs_upload_mimes( $mimes = array() ) {
31
  }
32
 
33
  }
34
- add_filter( 'upload_mimes', 'bodhi_svgs_upload_mimes' );
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  /**
38
  * Mime Check fix for WP 4.7.1 / 4.7.2
@@ -40,18 +63,20 @@ add_filter( 'upload_mimes', 'bodhi_svgs_upload_mimes' );
40
  * Fixes uploads for these 2 version of WordPress.
41
  * Issue was fixed in 4.7.3 core.
42
  */
43
- global $wp_version;
44
- if ( $wp_version == '4.7.1' || $wp_version == '4.7.2' ) {
45
- add_filter( 'wp_check_filetype_and_ext', 'bodhi_svgs_disable_real_mime_check', 10, 4 );
46
- }
47
- function bodhi_svgs_disable_real_mime_check( $data, $file, $filename, $mimes ) {
48
 
49
- $wp_filetype = wp_check_filetype( $filename, $mimes );
 
 
 
50
 
51
- $ext = $wp_filetype['ext'];
52
- $type = $wp_filetype['type'];
53
- $proper_filename = $data['proper_filename'];
54
 
55
- return compact( 'ext', 'type', 'proper_filename' );
 
 
 
 
56
 
57
  }
 
3
  * Add SVG mime types to WordPress
4
  *
5
  * Allows you to upload SVG files to the media library like any other image.
6
+ * Additionally provides a fix for WP 4.7.1 - 4.7.2 upload issues and for Avada theme.
7
  */
8
  if ( ! defined( 'ABSPATH' ) ) {
9
  exit; // Exit if accessed directly
31
  }
32
 
33
  }
34
+ add_filter( 'upload_mimes', 'bodhi_svgs_upload_mimes', 99 );
35
 
36
+ /**
37
+ * Check Mime Types
38
+ */
39
+ function bodhi_svgs_upload_check( $checked, $file, $filename, $mimes ) {
40
+
41
+ if ( ! $checked['type'] ) {
42
+
43
+ $check_filetype = wp_check_filetype( $filename, $mimes );
44
+ $ext = $check_filetype['ext'];
45
+ $type = $check_filetype['type'];
46
+ $proper_filename = $filename;
47
+
48
+ if ( $type && 0 === strpos( $type, 'image/' ) && $ext !== 'svg' ) {
49
+ $ext = $type = false;
50
+ }
51
+
52
+ $checked = compact( 'ext','type','proper_filename' );
53
+ }
54
+
55
+ return $checked;
56
+
57
+ }
58
+ add_filter( 'wp_check_filetype_and_ext', 'bodhi_svgs_upload_check', 10, 4 );
59
 
60
  /**
61
  * Mime Check fix for WP 4.7.1 / 4.7.2
63
  * Fixes uploads for these 2 version of WordPress.
64
  * Issue was fixed in 4.7.3 core.
65
  */
66
+ function bodhi_svgs_allow_svg_upload( $data, $file, $filename, $mimes ) {
 
 
 
 
67
 
68
+ global $wp_version;
69
+ if ( $wp_version !== '4.7.1' || $wp_version !== '4.7.2' ) {
70
+ return $data;
71
+ }
72
 
73
+ $filetype = wp_check_filetype( $filename, $mimes );
 
 
74
 
75
+ return [
76
+ 'ext' => $filetype['ext'],
77
+ 'type' => $filetype['type'],
78
+ 'proper_filename' => $data['proper_filename']
79
+ ];
80
 
81
  }
82
+ add_filter( 'wp_check_filetype_and_ext', 'bodhi_svgs_allow_svg_upload', 10, 4 );
readme.txt CHANGED
@@ -1,19 +1,23 @@
1
  === SVG Support ===
2
  Contributors: Benbodhi
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z9R7JERS82EQQ
4
- Tags: svg, vector, css, style, mime, mime type, embed, img, inline, animation, animate, js
5
  Requires at least: 4.8
6
- Tested up to: 5.0-alpha-42993
7
  Requires PHP: 5.2
8
- Stable tag: 2.3.15
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
- Upload SVG files to the Media Library and render SVG files inline for direct styling/animation of an SVG's internal elements using CSS/JS.
13
 
14
 
15
  == Description ==
16
 
 
 
 
 
17
  When using SVG images on your WordPress site, it can be hard to style elements within the SVG using CSS. **Now you can, easily!**
18
 
19
  Scalable Vector Graphics (SVG) are becoming common place in modern web design, allowing you to embed images with small file sizes that are scalable to any visual size without loss of quality.
@@ -82,7 +86,7 @@ As with allowing uploads of any files, there is potential risks involved. Only a
82
  * I'm open to your [suggestions and feedback](mailto:wp@benbodhi.com) - Thanks for using SVG Support!
83
  * Tag me [@benbodhi](https://twitter.com/benbodhi) on Twitter #svgsupport
84
 
85
- *Note:* I hope you like this plugin! Please take a moment to rate it and click 'works' under compatibility with your version of WordPress.
86
 
87
 
88
  == Translations ==
@@ -91,15 +95,6 @@ You can [contribute your translation here](https://translate.wordpress.org/proje
91
  New to Translating WordPress? Read through the [Translator Handbook](https://make.wordpress.org/polyglots/handbook/tools/glotpress-translate-wordpress-org/) to get started.
92
 
93
 
94
- == Credits ==
95
-
96
- Plugin by [Benbodhi](https://benbodhi.com/) [@benbodhi](https://twitter.com/benbodhi)
97
-
98
- Thanks to [ipokkel](https://wordpress.org/support/users/ipokkel/) for his suggestions and code contributions.
99
- Thanks to [laurosello](https://wordpress.org/support/users/laurosollero) for his code contribution.
100
- Logo By W3C, CC BY 2.5, [https://commons.wikimedia.org/w/index.php?curid=1895005](https://commons.wikimedia.org/w/index.php?curid=1895005).
101
-
102
-
103
  == Frequently Asked Questions ==
104
 
105
  = SVG not rendering inline since 2.3 update =
@@ -145,6 +140,11 @@ You need to add the mime type for svg and svgz to: "MLA Settings > Media Library
145
 
146
  == Changelog ==
147
 
 
 
 
 
 
148
  = 2.3.15 =
149
  * Had to roll back a recent PHP warnings fix due to it breaking some theme compatibility.
150
 
@@ -305,6 +305,9 @@ You need to add the mime type for svg and svgz to: "MLA Settings > Media Library
305
 
306
  == Upgrade Notice ==
307
 
 
 
 
308
  = 2.3.15 =
309
  Had to roll back a recent PHP warnings fix due to it breaking some theme compatibility.
310
 
1
  === SVG Support ===
2
  Contributors: Benbodhi
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z9R7JERS82EQQ
4
+ Tags: svg, vector, safesvg, css, style, mime, mime type, embed, img, inline, animation, animate, js
5
  Requires at least: 4.8
6
+ Tested up to: 5.3.3
7
  Requires PHP: 5.2
8
+ Stable tag: 2.3.16
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
+ Safely upload SVG files to the Media Library. Advanced features also allow you to render SVG files inline for direct styling/animation of an SVG's internal elements using CSS/JS.
13
 
14
 
15
  == Description ==
16
 
17
+ **Safely upload SVG files to your media library and use them like any other image.**
18
+
19
+ But SVG Support has more features!!! Read on to learn more.
20
+
21
  When using SVG images on your WordPress site, it can be hard to style elements within the SVG using CSS. **Now you can, easily!**
22
 
23
  Scalable Vector Graphics (SVG) are becoming common place in modern web design, allowing you to embed images with small file sizes that are scalable to any visual size without loss of quality.
86
  * I'm open to your [suggestions and feedback](mailto:wp@benbodhi.com) - Thanks for using SVG Support!
87
  * Tag me [@benbodhi](https://twitter.com/benbodhi) on Twitter #svgsupport
88
 
89
+ *Note:* I hope you like this plugin! Please take a moment to [rate it](https://wordpress.org/support/view/plugin-reviews/svg-support?filter=5#postform).
90
 
91
 
92
  == Translations ==
95
  New to Translating WordPress? Read through the [Translator Handbook](https://make.wordpress.org/polyglots/handbook/tools/glotpress-translate-wordpress-org/) to get started.
96
 
97
 
 
 
 
 
 
 
 
 
 
98
  == Frequently Asked Questions ==
99
 
100
  = SVG not rendering inline since 2.3 update =
140
 
141
  == Changelog ==
142
 
143
+ = 2.3.16 =
144
+ * Fix for files that have the XML declaration.
145
+ * Fix for PHP warnings from image widget.
146
+ * Some small CSS changes to the frontend when displaying SVG media attachments.
147
+
148
  = 2.3.15 =
149
  * Had to roll back a recent PHP warnings fix due to it breaking some theme compatibility.
150
 
305
 
306
  == Upgrade Notice ==
307
 
308
+ = 2.3.16 =
309
+ This update addresses upload issues, PHP warnings and some frontend CSS changes with attachment display.
310
+
311
  = 2.3.15 =
312
  Had to roll back a recent PHP warnings fix due to it breaking some theme compatibility.
313
 
scss/svgs-attachment.scss CHANGED
@@ -1,14 +1,14 @@
1
- .attachment img[src$=".svg"],
2
- .widget_media_image img[src$=".svg"] {
3
- width: 100%;
4
- }
5
 
6
  .attachment,
7
  .widget_media_image {
8
 
9
- img[src$=".svg"] {
10
- width: 100%;
11
- }
12
 
13
  svg {
14
  max-width: 100%;
1
+ // .attachment img[src$=".svg"],
2
+ // .widget_media_image img[src$=".svg"] {
3
+ // width: 100%;
4
+ // }
5
 
6
  .attachment,
7
  .widget_media_image {
8
 
9
+ // img[src$=".svg"] {
10
+ // width: 100%;
11
+ // }
12
 
13
  svg {
14
  max-width: 100%;
svg-support.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: SVG Support
4
  Plugin URI: http://wordpress.org/plugins/svg-support/
5
  Description: Upload SVG files to the Media Library and render SVG files inline for direct styling/animation of an SVG's internal elements using CSS/JS.
6
- Version: 2.3.15
7
  Author: Benbodhi
8
  Author URI: http://benbodhi.com
9
  Text Domain: svg-support
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  /**
23
  * Global variables
24
  */
25
- $svgs_plugin_version = '2.3.15'; // for use on admin pages
26
  $plugin_file = plugin_basename(__FILE__); // plugin file for reference
27
  define( 'BODHI_SVGS_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); // define the absolute plugin path for includes
28
  define( 'BODHI_SVGS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); // define the plugin url for use in enqueue
@@ -35,7 +35,7 @@ include( BODHI_SVGS_PLUGIN_PATH . 'admin/admin-init.php' ); // initial
35
  include( BODHI_SVGS_PLUGIN_PATH . 'admin/plugin-action-meta-links.php' ); // add links to the plugin on the plugins page
36
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/mime-types.php' ); // setup mime types support for SVG (with fix for WP 4.7.1 - 4.7.2)
37
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/thumbnail-display.php' ); // make SVG thumbnails display correctly in media library
38
- include( BODHI_SVGS_PLUGIN_PATH . 'functions/attachment-modal.php' ); // make SVG thumbnails display correctly in attachment modals
39
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/enqueue.php' ); // enqueue js & css for inline replacement & admin
40
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/localization.php' ); // setup localization & languages
41
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/attribute-control.php' ); // auto set SVG class & remove dimensions during insertion
3
  Plugin Name: SVG Support
4
  Plugin URI: http://wordpress.org/plugins/svg-support/
5
  Description: Upload SVG files to the Media Library and render SVG files inline for direct styling/animation of an SVG's internal elements using CSS/JS.
6
+ Version: 2.3.16
7
  Author: Benbodhi
8
  Author URI: http://benbodhi.com
9
  Text Domain: svg-support
22
  /**
23
  * Global variables
24
  */
25
+ $svgs_plugin_version = '2.3.16'; // for use on admin pages
26
  $plugin_file = plugin_basename(__FILE__); // plugin file for reference
27
  define( 'BODHI_SVGS_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); // define the absolute plugin path for includes
28
  define( 'BODHI_SVGS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); // define the plugin url for use in enqueue
35
  include( BODHI_SVGS_PLUGIN_PATH . 'admin/plugin-action-meta-links.php' ); // add links to the plugin on the plugins page
36
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/mime-types.php' ); // setup mime types support for SVG (with fix for WP 4.7.1 - 4.7.2)
37
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/thumbnail-display.php' ); // make SVG thumbnails display correctly in media library
38
+ include( BODHI_SVGS_PLUGIN_PATH . 'functions/attachment.php' ); // make SVG thumbnails display correctly in attachment modals and generate attachment sizes
39
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/enqueue.php' ); // enqueue js & css for inline replacement & admin
40
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/localization.php' ); // setup localization & languages
41
  include( BODHI_SVGS_PLUGIN_PATH . 'functions/attribute-control.php' ); // auto set SVG class & remove dimensions during insertion