[wp-trac] [WordPress Trac] #10494: wp_generate_attachment_metadata filter needs attachment ID

WordPress Trac wp-trac at lists.automattic.com
Mon Jul 27 05:40:25 UTC 2009


#10494: wp_generate_attachment_metadata filter needs attachment ID
-------------------------+--------------------------------------------------
 Reporter:  taco1991     |       Owner:            
     Type:  enhancement  |      Status:  new       
 Priority:  normal       |   Milestone:  Unassigned
Component:  General      |     Version:  2.8.2     
 Severity:  normal       |    Keywords:            
-------------------------+--------------------------------------------------
 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 );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10494>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list