[wp-trac] [WordPress Trac] #22085: Correctly assign post_parent to uploaded attachments in the new media modal

WordPress Trac noreply at wordpress.org
Sat Nov 24 17:09:30 UTC 2012


#22085: Correctly assign post_parent to uploaded attachments in the new media modal
--------------------------+--------------------------
 Reporter:  koopersmith   |       Owner:  koopersmith
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  3.5
Component:  Media         |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+--------------------------

Comment (by nacin):

 It's handled by this in get_media_item() —

 {{{
 if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
         $parent = (int) $_REQUEST['post_id'];
         $parent_name = "attachments[$attachment_id][post_parent]";
         $item .= "\t<input type='hidden' name='$parent_name'
 id='$parent_name' value='$parent' />\n";
 }
 }}}

 And then this in media_upload_form_handler() —
 {{{
 if ( isset($send_id) && $attachment_id == $send_id ) {
         if ( isset($attachment['post_parent']) )
                 $post['post_parent'] = $attachment['post_parent'];
 }
 }}}

 I think we can handle this in wp_ajax_send_attachment_to_editor() in a
 much simpler fashion. If the attachment's post_parent is 0 at the time of
 insertion, then we can update the attachment.

 Previously, we saved and inserted at the same time. Now, they are three
 separate ajax requests, handled by wp_ajax_save_attachment(),
 wp_ajax_save_attachment_compat(), and wp_ajax_send_attachment_to_editor().
 We need to either chain compat() and send() in a single request or make
 sure that compat() returns before triggering send(), as we need to make
 sure the new values are in place before firing filters.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22085#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list