Opened 11 years ago
Closed 9 years ago
#20720 closed defect (bug) (fixed)
attachment_fields_to_save filter is called twice after initial image upload in post
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | 3.3 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
I believe I found a bug in WordPress with the attachment_fields_to_save filter. For some reason attachment_fields_to_save is called twice per image, but only if you "Save all changes" after uploading a new image to a post.
How to reproduce:
- Add the below code to a plugin:
add_filter( 'attachment_fields_to_save', 'test_attachment_fields_to_save', 10, 2 ); function test_attachment_fields_to_save( $post, $attachment ) { echo 'Hi! </br >'; return $post; }
- Create a new post
- Upload a single image and click "Save all changes"
You'll see "Hi!" displayed twice. Now visit the Gallery tab and save the same image and you'll see "Hi!" is only displayed once. This only happens when you save a new image uploaded to a post. If you save an image under the Gallery tab, or via the Media Library, the filter is only called once as expected.
I confirmed this is happening in 3.3.1 and trunk
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
Both calls are in
wp_media_upload_handler()
.First,
media_upload_form_handler()
is called in line 555:http://core.trac.wordpress.org/browser/tags/3.3.2/wp-admin/includes/media.php#L554
Then
media_upload_gallery()
is called, which has exactly the same block:http://core.trac.wordpress.org/browser/tags/3.3.2/wp-admin/includes/media.php#L637
20720.patch is an attempt to correct the logic.