Safe SVG - Version 1.9.1

Version Description

  • Fixed a warning that was being generated by a change made in 1.9.0.
Download this release

Release Info

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

Code changes from version 1.9.0 to 1.9.1

Files changed (2) hide show
  1. readme.txt +4 -1
  2. safe-svg.php +313 -310
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: svg, sanitize, upload, sanitise, security, svg upload, image, vector, file
5
  Requires at least: 4.0
6
  Tested up to: 5.0.2
7
  Requires PHP: 5.6
8
- Stable tag: 1.9.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -62,6 +62,9 @@ They take one argument that must be returned. See below for examples:
62
 
63
  == Changelog ==
64
 
 
 
 
65
  = 1.9.0 =
66
  * If an image is the correct ratio, allow skipping of the crop popup when setting header/logo images with SVGs.
67
 
5
  Requires at least: 4.0
6
  Tested up to: 5.0.2
7
  Requires PHP: 5.6
8
+ Stable tag: 1.9.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.9.1 =
66
+ * Fixed a warning that was being generated by a change made in 1.9.0.
67
+
68
  = 1.9.0 =
69
  * If an image is the correct ratio, allow skipping of the crop popup when setting header/logo images with SVGs.
70
 
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.9.0
7
  Author: Daryll Doyle
8
  Author URI: http://enshrined.co.uk
9
  Text Domain: safe-svg
@@ -18,269 +18,272 @@ require 'includes/safe-svg-attributes.php';
18
 
