Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#25649 closed defect (bug) (fixed)

Warning in wp-admin/includes/images.php

Reported by: asakurayoh's profile asakurayoh Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.8 Priority: normal
Severity: normal Version: 3.6
Component: Warnings/Notices Keywords:
Focuses: Cc:

Description

So, in wp-admin/includes/images.php, on line 154, this line is throwing a warning:

unset( $metadata['image']['data'] );

because, if the file attachment is not an image (like a video or audio file) those array are not set. So I propose to change it to:

if(isset($metadata['image']) && isset($metadata['image']['data'])){
    unset( $metadata['image']['data'] );
}


Thanks

Change History (8)

#1 @helen
11 years ago

I thought unset() didn't throw any warnings for a non-existent key. Are you actually seeing this in practice or is this an IDE warning?

#2 follow-up: @asakurayoh
11 years ago

Well... it does, on EasyPHP, with errors activated, on PHP 5.2...

#3 in reply to: ↑ 2 @rmccue
11 years ago

Replying to asakurayoh:

Well... it does, on EasyPHP, with errors activated, on PHP 5.2...

What's the exact warning?

(helen: I'm guessing it's for $metadata['image'])

#4 @asakurayoh
11 years ago

The exact warning is this:

Warning: Cannot unset offset in a non-array variable in [my computer]\wp-admin\includes\image.php on line 154

So the problem is that it can't unset $metadata['image']['data'] because $metadata['image'] does'nt exists... the problem is with the multidimension array...

Thanks.

Last edited 11 years ago by SergeyBiryukov (previous) (diff)

#5 @SergeyBiryukov
11 years ago

  • Milestone changed from Awaiting Review to 3.8
  • Version changed from trunk to 3.6

The issue here is not a non-existent array key, it's that $metadata isn't always an array.

I can reproduce the warning by calling wp_generate_attachment_metadata() for an audio or video attachment that doesn't exist in the local filesystem.

Both wp_read_video_metadata() and wp_read_audio_metadata() return false in that case:
tags/3.7/src/wp-admin/includes/media.php#L2615
tags/3.7/src/wp-admin/includes/image.php#L121

And that causes the warning:

$metadata = false;
unset( $metadata['image']['data'] );

#6 @SergeyBiryukov
11 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 25968:

Avoid a PHP warning in wp_generate_attachment_metadata() if $metadata is not an array. props asakurayoh. fixes #25649.

#7 @skithund
9 years ago

[32545] from #32444 broke this again

Note: See TracTickets for help on using tickets.