From 0a3b4246b75a875242d84d1bee25b72a944658b9 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 21 Jan 2009 03:45:57 +0000 Subject: [PATCH] When inserting orphaned attachment in a post, set post_parent only for this attachment, see #8721 git-svn-id: https://develop.svn.wordpress.org/trunk@10390 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/media.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index ff8324816c..9c772fb618 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -370,6 +370,11 @@ add_action('media_upload_media', 'media_upload_handler'); function media_upload_form_handler() { check_admin_referer('media-form'); + if ( isset($_POST['send']) ) { + $keys = array_keys($_POST['send']); + $send_id = (int) array_shift($keys); + } + if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { $post = $_post = get_post($attachment_id, ARRAY_A); if ( isset($attachment['post_content']) ) @@ -380,8 +385,11 @@ function media_upload_form_handler() { $post['post_excerpt'] = $attachment['post_excerpt']; if ( isset($attachment['menu_order']) ) $post['menu_order'] = $attachment['menu_order']; - if ( isset($attachment['post_parent']) ) - $post['post_parent'] = $attachment['post_parent']; + + if ( isset($send_id) && $attachment_id == $send_id ) { + if ( isset($attachment['post_parent']) ) + $post['post_parent'] = $attachment['post_parent']; + } $post = apply_filters('attachment_fields_to_save', $post, $attachment); @@ -409,9 +417,7 @@ function media_upload_form_handler() { exit; } - if ( isset($_POST['send']) ) { - $keys = array_keys($_POST['send']); - $send_id = (int) array_shift($keys); + if ( isset($send_id) ) { $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); $html = $attachment['post_title']; if ( !empty($attachment['url']) ) {