WordPress.org

Make WordPress Core

Opened 13 months ago

Last modified 13 months ago

#20720 new defect (bug)

attachment_fields_to_save filter is called twice after initial image upload in post

Reported by: williamsba1 Owned by:
Priority: normal Milestone: Awaiting Review
Component: Media Version: 3.3
Severity: normal Keywords: has-patch
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:

  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 13 months ago.

Download all attachments as: .zip

Change History (3)

comment:1 nacin13 months ago

  • Version changed from 3.4 to 3.3

comment:2 SergeyBiryukov13 months ago

  • Keywords has-patch added

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.

SergeyBiryukov13 months ago

Note: See TracTickets for help on using tickets.