Skip to content

Commit d1081ca

Browse files
Merge pull request #1088 from cloudinary/fix-svg-pulling
Avoid SVG conversion for pulled SVG from Cloudinary if SVG support is enabled
2 parents a64d00e + 8821799 commit d1081ca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

php/class-svg.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ public function is_active() {
217217
return 'on' === $this->config[ $this->enable_slug ];
218218
}
219219

220+
/**
221+
* Disable SVG conversion.
222+
* If SVG support is active, we don't want to convert SVGs to other formats.
223+
*
224+
* @param array $base_types The base types for conversion.
225+
*
226+
* @return array
227+
*/
228+
public function disable_svg_conversion( $base_types ) {
229+
if ( $this->is_active() && ! empty( $base_types['svg'] ) ) {
230+
unset( $base_types['svg'] );
231+
}
232+
233+
return $base_types;
234+
}
235+
220236
/**
221237
* Setup the component
222238
*/
@@ -233,6 +249,7 @@ public function setup_hooks() {
233249
add_filter( 'cloudinary_allowed_extensions', array( $this, 'allow_svg_for_cloudinary' ) );
234250
add_filter( 'cloudinary_upload_options', array( $this, 'remove_svg_eagers' ), 10, 2 );
235251
add_filter( 'cloudinary_upload_args', array( $this, 'upload_args' ), 10, 2 );
252+
add_filter( 'cloudinary_convert_media_types', array( $this, 'disable_svg_conversion' ) );
236253

237254
// Add actions.
238255
add_action( 'cloudinary_uploaded_asset', array( $this, 'maybe_setup_metadata' ), 10, 2 );

0 commit comments

Comments
 (0)