Permalink
Browse files

When inserting orphaned attachment in a post, set post_parent only fo…

…r this attachment, fixes #8721

git-svn-id: http://svn.automattic.com/wordpress/branches/2.7@10435 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent 931052a commit d34a34af3e4dfaa87a07c3928e5e69bd3fd1fefc azaozz committed Jan 24, 2009
Showing with 10 additions and 5 deletions.
  1. +10 −5 wp-admin/includes/media.php
@@ -369,6 +369,11 @@ function media_buttons() {
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']) )
@@ -379,8 +384,10 @@ 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);
@@ -408,9 +415,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']) ) {

0 comments on commit d34a34a

Please sign in to comment.