Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG's Not Rendering for Image Field Type #1210

Open
romanberdnikov opened this issue Dec 19, 2023 · 1 comment
Open

SVG's Not Rendering for Image Field Type #1210

romanberdnikov opened this issue Dec 19, 2023 · 1 comment

Comments

@romanberdnikov
Copy link

romanberdnikov commented Dec 19, 2023

I'm using the Safe SVG plugin (https://wordpress.org/plugins/safe-svg) v2.2.2 and CF v3.6. For some reason my svg files have an empty 'file_type' meta.

{
    "id": 1465,
    "thumb_url": "https://site.com/wp-content/uploads/2023/11/antihistamines.svg",
    "file_type": "",
    "file_name": "antihistamines.svg",
    "file_url": "https://site.com/wp-content/uploads/2023/11/antihistamines.svg",
    "filetype": {
        "ext": false,
        "type": false
    }
}

core/Helper/Helper.php

		if ( $attachment_metadata['file_type'] == 'image' ) {
			$attachment_metadata['thumb_url'] = $attachment_metadata['file_url'];

			if ( $type == 'id' ) {
				$attachment_metadata['thumb_url'] = wp_get_attachment_thumb_url( $id );
			}
		} else {
			$attachment_metadata['thumb_url'] = wp_mime_type_icon( $id );
		}

After a quick research, it seems like the wp_get_image_mime() function isn't reliable. It returns nothing for the SVG file (probably because of the size optimization). However, it works fine for png/jpeg: 'image/jpeg'.

And I checked '_wp_attachment_metadata' meta value, it does have a correct mime type

array(4) {
  ["width"]=>
  int(408)
  ["height"]=>
  int(456)
  ["file"]=>
  string(26) "2023/11/antihistamines.svg"
  ["sizes"]=>
  array(7) {
    ["thumbnail"]=>
    array(5) {
      ["width"]=>
      string(3) "150"
      ["height"]=>
      string(3) "150"
      ["crop"]=>
      string(1) "1"
      ["file"]=>
      string(18) "antihistamines.svg"
      ["mime-type"]=>
      string(13) "image/svg+xml"
    }

Originally posted by @jorostoyanov in #962 (comment)

@romanberdnikov
Copy link
Author

@jorostoyanov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant