Safe SVG - Version 1.3.2

Version Description

  • Fix for the mime type issue in 4.7.1. Mad props to @lewiscowles
Download this release

Release Info

Developer enshrined
Plugin Icon 128x128 Safe SVG
Version 1.3.2
Comparing to
See all releases

Code changes from version 1.3.1 to 1.3.2

Files changed (2) hide show
  1. readme.txt +5 -2
  2. safe-svg.php +27 -1
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: enshrined
3
  Donate link: http://enshrined.co.uk
4
  Tags: svg, sanitize, uploads, sanitise, security, svg upload
5
  Requires at least: 4.0
6
- Tested up to: 4.6.1
7
- Stable tag: 1.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -43,3 +43,6 @@ Install through the WordPress directory or download, unzip and upload the files
43
 
44
  = 1.3.1 =
45
  * Updated underlying library version
 
 
 
3
  Donate link: http://enshrined.co.uk
4
  Tags: svg, sanitize, uploads, sanitise, security, svg upload
5
  Requires at least: 4.0
6
+ Tested up to: 4.7.2
7
+ Stable tag: 1.3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
43
 
44
  = 1.3.1 =
45
  * Updated underlying library version
46
+
47
+ = 1.3.2 =
48
+ * Fix for the mime type issue in 4.7.1. Mad props to @lewiscowles
safe-svg.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Safe SVG
4
  Plugin URI: https://wordpress.org/plugins/safe-svg/
5
  Description: Allows SVG uploads into Wordpress and sanitizes the SVG before saving it
6
- Version: 1.3.1
7
  Author: Daryll Doyle
8
  Author URI: http://enshrined.co.uk
9
  Text Domain: safe-svg
@@ -37,6 +37,7 @@ if ( ! class_exists( 'safe_svg' ) ) {
37
 
38
  add_filter( 'upload_mimes', array( $this, 'allow_svg' ) );
39
  add_filter( 'wp_handle_upload_prefilter', array( $this, 'check_for_svg' ) );
 
40
  }
41
 
42
  /**
@@ -52,6 +53,31 @@ if ( ! class_exists( 'safe_svg' ) ) {
52
  return $mimes;
53
  }
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  /**
56
  * Check if the file is an SVG, if so handle appropriately
57
  *
3
  Plugin Name: Safe SVG
4
  Plugin URI: https://wordpress.org/plugins/safe-svg/
5
  Description: Allows SVG uploads into Wordpress and sanitizes the SVG before saving it
6
+ Version: 1.3.2
7
  Author: Daryll Doyle
8
  Author URI: http://enshrined.co.uk
9
  Text Domain: safe-svg
37
 
38
  add_filter( 'upload_mimes', array( $this, 'allow_svg' ) );
39
  add_filter( 'wp_handle_upload_prefilter', array( $this, 'check_for_svg' ) );
40
+ add_filter( 'wp_check_filetype_and_ext', array( $this, 'fix_mime_type_svg' ), 75, 4 );
41
  }
42
 
43
  /**
53
  return $mimes;
54
  }
55
 
56
+ /**
57
+ * Fixes the issue in WordPress 4.7.1 being unable to correctly identify SVGs
58
+ *
59
+ * @thanks @lewiscowles
60
+ *
61
+ * @param null $data
62
+ * @param null $file
63
+ * @param null $filename
64
+ * @param null $mimes
65
+ *
66
+ * @return null
67
+ */
68
+ public function fix_mime_type_svg( $data = null, $file = null, $filename = null, $mimes = null ) {
69
+ $ext = isset( $data['ext'] ) ? $data['ext'] : '';
70
+ if ( strlen( $ext ) < 1 ) {
71
+ $ext = strtolower( end( explode( '.', $filename ) ) );
72
+ }
73
+ if ( $ext === 'svg' ) {
74
+ $data['type'] = 'image/svg+xml';
75
+ $data['ext'] = 'svg';
76
+ }
77
+
78
+ return $data;
79
+ }
80
+
81
  /**
82
  * Check if the file is an SVG, if so handle appropriately
83
  *