@@ -162,7 +162,7 @@ public function allow_svg_for_cloudinary( $types ) {
162162 * @return array
163163 */
164164 public function remove_svg_eagers ( $ options , $ attachment ) {
165- if ( ' image/svg+xml ' === $ attachment ->post_mime_type ) {
165+ if ( static :: is_svg ( $ attachment ->ID ) ) {
166166 unset( $ options ['eager ' ], $ options ['eager_async ' ] );
167167 }
168168
@@ -179,7 +179,7 @@ public function remove_svg_eagers( $options, $attachment ) {
179179 */
180180 public function upload_args ( $ args , $ attachment_id ) {
181181
182- if ( ' image/svg+xml ' === get_post_mime_type ( $ attachment_id ) ) {
182+ if ( static :: is_svg ( $ attachment_id ) ) {
183183 $ args ['body ' ]['resource_type ' ] = 'auto ' ;
184184 $ args ['body ' ]['eager ' ] = 'fl_sanitize ' ;
185185 }
@@ -194,7 +194,7 @@ public function upload_args( $args, $attachment_id ) {
194194 */
195195 public function maybe_setup_metadata ( $ attachment_id , $ result ) {
196196
197- if ( is_array ( $ result ) && ' image/svg+xml ' === get_post_mime_type ( $ attachment_id ) ) {
197+ if ( is_array ( $ result ) && static :: is_svg ( $ attachment_id ) ) {
198198 $ file_path = get_post_meta ( $ attachment_id , '_wp_attached_file ' , true );
199199 $ meta = wp_get_attachment_metadata ( $ attachment_id );
200200 if ( empty ( $ meta ) ) {
@@ -237,4 +237,15 @@ public function setup_hooks() {
237237 // Add actions.
238238 add_action ( 'cloudinary_uploaded_asset ' , array ( $ this , 'maybe_setup_metadata ' ), 10 , 2 );
239239 }
240+
241+ /**
242+ * Check if an attachment is an SVG.
243+ *
244+ * @param int $attachment_id The attachment ID.
245+ *
246+ * @return bool
247+ */
248+ public static function is_svg ( $ attachment_id ) {
249+ return 'image/svg+xml ' === get_post_mime_type ( $ attachment_id );
250+ }
240251}
0 commit comments