Scalable Vector Graphics (SVG) - Version 3.3

Version Description

  • Add a patch for core bug introduced in 4.7.1
Download this release

Release Info

Developer sterlo
Plugin Icon Scalable Vector Graphics (SVG)
Version 3.3
Comparing to
See all releases

Code changes from version 3.2 to 3.3

Files changed (2) hide show
  1. readme.txt +5 -3
  2. scalable-vector-graphics.php +23 -4
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Scalable Vector Graphics (SVG) ===
2
  Contributors: sterlo
3
  Donate link: http://www.sterlinghamilton.com/projects/scalable-vector-graphics/
4
- Tags: svg, scalable, vector, mime, type, image, graphic, file, upload
5
  Requires at least: 3.0
6
- Tested up to: 4.5.3
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -40,10 +40,12 @@ Resources for understanding security risks:
40
  = WP CLI =
41
  1. Be in the root of your WordPress installation.
42
  1. Run `wp plugin install scalable-vector-graphics-svg`.
43
- 1. Run `wp activate scalable-vector-graphics-svg`.
44
 
45
  == Changelog ==
46
 
 
 
47
  = 3.2 =
48
  * Created End User styles to allow for the front of the site to display SVG files properly.
49
  = 3.1 =
1
  === Scalable Vector Graphics (SVG) ===
2
  Contributors: sterlo
3
  Donate link: http://www.sterlinghamilton.com/projects/scalable-vector-graphics/
4
+ Tags: svg, scalable, vector, mime, type, image, graphic, file, upload, media
5
  Requires at least: 3.0
6
+ Tested up to: 4.7.2
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
40
  = WP CLI =
41
  1. Be in the root of your WordPress installation.
42
  1. Run `wp plugin install scalable-vector-graphics-svg`.
43
+ 1. Run `wp plugin activate scalable-vector-graphics-svg`.
44
 
45
  == Changelog ==
46
 
47
+ = 3.3 =
48
+ * Add a patch for core bug introduced in 4.7.1
49
  = 3.2 =
50
  * Created End User styles to allow for the front of the site to display SVG files properly.
51
  = 3.1 =
scalable-vector-graphics.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Scalable Vector Graphics (SVG)
4
  * Plugin URI: http://www.sterlinghamilton.com/projects/scalable-vector-graphics/
5
  * Description: Scalable Vector Graphics are two-dimensional vector graphics, that can be both static and dynamic. This plugin allows your to easily use them on your site.
6
- * Version: 3.2
7
  * Author: Sterling Hamilton
8
  * Author URI: http://www.sterlinghamilton.com/
9
  * License: GPLv2 or later
@@ -25,6 +25,8 @@
25
 
26
  namespace SterlingHamilton\Plugins\ScalableVectorGraphics;
27
 
 
 
28
  // Return the accepted value for SVG mime-types in compliance with the RFC 3023.
29
  // RFC 3023: https://www.ietf.org/rfc/rfc3023.txt 8.19, A.1, A.2, A.3, A.5, and A.7
30
  // Expects to interface with https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_mimes
@@ -51,7 +53,7 @@ function get_dimensions( $svg ) {
51
  //
52
  // Consider this the "server side" fix for dimensions.
53
  // Which is needed for the Media Grid within the Administration area.
54
- function adjust_response_for_svg( $response, $attachment, $meta ) {
55
  if( $response['mime'] == 'image/svg+xml' && empty( $response['sizes'] ) ) {
56
  $svg_file_path = get_attached_file( $attachment->ID );
57
  $dimensions = get_dimensions( $svg_file_path );
@@ -68,6 +70,7 @@ function adjust_response_for_svg( $response, $attachment, $meta ) {
68
 
69
  return $response;
70
  }
 
71
  // Browsers may or may not show SVG files properly without a height/width.
72
  // WordPress specifically defines width/height as "0" if it cannot figure it out.
73
  // Thus the below is needed.
@@ -94,9 +97,25 @@ function public_styles() {
94
  echo "<style>.post-thumbnail img[src$='.svg'] { width: 100%; height: auto; }</style>";
95
  }
96
 
97
- // Do work son.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  add_filter( 'upload_mimes', __NAMESPACE__ . '\\allow_svg_uploads' );
99
- add_filter( 'wp_prepare_attachment_for_js', __NAMESPACE__ . '\\adjust_response_for_svg', 10, 3 );
100
  add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\administration_styles' );
101
  add_action( 'wp_head', __NAMESPACE__ . '\\public_styles' );
102
 
3
  * Plugin Name: Scalable Vector Graphics (SVG)
4
  * Plugin URI: http://www.sterlinghamilton.com/projects/scalable-vector-graphics/
5
  * Description: Scalable Vector Graphics are two-dimensional vector graphics, that can be both static and dynamic. This plugin allows your to easily use them on your site.
6
+ * Version: 3.3
7
  * Author: Sterling Hamilton
8
  * Author URI: http://www.sterlinghamilton.com/
9
  * License: GPLv2 or later
25
 
26
  namespace SterlingHamilton\Plugins\ScalableVectorGraphics;
27
 
28
+ $wordpress_version = get_bloginfo('version');
29
+
30
  // Return the accepted value for SVG mime-types in compliance with the RFC 3023.
31
  // RFC 3023: https://www.ietf.org/rfc/rfc3023.txt 8.19, A.1, A.2, A.3, A.5, and A.7
32
  // Expects to interface with https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_mimes
53
  //
54
  // Consider this the "server side" fix for dimensions.
55
  // Which is needed for the Media Grid within the Administration area.
56
+ function set_dimensions( $response, $attachment, $meta ) {
57
  if( $response['mime'] == 'image/svg+xml' && empty( $response['sizes'] ) ) {
58
  $svg_file_path = get_attached_file( $attachment->ID );
59
  $dimensions = get_dimensions( $svg_file_path );
70
 
71
  return $response;
72
  }
73
+
74
  // Browsers may or may not show SVG files properly without a height/width.
75
  // WordPress specifically defines width/height as "0" if it cannot figure it out.
76
  // Thus the below is needed.
97
  echo "<style>.post-thumbnail img[src$='.svg'] { width: 100%; height: auto; }</style>";
98
  }
99
 
100
+ // Restores the ability to upload non-image files in WordPress 4.7.1 and 4.7.2.
101
+ // Related Trac Ticket: https://core.trac.wordpress.org/ticket/39550
102
+ // Credit: @sergeybiryukov
103
+ // @TODO: Remove the plugin once WordPress 4.7.3 is available!
104
+ function disable_real_mime_check( $data, $file, $filename, $mimes ) {
105
+ $wp_filetype = wp_check_filetype( $filename, $mimes );
106
+
107
+ $ext = $wp_filetype['ext'];
108
+ $type = $wp_filetype['type'];
109
+ $proper_filename = $data['proper_filename'];
110
+
111
+ return compact( 'ext', 'type', 'proper_filename' );
112
+ }
113
+
114
+ if($wordpress_version < "4.7.3") {
115
+ add_filter( 'wp_check_filetype_and_ext', __NAMESPACE__ . '\\disable_real_mime_check', 10, 4 );
116
+ }
117
  add_filter( 'upload_mimes', __NAMESPACE__ . '\\allow_svg_uploads' );
118
+ add_filter( 'wp_prepare_attachment_for_js', __NAMESPACE__ . '\\set_dimensions', 10, 3 );
119
  add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\administration_styles' );
120
  add_action( 'wp_head', __NAMESPACE__ . '\\public_styles' );
121