Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#10494 closed enhancement (fixed)

wp_generate_attachment_metadata filter needs attachment ID

Reported by: taco1991's profile taco1991 Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8.2
Component: General Keywords:
Focuses: Cc:

Description

The wp_generate_attachment_metadata filter (/wp-admin/includes/image.php line 124) passes only the metadata array to any functions using that hook:

   return apply_filters( 'wp_generate_attachment_metadata', $metadata );

The filter is useless without the attachment ID of the new item. And for anything that's not an image, $metadata is empty so you have no idea what the new attachment is.

Instead it should be just like the wp_update_attachment_metadata filter and include the attachment ID as a second argument (/wp-includes/post.php line 2668):

   $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );

I stumbled on this as I was writing a plugin to handle new attachments. The easiest and best way to add extra metadata at create time is to use the wp_generate_attachment_metadata hook. But without the ID, I don't know which file to update.

Simply adding the post ID to the function would make this filter awesome. I'm having trouble making a patch, but here's the new code for /wp-admin/includes/image.php line 124:

   return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );

Change History (2)

#1 @azaozz
16 years ago

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

(In [11747]) Add attachment ID to the wp_generate_attachment_metadata filter, props taco1991, fixes #10494

#2 @azaozz
16 years ago

  • Milestone changed from Unassigned to 2.9
Note: See TracTickets for help on using tickets.