Make WordPress Core

Opened 14 years ago

Closed 12 years ago

#16391 closed enhancement (fixed)

Don't add empty "_wp_attachment_metadata" on non-image media files

Reported by: caspie's profile Caspie Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: minor Version: 3.0.1
Component: Media Keywords: has-patch
Focuses: Cc:

Description

I'm currently working on a community project where there are a lot of front-end file uploads. I've noticed that when you upload a non-image file, an empty _wp_attachment_metadata is added to the postmeta table. Just did a quick patch to check the $data in wp_update_attachment_metadata function. And since $data comes always as an array from wp_generate_attachment_metadata, we do not update if it is an empty array.

Attachments (3)

16391.diff (447 bytes) - added by Caspie 14 years ago.
empty() is faster :)
16391.2.diff (1.2 KB) - added by SergeyBiryukov 12 years ago.
16391.3.diff (1.6 KB) - added by SergeyBiryukov 12 years ago.

Download all attachments as: .zip

Change History (15)

#1 follow-up: @scribu
14 years ago

You should use !empty() instead of count().

#2 @scribu
14 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from normal to minor
  • Type changed from defect (bug) to enhancement

@Caspie
14 years ago

empty() is faster :)

#3 in reply to: ↑ 1 @Caspie
14 years ago

Replying to scribu:

You should use !empty() instead of count().

thx! for better performance I guess?

#4 @scribu
14 years ago

  • Keywords has-patch added

Yep.

#5 @nacin
12 years ago

  • Keywords needs-refresh added
  • Milestone changed from Future Release to 3.5

We can actually just say if ( $data ).

#6 @SergeyBiryukov
12 years ago

  • Keywords needs-refresh removed

#7 @nacin
12 years ago

  • Keywords commit added
  • Type changed from enhancement to defect (bug)

#8 @nacin
12 years ago

  • Keywords needs-patch added; has-patch commit removed
  • Type changed from defect (bug) to enhancement

When updating an attachment with empty file or data after it previously had a meta value for _wp_attached_file or _wp_attachment_metadata, the data would not get cleared.

The options are either not applying this patch, or doing if ( $date ) update; else delete;

I no longer consider this a pure bug.

#9 @wonderboymusic
12 years ago

  • Keywords has-patch added; needs-patch removed

I like the latest Sergey approach

#10 @scribu
12 years ago

Why do we have to do this in 3 places?

#11 @wonderboymusic
12 years ago

different metadata being altered

#12 @ryan
12 years ago

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

In [21967]:

Don't add empty _wp_attached_file, _wp_attachment_metadata, _thumbnail_id meta to posts. Delete these fields when set to empty. Props SergeyBiryukov, Caspie. fixes #16391

Note: See TracTickets for help on using tickets.