WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 7 months ago

#39422 new defect (bug)

Consistency for returned value of attachment meta : mime_type VS mime-type

Reported by: gabrielstuff Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.6.1
Component: Media Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

Hello here,

While using the function wp_get_attachment_metadata, the returned associative array is not consistent. For video attachment it will give mime_type key with a "_" and for images it will return mime-type key with a "-".

The returned mime type key should either be "mime_type" or "mime-type", but should be the same for any type of media attachment.

Thanks for the great job !

Attachments (1)

39422.patch (1.0 KB) - added by dhanendran 17 months ago.

Download all attachments as: .zip

Change History (8)

#1 @dhanendran
17 months ago

Hi @gabrielstuff ,

Are you sure that you are getting the wrong key value? Because I have tried this and got the correct data as expected.

Array
(
    [filesize] => 1055736
    [mime_type] => video/quicktime
    [length] => 5
    [length_formatted] => 0:05
    [width] => 1280
    [height] => 720
    [fileformat] => mp4
    [dataformat] => quicktime
    [audio] => Array
        (
            [dataformat] => mp4
            [codec] => ISO/IEC 14496-3 AAC
            [sample_rate] => 48000
            [channels] => 2
            [bits_per_sample] => 16
            [lossless] => 
            [channelmode] => stereo
        )

)

Are you using any plugin to do any additional work in media? If so please check with your plugin it may modify the data using wp_get_attachment_metadata filter.

#2 @dhanendran
17 months ago

Apologies @gabrielstuff , that was my mistake I checked with the video type. Now I have checked with image and Yes it is returning mime type with -.

Array
(
    [width] => 220
    [height] => 169
    [file] => 2016/12/helpinghomeless0.png
    [sizes] => Array
        (
            [thumbnail] => Array
                (
                    [file] => helpinghomeless0-150x150.png
                    [width] => 150
                    [height] => 150
                    [mime-type] => image/png
                )

        )

    [image_meta] => Array
        (
            [aperture] => 0
            [credit] => 
            [camera] => 
            [caption] => 
            [created_timestamp] => 0
            [copyright] => 
            [focal_length] => 0
            [iso] => 0
            [shutter_speed] => 0
            [title] => 
            [orientation] => 0
            [keywords] => Array
                (
                )

        )

)

And this is happening in 4.7 as well. I'm not sure why this is been implemented in this way, lets wait and hear from the core team. Meanwhile, I will try to get a patch for this fix.

#3 @gabrielstuff
17 months ago

This is related to the attachment core part and the fact that video is using ID3 which using mime_type. Glad you confirmed that it is a defect. Sad to hear that this is present in 4.7

Really weird that it does not impact more people :)

Thanks !

Last edited 17 months ago by gabrielstuff (previous) (diff)

@dhanendran
17 months ago

#4 @dhanendran
17 months ago

@gabrielstuff can you tell me in which scenario you are facing this issue? Is there any situation where you are facing any Wordpress bug due to this?

#5 @gabrielstuff
17 months ago

Yup, I was planing to automatically insert attachment depending on their mime-type. I'm working on a theme where you get served with custom embed and some automatic behavior after an attachment has been uploaded.

Based on the mime-type, we generate the appropriate html markup. Unfortunately, I'm now forced to check for mime-type and mime_type. Not the end of the world, but if someone read the code, it looks like a typo first and then force you to think about the hot fix instead of thinking about the feature you are coding.

That is all !

Thanks !

#6 @johnbillion
17 months ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

#7 @birgire
7 months ago

It looks like affected files would be:

wp-includes/class-wp-image-editor.php
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
wp-includes/class-wp-image-editor-gd.php
wp-includes/media.php
wp-includes/class-wp-image-editor-imagick.php

and

tests/phpunit/tests/image/editorImagick.php
tests/phpunit/tests/image/editorGd.php
tests/phpunit/tests/image/functions.php
tests/phpunit/tests/image/intermediateSize.php
tests/phpunit/tests/media.php

Before changing these files and replace mime-type with mime_type, I wonder about all the plugins out there that might depend on mime-type?

Last edited 7 months ago by birgire (previous) (diff)
Note: See TracTickets for help on using tickets.