WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10494 closed enhancement (fixed)

wp_generate_attachment_metadata filter needs attachment ID

Reported by: 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)

comment:1 azaozz5 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

comment:2 azaozz5 years ago

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