Safe SVG - Version 1.4.4

Version Description

  • SVGs now display as featured images in the admin area
Download this release

Release Info

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

Code changes from version 1.4.3 to 1.4.4

Files changed (3) hide show
  1. assets/safe-svg.css +6 -0
  2. readme.txt +5 -2
  3. safe-svg.php +31 -2
assets/safe-svg.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ /**
2
+ * Fix SVGs not showing correctly as featured images.
3
+ */
4
+ #postimagediv .inside .svg img {
5
+ width: 100%;
6
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: enshrined
3
  Donate link: https://wpsvg.com/
4
  Tags: svg, sanitize, upload, sanitise, security, svg upload, image, vector, file, graphic, media, mime
5
  Requires at least: 4.0
6
- Tested up to: 4.7.3
7
- Stable tag: 1.4.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -39,6 +39,9 @@ Install through the WordPress directory or download, unzip and upload the files
39
 
40
  == Changelog ==
41
 
 
 
 
42
  = 1.4.3 =
43
  * WordPress 4.7.3 Compatibility
44
  * Expanded SVG previews in media library
3
  Donate link: https://wpsvg.com/
4
  Tags: svg, sanitize, upload, sanitise, security, svg upload, image, vector, file, graphic, media, mime
5
  Requires at least: 4.0
6
+ Tested up to: 4.8.0
7
+ Stable tag: 1.4.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
39
 
40
  == Changelog ==
41
 
42
+ = 1.4.4 =
43
+ * SVGs now display as featured images in the admin area
44
+
45
  = 1.4.3 =
46
  * WordPress 4.7.3 Compatibility
47
  * Expanded SVG previews in media library
safe-svg.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Safe SVG
4
  Plugin URI: https://wpsvg.com/
5
  Description: Allows SVG uploads into WordPress and sanitizes the SVG before saving it
6
- Version: 1.4.3
7
  Author: Daryll Doyle
8
  Author URI: http://enshrined.co.uk
9
  Text Domain: safe-svg
@@ -39,7 +39,9 @@ if ( ! class_exists( 'safe_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
  add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_admin_preview' ), 10, 3 );
42
- add_filter( 'wp_get_attachment_image_src', array( $this, 'one_pixel_fix' ), 10, 4 );
 
 
43
  }
44
 
45
  /**
@@ -212,6 +214,33 @@ if ( ! class_exists( 'safe_svg' ) ) {
212
 
213
  return $image;
214
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  }
216
  }
217
 
3
  Plugin Name: Safe SVG
4
  Plugin URI: https://wpsvg.com/
5
  Description: Allows SVG uploads into WordPress and sanitizes the SVG before saving it
6
+ Version: 1.4.4
7
  Author: Daryll Doyle
8
  Author URI: http://enshrined.co.uk
9
  Text Domain: safe-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
  add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_admin_preview' ), 10, 3 );
42
+ add_filter( 'wp_get_attachment_image_src', array( $this, 'one_pixel_fix' ), 10, 4 );
43
+ add_filter( 'admin_post_thumbnail_html', array( $this, 'featured_image_fix' ), 10, 3 );
44
+ add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_admin_style' ) );
45
  }
46
 
47
  /**
214
 
215
  return $image;
216
  }
217
+
218
+ /**
219
+ * If the featured image is an SVG we wrap it in an SVG class so we can apply our CSS fix.
220
+ *
221
+ * @param string $content Admin post thumbnail HTML markup.
222
+ * @param int $post_id Post ID.
223
+ * @param int $thumbnail_id Thumbnail ID.
224
+ *
225
+ * @return string
226
+ */
227
+ public function featured_image_fix( $content, $post_id, $thumbnail_id) {
228
+ $mime = get_post_mime_type( $thumbnail_id );
229
+
230
+ if( 'image/svg+xml' === $mime ) {
231
+ $content = sprintf( '<span class="svg">%s</span>', $content );
232
+ }
233
+
234
+ return $content;
235
+ }
236
+
237
+ /**
238
+ * Load our custom CSS sheet.
239
+ */
240
+ function load_custom_admin_style() {
241
+ wp_enqueue_style( 'safe-svg-css', plugins_url( 'assets/safe-svg.css', __FILE__ ), array() );
242
+ }
243
+
244
  }
245
  }
246