Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#20720 new defect (bug)

attachment_fields_to_save filter is called twice after initial image upload in post

Reported by: williamsba1 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3
Component: Media Keywords: has-patch
Focuses: Cc:


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:

  1. 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;
  1. Create a new post
  2. 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)

20720.patch (950 bytes) - added by SergeyBiryukov 2 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 nacin2 years ago

  • Version changed from 3.4 to 3.3

comment:2 SergeyBiryukov2 years ago

  • Keywords has-patch added

Both calls are in wp_media_upload_handler().

First, media_upload_form_handler() is called in line 555:

Then media_upload_gallery() is called, which has exactly the same block:

20720.patch is an attempt to correct the logic.

SergeyBiryukov2 years ago

Note: See TracTickets for help on using tickets.