SVG Support - Version 2.3.2

Version Description

  • Modified the attribute control code that auto inserts our class to only apply to SVG files.
Download this release

Release Info

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

Code changes from version 2.3.1 to 2.3.2

Files changed (3) hide show
  1. functions/attribute-control.php +25 -24
  2. readme.txt +9 -1
  3. svg-support.php +2 -2
functions/attribute-control.php CHANGED
@@ -12,47 +12,48 @@ if ( ! defined( 'ABSPATH' ) ) {
12
  if ( bodhi_svgs_advanced_mode() ) {
13
 
14
  /**
15
- * Filter the img tag class during insertion and return SVG Support class
16
  */
17
- function bodhi_svgs_image_class_filter( $classes ) {
18
 
19
  global $bodhi_svgs_options;
20
 
21
  if ( ! empty( $bodhi_svgs_options['css_target'] ) ) {
22
 
23
- $classes = $bodhi_svgs_options['css_target'];
 
24
 
25
  } else {
26
 
27
- $classes = 'style-svg';
 
28
 
29
  }
30
 
31
- return $classes;
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  }
 
34
  /**
35
- * Check settings to see if we should add the class automatically
36
  */
37
  if ( ! empty( $bodhi_svgs_options['auto_insert_class'] ) ) {
38
-
39
- // add the class
40
- add_filter( 'get_image_tag_class', 'bodhi_svgs_image_class_filter' );
41
-
42
  }
43
 
44
- }
45
-
46
- /**
47
- * Remove the width and height attributes during insertion of svg
48
- */
49
- function bodhi_svgs_remove_svg_dimensions( $html='' ) {
50
 
51
- // if ( preg_match( '/src="(.*[.]svg)"\s/', $html ) ) {
52
- // //$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
53
- // }
54
- return str_ireplace( array( " width=\"1\"", " height=\"1\"" ), "", $html );
55
-
56
- }
57
- add_filter( 'post_thumbnail_html', 'bodhi_svgs_remove_svg_dimensions', 10 );
58
- add_filter( 'image_send_to_editor', 'bodhi_svgs_remove_svg_dimensions', 10 );
12
  if ( bodhi_svgs_advanced_mode() ) {
13
 
14
  /**
15
+ * Strip HTML of all attributes and add custom class if the file is .svg
16
  */
17
+ function bodhi_svgs_auto_insert_class( $html, $id, $caption, $title, $align, $url, $size, $alt='' ) {
18
 
19
  global $bodhi_svgs_options;
20
 
21
  if ( ! empty( $bodhi_svgs_options['css_target'] ) ) {
22
 
23
+ // if custom class is set, use it
24
+ $class = $bodhi_svgs_options['css_target'];
25
 
26
  } else {
27
 
28
+ // if no custom class set, use default
29
+ $class = 'style-svg';
30
 
31
  }
32
 
33
+ // check if the src file has .svg extension
34
+ if ( strpos( $html, '.svg' ) !== FALSE ) {
35
+
36
+ // strip html for svg files
37
+ $html = preg_replace( '/(width|height|title|alt|class)=".*"\s/', 'class="' . $class . '"', $html );;
38
+
39
+ } else {
40
+
41
+ // leave html intact for non-svg
42
+ $html = $html;
43
+
44
+ }
45
+
46
+ return $html;
47
 
48
  }
49
+
50
  /**
51
+ * Fire auto insert class
52
  */
53
  if ( ! empty( $bodhi_svgs_options['auto_insert_class'] ) ) {
54
+ add_filter( 'image_send_to_editor', 'bodhi_svgs_auto_insert_class', 10 );
55
+ add_filter( 'post_thumbnail_html', 'bodhi_svgs_auto_insert_class', 10 );
 
 
56
  }
57
 
 
 
 
 
 
 
58
 
59
+ }
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: svg, vector, css, style, mime, mime type, embed, img, inline, animation
5
  Requires at least: 4.0
6
  Tested up to: 4.8-alpha-39901
7
- Stable tag: 2.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -138,6 +138,10 @@ If you are using SVG Support with Visual Composer or any other page builders, yo
138
 
139
  == Changelog ==
140
 
 
 
 
 
141
  = 2.3.1 =
142
 
143
  * Fix: Fatal error in some cases due to admin notice.
@@ -251,6 +255,10 @@ If you are using SVG Support with Visual Composer or any other page builders, yo
251
 
252
  == Upgrade Notice ==
253
 
 
 
 
 
254
  = 2.3.1 =
255
 
256
  * Fixes fatal error in some cases due to admin notice in V2.3.
4
  Tags: svg, vector, css, style, mime, mime type, embed, img, inline, animation
5
  Requires at least: 4.0
6
  Tested up to: 4.8-alpha-39901
7
+ Stable tag: 2.3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
138
 
139
  == Changelog ==
140
 
141
+ = 2.3.2 =
142
+
143
+ * Modified the attribute control code that auto inserts our class to only apply to SVG files.
144
+
145
  = 2.3.1 =
146
 
147
  * Fix: Fatal error in some cases due to admin notice.
255
 
256
  == Upgrade Notice ==
257
 
258
+ = 2.3.2 =
259
+
260
+ * Changes to the way the auto class insert works.
261
+
262
  = 2.3.1 =
263
 
264
  * Fixes fatal error in some cases due to admin notice in V2.3.
svg-support.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: SVG Support
4
  Plugin URI: http://wordpress.org/plugins/svg-support/
5
  Description: Allow SVG file uploads using the WordPress Media Library uploader plus the ability to inline SVG files for direct targeting of SVG elements for CSS and JS.
6
- Version: 2.3.1
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.1'; // 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
3
  Plugin Name: SVG Support
4
  Plugin URI: http://wordpress.org/plugins/svg-support/
5
  Description: Allow SVG file uploads using the WordPress Media Library uploader plus the ability to inline SVG files for direct targeting of SVG elements for CSS and JS.
6
+ Version: 2.3.2
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.2'; // 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