19
  if ( ! class_exists( 'safe_svg' ) ) {
20
 
21
- /**
22
- * Class safe_svg
23
- */
24
- Class safe_svg {
25
-
26
- /**
27
- * The sanitizer
28
- *
29
- * @var \enshrined\svgSanitize\Sanitizer
30
- */
31
- protected $sanitizer;
32
-
33
- /**
34
- * Set up the class
35
- */
36
- function __construct() {
37
- $this->sanitizer = new enshrined\svgSanitize\Sanitizer();
38
- $this->sanitizer->minify( true );
39
-
40
- add_filter( 'upload_mimes', array( $this, 'allow_svg' ) );
41
- add_filter( 'wp_handle_upload_prefilter', array( $this, 'check_for_svg' ) );
42
- add_filter( 'wp_check_filetype_and_ext', array( $this, 'fix_mime_type_svg' ), 75, 4 );
43
- add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_admin_preview' ), 10, 3 );
44
- add_filter( 'wp_get_attachment_image_src', array( $this, 'one_pixel_fix' ), 10, 4 );
45
- add_filter( 'admin_post_thumbnail_html', array( $this, 'featured_image_fix' ), 10, 3 );
46
- add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_admin_style' ) );
47
- add_action( 'get_image_tag', array( $this, 'get_image_tag_override' ), 10, 6 );
48
- add_filter( 'wp_generate_attachment_metadata', array( $this, 'skip_svg_regeneration' ), 10, 2 );
49
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_upgrade_link' ) );
50
- add_filter( 'wp_get_attachment_metadata', array( $this, 'metadata_error_fix' ), 10, 2 );
51
- add_filter( 'wp_get_attachment_image_attributes',array( $this, 'fix_direct_image_output' ), 10, 3 );
52
- }
53
-
54
- /**
55
- * Allow SVG Uploads
56
- *
57
- * @param $mimes
58
- *
59
- * @return mixed
60
- */
61
- public function allow_svg( $mimes ) {
62
- $mimes['svg'] = 'image/svg+xml';
63
- $mimes['svgz'] = 'image/svg+xml';
64
-
65
- return $mimes;
66
- }
67
-
68
- /**
69
- * Fixes the issue in WordPress 4.7.1 being unable to correctly identify SVGs
70
- *
71
- * @thanks @lewiscowles
72
- *
73
- * @param null $data
74
- * @param null $file
75
- * @param null $filename
76
- * @param null $mimes
77
- *
78
- * @return null
79
- */
80
- public function fix_mime_type_svg( $data = null, $file = null, $filename = null, $mimes = null ) {
81
- $ext = isset( $data['ext'] ) ? $data['ext'] : '';
82
- if ( strlen( $ext ) < 1 ) {
83
- $exploded = explode( '.', $filename );
84
- $ext = strtolower( end( $exploded ) );
85
- }
86
- if ( $ext === 'svg' ) {
87
- $data['type'] = 'image/svg+xml';
88
- $data['ext'] = 'svg';
89
- } elseif ( $ext === 'svgz' ) {
90
- $data['type'] = 'image/svg+xml';
91
- $data['ext'] = 'svgz';
92
- }
93
-
94
- return $data;
95
- }
96
-
97
- /**
98
- * Check if the file is an SVG, if so handle appropriately
99
- *
100
- * @param $file
101
- *
102
- * @return mixed
103
- */
104
- public function check_for_svg( $file ) {
105
-
106
- if ( $file['type'] === 'image/svg+xml' ) {
107
- if ( ! $this->sanitize( $file['tmp_name'] ) ) {
108
- $file['error'] = __( "Sorry, this file couldn't be sanitized so for security reasons wasn't uploaded",
109
- 'safe-svg' );
110
- }
111
- }
112
-
113
- return $file;
114
- }
115
-
116
- /**
117
- * Sanitize the SVG
118
- *
119
- * @param $file
120
- *
121
- * @return bool|int
122
- */
123
- protected function sanitize( $file ) {
124
- $dirty = file_get_contents( $file );
125
-
126
- // Is the SVG gzipped? If so we try and decode the string
127
- if ( $is_zipped = $this->is_gzipped( $dirty ) ) {
128
- $dirty = gzdecode( $dirty );
129
-
130
- // If decoding fails, bail as we're not secure
131
- if ( $dirty === false ) {
132
- return false;
133
- }
134
- }
135
-
136
- /**
137
- * Load extra filters to allow devs to access the safe tags and attrs by themselves.
138
- */
139
- $this->sanitizer->setAllowedTags(new safe_svg_tags());
140
- $this->sanitizer->setAllowedAttrs(new safe_svg_attributes());
141
-
142
- $clean = $this->sanitizer->sanitize( $dirty );
143
-
144
- if ( $clean === false ) {
145
- return false;
146
- }
147
-
148
- // If we were gzipped, we need to re-zip
149
- if ( $is_zipped ) {
150
- $clean = gzencode( $clean );
151
- }
152
-
153
- file_put_contents( $file, $clean );
154
-
155
- return true;
156
- }
157
-
158
- /**
159
- * Check if the contents are gzipped
160
- *
161
- * @see http://www.gzip.org/zlib/rfc-gzip.html#member-format
162
- *
163
- * @param $contents
164
- *
165
- * @return bool
166
- */
167
- protected function is_gzipped( $contents ) {
168
- if ( function_exists( 'mb_strpos' ) ) {
169
- return 0 === mb_strpos( $contents, "\x1f" . "\x8b" . "\x08" );
170
- } else {
171
- return 0 === strpos( $contents, "\x1f" . "\x8b" . "\x08" );
172
- }
173
- }
174
-
175
- /**
176
- * Filters the attachment data prepared for JavaScript to add the sizes array to the response
177
- *
178
- * @param array $response Array of prepared attachment data.
179
- * @param int|object $attachment Attachment ID or object.
180
- * @param array $meta Array of attachment meta data.
181
- *
182
- * @return array
183
- */
184
- public function fix_admin_preview( $response, $attachment, $meta ) {
185
-
186
- if ( $response['mime'] == 'image/svg+xml' ) {
187
- $dimensions = $this->svg_dimensions( get_attached_file( $attachment->ID ) );
188
- $response = array_merge($response, $dimensions);
189
-
190
- $possible_sizes = apply_filters( 'image_size_names_choose', array(
 
 
 
191
  'full' => __( 'Full Size' ),
192
- 'thumbnail' => __( 'Thumbnail' ),
193
- 'medium' => __( 'Medium' ),
194
- 'large' => __( 'Large' ),
195
- ) );
196
 
197
- $sizes = array();
198
 
199
- foreach ( $possible_sizes as $size => $label ) {
200
  $default_height = 2000;
201
- $default_width = 2000;
202
 
203
  if ( 'full' === $size && $dimensions ) {
204
- $default_height = $dimensions['height'];
205
- $default_width = $dimensions['width'];
206
  }
207
 
208
- $sizes[ $size ] = array(
209
- 'height' => get_option( "{$size}_size_w", $default_height ),
210
- 'width' => get_option( "{$size}_size_h", $default_width ),
211
- 'url' => $response['url'],
212
- 'orientation' => 'portrait',
213
- );
214
- }
215
-
216
- $response['sizes'] = $sizes;
217
- $response['icon'] = $response['url'];
218
- }
219
-
220
- return $response;
221
- }
222
-
223
- /**
224
- * Filters the image src result.
225
- * Here we're gonna spoof the image size and set it to 100 width and height
226
- *
227
- * @param array|false $image Either array with src, width & height, icon src, or false.
228
- * @param int $attachment_id Image attachment ID.
229
- * @param string|array $size Size of image. Image size or array of width and height values
230
- * (in that order). Default 'thumbnail'.
231
- * @param bool $icon Whether the image should be treated as an icon. Default false.
232
- *
233
- * @return array
234
- */
235
- public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
236
- if ( get_post_mime_type( $attachment_id ) == 'image/svg+xml' ) {
237
- $image['1'] = false;
238
- $image['2'] = false;
239
- }
240
-
241
- return $image;
242
- }
243
-
244
- /**
245
- * If the featured image is an SVG we wrap it in an SVG class so we can apply our CSS fix.
246
- *
247
- * @param string $content Admin post thumbnail HTML markup.
248
- * @param int $post_id Post ID.
249
- * @param int $thumbnail_id Thumbnail ID.
250
- *
251
- * @return string
252
- */
253
- public function featured_image_fix( $content, $post_id, $thumbnail_id ) {
254
- $mime = get_post_mime_type( $thumbnail_id );
255
-
256
- if ( 'image/svg+xml' === $mime ) {
257
- $content = sprintf( '<span class="svg">%s</span>', $content );
258
- }
259
-
260
- return $content;
261
- }
262
-
263
- /**
264
- * Load our custom CSS sheet.
265
- */
266
- function load_custom_admin_style() {
267
- wp_enqueue_style( 'safe-svg-css', plugins_url( 'assets/safe-svg.css', __FILE__ ), array() );
268
- }
269
-
270
- /**
271
- * Override the default height and width string on an SVG
272
- *
273
- * @param string $html HTML content for the image.
274
- * @param int $id Attachment ID.
275
- * @param string $alt Alternate text.
276
- * @param string $title Attachment title.
277
- * @param string $align Part of the class name for aligning the image.
278
- * @param string|array $size Size of image. Image size or array of width and height values (in that order).
279
- * Default 'medium'.
280
- *
281
- * @return mixed
282
- */
283
- function get_image_tag_override( $html, $id, $alt, $title, $align, $size ) {
284
  $mime = get_post_mime_type( $id );
285
 
286
  if ( 'image/svg+xml' === $mime ) {
@@ -307,56 +310,56 @@ if ( ! class_exists( 'safe_svg' ) ) {
307
  }
308
 
309
  return $html;
310
- }
311
-
312
- /**
313
- * Skip regenerating SVGs
314
- *
315
- * @param int $attachment_id Attachment Id to process.
316
- * @param string $file Filepath of the Attached image.
317
- *
318
- * @return mixed Metadata for attachment.
319
- */
320
- function skip_svg_regeneration( $metadata, $attachment_id ) {
321
- if ( 'image/svg+xml' === get_post_mime_type( $attachment_id ) ) {
322
  // return new WP_Error( 'skip_svg_generate', __( 'Skipping SVG file.', 'safe-svg' ) );
323
- }
324
-
325
- return $metadata;
326
- }
327
-
328
- /**
329
- * Add in an upgrade link for Safe SVG
330
- *
331
- * @param $links
332
- *
333
- * @return array
334
- */
335
- function add_upgrade_link( $links ) {
336
- $mylinks = array(
337
- '<a target="_blank" style="color:#3db634;" href="https://wpsvg.com/?utm_source=plugin-list&utm_medium=upgrade-link&utm_campaign=plugin-list&utm_content=action-link">Upgrade</a>',
338
- );
339
-
340
- return array_merge( $links, $mylinks );
341
- }
342
-
343
- /**
344
- * Filters the attachment meta data.
345
- *
346
- * @param array|bool $data Array of meta data for the given attachment, or false
347
- * if the object does not exist.
348
- * @param int $post_id Attachment ID.
349
- */
350
- function metadata_error_fix( $data, $post_id ) {
351
-
352
- // If it's a WP_Error regenerate metadata and save it
353
- if ( is_wp_error( $data ) ) {
354
- $data = wp_generate_attachment_metadata( $post_id, get_attached_file( $post_id ) );
355
- wp_update_attachment_metadata( $post_id, $data );
356
- }
357
-
358
- return $data;
359
- }
360
 
361
  /**
362
  * Get SVG size from the width/height or viewport.
@@ -386,10 +389,10 @@ if ( ! class_exists( 'safe_svg' ) ) {
386
  }
387
 
388
  return array(
389
- 'width' => $width,
390
- 'height' => $height,
391
- 'orientation' => ($width > $height) ? 'landscape' : 'portrait'
392
- );
393
  }
394
 
395
  /**
@@ -420,7 +423,7 @@ if ( ! class_exists( 'safe_svg' ) ) {
420
  return $attr;
421
  }
422
 
423
- }
424
  }
425
 
426
  $safe_svg = new safe_svg();
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.9.1
7
  Author: Daryll Doyle
8
  Author URI: http://enshrined.co.uk
9
  Text Domain: safe-svg
18
 
19
  if ( ! class_exists( 'safe_svg' ) ) {
20
 
21
+ /**
22
+ * Class safe_svg
23
+ */
24
+ Class safe_svg {
25
+
26
+ /**
27
+ * The sanitizer
28
+ *
29
+ * @var \enshrined\svgSanitize\Sanitizer
30
+ */
31
+ protected $sanitizer;
32
+
33
+ /**
34
+ * Set up the class
35
+ */
36
+ function __construct() {
37
+ $this->sanitizer = new enshrined\svgSanitize\Sanitizer();
38
+ $this->sanitizer->minify( true );
39
+
40
+ add_filter( 'upload_mimes', array( $this, 'allow_svg' ) );
41
+ add_filter( 'wp_handle_upload_prefilter', array( $this, 'check_for_svg' ) );
42
+ add_filter( 'wp_check_filetype_and_ext', array( $this, 'fix_mime_type_svg' ), 75, 4 );
43
+ add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_admin_preview' ), 10, 3 );
44
+ add_filter( 'wp_get_attachment_image_src', array( $this, 'one_pixel_fix' ), 10, 4 );
45
+ add_filter( 'admin_post_thumbnail_html', array( $this, 'featured_image_fix' ), 10, 3 );
46
+ add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_admin_style' ) );
47
+ add_action( 'get_image_tag', array( $this, 'get_image_tag_override' ), 10, 6 );
48
+ add_filter( 'wp_generate_attachment_metadata', array( $this, 'skip_svg_regeneration' ), 10, 2 );
49
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_upgrade_link' ) );
50
+ add_filter( 'wp_get_attachment_metadata', array( $this, 'metadata_error_fix' ), 10, 2 );
51
+ add_filter( 'wp_get_attachment_image_attributes', array( $this, 'fix_direct_image_output' ), 10, 3 );
52
+ }
53
+
54
+ /**
55
+ * Allow SVG Uploads
56
+ *
57
+ * @param $mimes
58
+ *
59
+ * @return mixed
60
+ */
61
+ public function allow_svg( $mimes ) {
62
+ $mimes['svg'] = 'image/svg+xml';
63
+ $mimes['svgz'] = 'image/svg+xml';
64
+
65
+ return $mimes;
66
+ }
67
+
68
+ /**
69
+ * Fixes the issue in WordPress 4.7.1 being unable to correctly identify SVGs
70
+ *
71
+ * @thanks @lewiscowles
72
+ *
73
+ * @param null $data
74
+ * @param null $file
75
+ * @param null $filename
76
+ * @param null $mimes
77
+ *
78
+ * @return null
79
+ */
80
+ public function fix_mime_type_svg( $data = null, $file = null, $filename = null, $mimes = null ) {
81
+ $ext = isset( $data['ext'] ) ? $data['ext'] : '';
82
+ if ( strlen( $ext ) < 1 ) {
83
+ $exploded = explode( '.', $filename );
84
+ $ext = strtolower( end( $exploded ) );
85
+ }
86
+ if ( $ext === 'svg' ) {
87
+ $data['type'] = 'image/svg+xml';
88
+ $data['ext'] = 'svg';
89
+ } elseif ( $ext === 'svgz' ) {
90
+ $data['type'] = 'image/svg+xml';
91
+ $data['ext'] = 'svgz';
92
+ }
93
+
94
+ return $data;
95
+ }
96
+
97
+ /**
98
+ * Check if the file is an SVG, if so handle appropriately
99
+ *
100
+ * @param $file
101
+ *
102
+ * @return mixed
103
+ */
104
+ public function check_for_svg( $file ) {
105
+
106
+ if ( $file['type'] === 'image/svg+xml' ) {
107
+ if ( ! $this->sanitize( $file['tmp_name'] ) ) {
108
+ $file['error'] = __( "Sorry, this file couldn't be sanitized so for security reasons wasn't uploaded",
109
+ 'safe-svg' );
110
+ }
111
+ }
112
+
113
+ return $file;
114
+ }
115
+
116
+ /**
117
+ * Sanitize the SVG
118
+ *
119
+ * @param $file
120
+ *
121
+ * @return bool|int
122
+ */
123
+ protected function sanitize( $file ) {
124
+ $dirty = file_get_contents( $file );
125
+
126
+ // Is the SVG gzipped? If so we try and decode the string
127
+ if ( $is_zipped = $this->is_gzipped( $dirty ) ) {
128
+ $dirty = gzdecode( $dirty );
129
+
130
+ // If decoding fails, bail as we're not secure
131
+ if ( $dirty === false ) {
132
+ return false;
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Load extra filters to allow devs to access the safe tags and attrs by themselves.
138
+ */
139
+ $this->sanitizer->setAllowedTags( new safe_svg_tags() );
140
+ $this->sanitizer->setAllowedAttrs( new safe_svg_attributes() );
141
+
142
+ $clean = $this->sanitizer->sanitize( $dirty );
143
+
144
+ if ( $clean === false ) {
145
+ return false;
146
+ }
147
+
148
+ // If we were gzipped, we need to re-zip
149
+ if ( $is_zipped ) {
150
+ $clean = gzencode( $clean );
151
+ }
152
+
153
+ file_put_contents( $file, $clean );
154
+
155
+ return true;
156
+ }
157
+
158
+ /**
159
+ * Check if the contents are gzipped
160
+ *
161
+ * @see http://www.gzip.org/zlib/rfc-gzip.html#member-format
162
+ *
163
+ * @param $contents
164
+ *
165
+ * @return bool
166
+ */
167
+ protected function is_gzipped( $contents ) {
168
+ if ( function_exists( 'mb_strpos' ) ) {
169
+ return 0 === mb_strpos( $contents, "\x1f" . "\x8b" . "\x08" );
170
+ } else {
171
+ return 0 === strpos( $contents, "\x1f" . "\x8b" . "\x08" );
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Filters the attachment data prepared for JavaScript to add the sizes array to the response
177
+ *
178
+ * @param array $response Array of prepared attachment data.
179
+ * @param int|object $attachment Attachment ID or object.
180
+ * @param array $meta Array of attachment meta data.
181
+ *
182
+ * @return array
183
+ */
184
+ public function fix_admin_preview( $response, $attachment, $meta ) {
185
+
186
+ if ( $response['mime'] == 'image/svg+xml' ) {
187
+ $dimensions = $this->svg_dimensions( get_attached_file( $attachment->ID ) );
188
+
189
+ if ( $dimensions ) {
190
+ $response = array_merge( $response, $dimensions );
191
+ }
192
+
193
+ $possible_sizes = apply_filters( 'image_size_names_choose', array(
194
  'full' => __( 'Full Size' ),
195
+ 'thumbnail' => __( 'Thumbnail' ),
196
+ 'medium' => __( 'Medium' ),
197
+ 'large' => __( 'Large' ),
198
+ ) );
199
 
200
+ $sizes = array();
201
 
202
+ foreach ( $possible_sizes as $size => $label ) {
203
  $default_height = 2000;
204
+ $default_width = 2000;
205
 
206
  if ( 'full' === $size && $dimensions ) {
207
+ $default_height = $dimensions['height'];
208
+ $default_width = $dimensions['width'];
209
  }
210
 
211
+ $sizes[ $size ] = array(
212
+ 'height' => get_option( "{$size}_size_w", $default_height ),
213
+ 'width' => get_option( "{$size}_size_h", $default_width ),
214
+ 'url' => $response['url'],
215
+ 'orientation' => 'portrait',
216
+ );
217
+ }
218
+
219
+ $response['sizes'] = $sizes;
220
+ $response['icon'] = $response['url'];
221
+ }
222
+
223
+ return $response;
224
+ }
225
+
226
+ /**
227
+ * Filters the image src result.
228
+ * Here we're gonna spoof the image size and set it to 100 width and height
229
+ *
230
+ * @param array|false $image Either array with src, width & height, icon src, or false.
231
+ * @param int $attachment_id Image attachment ID.
232
+ * @param string|array $size Size of image. Image size or array of width and height values
233
+ * (in that order). Default 'thumbnail'.
234
+ * @param bool $icon Whether the image should be treated as an icon. Default false.
235
+ *
236
+ * @return array
237
+ */
238
+ public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
239
+ if ( get_post_mime_type( $attachment_id ) == 'image/svg+xml' ) {
240
+ $image['1'] = false;
241
+ $image['2'] = false;
242
+ }
243
+
244
+ return $image;
245
+ }
246
+
247
+ /**
248
+ * If the featured image is an SVG we wrap it in an SVG class so we can apply our CSS fix.
249
+ *
250
+ * @param string $content Admin post thumbnail HTML markup.
251
+ * @param int $post_id Post ID.
252
+ * @param int $thumbnail_id Thumbnail ID.
253
+ *
254
+ * @return string
255
+ */
256
+ public function featured_image_fix( $content, $post_id, $thumbnail_id ) {
257
+ $mime = get_post_mime_type( $thumbnail_id );
258
+
259
+ if ( 'image/svg+xml' === $mime ) {
260
+ $content = sprintf( '<span class="svg">%s</span>', $content );
261
+ }
262
+
263
+ return $content;
264
+ }
265
+
266
+ /**
267
+ * Load our custom CSS sheet.
268
+ */
269
+ function load_custom_admin_style() {
270
+ wp_enqueue_style( 'safe-svg-css', plugins_url( 'assets/safe-svg.css', __FILE__ ), array() );
271
+ }
272
+
273
+ /**
274
+ * Override the default height and width string on an SVG
275
+ *
276
+ * @param string $html HTML content for the image.
277
+ * @param int $id Attachment ID.
278
+ * @param string $alt Alternate text.
279
+ * @param string $title Attachment title.
280
+ * @param string $align Part of the class name for aligning the image.
281
+ * @param string|array $size Size of image. Image size or array of width and height values (in that order).
282
+ * Default 'medium'.
283
+ *
284
+ * @return mixed
285
+ */
286
+ function get_image_tag_override( $html, $id, $alt, $title, $align, $size ) {
287
  $mime = get_post_mime_type( $id );
288
 
289
  if ( 'image/svg+xml' === $mime ) {
310
  }
311
 
312
  return $html;
313
+ }
314
+
315
+ /**
316
+ * Skip regenerating SVGs
317
+ *
318
+ * @param int $attachment_id Attachment Id to process.
319
+ * @param string $file Filepath of the Attached image.
320
+ *
321
+ * @return mixed Metadata for attachment.
322
+ */
323
+ function skip_svg_regeneration( $metadata, $attachment_id ) {
324
+ if ( 'image/svg+xml' === get_post_mime_type( $attachment_id ) ) {
325
  // return new WP_Error( 'skip_svg_generate', __( 'Skipping SVG file.', 'safe-svg' ) );
326
+ }
327
+
328
+ return $metadata;
329
+ }
330
+
331
+ /**
332
+ * Add in an upgrade link for Safe SVG
333
+ *
334
+ * @param $links
335
+ *
336
+ * @return array
337
+ */
338
+ function add_upgrade_link( $links ) {
339
+ $mylinks = array(
340
+ '<a target="_blank" style="color:#3db634;" href="https://wpsvg.com/?utm_source=plugin-list&utm_medium=upgrade-link&utm_campaign=plugin-list&utm_content=action-link">Upgrade</a>',
341
+ );
342
+
343
+ return array_merge( $links, $mylinks );
344
+ }
345
+
346
+ /**
347
+ * Filters the attachment meta data.
348
+ *
349
+ * @param array|bool $data Array of meta data for the given attachment, or false
350
+ * if the object does not exist.
351
+ * @param int $post_id Attachment ID.
352
+ */
353
+ function metadata_error_fix( $data, $post_id ) {
354
+
355
+ // If it's a WP_Error regenerate metadata and save it
356
+ if ( is_wp_error( $data ) ) {
357
+ $data = wp_generate_attachment_metadata( $post_id, get_attached_file( $post_id ) );
358
+ wp_update_attachment_metadata( $post_id, $data );
359
+ }
360
+
361
+ return $data;
362
+ }
363
 
364
  /**
365
  * Get SVG size from the width/height or viewport.
389
  }
390
 
391
  return array(
392
+ 'width' => $width,
393
+ 'height' => $height,
394
+ 'orientation' => ( $width > $height ) ? 'landscape' : 'portrait'
395
+ );
396
  }
397
 
398
  /**
423
  return $attr;
424
  }
425
 
426
+ }
427
  }
428
 
429
  $safe_svg = new safe_svg();