From a2eb48c7ab509d2703837ef256729a66cf345f6d Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 26 Nov 2012 16:34:42 +0000 Subject: [PATCH] Media: When inserting an attachment, if the item is unattached (no post_parent), attach it to the post. fixes #22085. git-svn-id: https://develop.svn.wordpress.org/trunk@22843 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/ajax-actions.php | 5 +++++ wp-includes/js/media-editor.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 7580f65bf4..1ea7e45053 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1931,6 +1931,11 @@ function wp_ajax_send_attachment_to_editor() { if ( 'attachment' != $post->post_type ) wp_send_json_error(); + // If this attachment is unattached, attach it. Primarily a back compat thing. + if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) { + wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) ); + } + $html = isset( $attachment['title'] ) ? $attachment['title'] : ''; if ( ! empty( $attachment['url'] ) ) { $rel = ''; diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 9ffeb3654c..4215ce63b9 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -450,7 +450,8 @@ return media.post( 'send-attachment-to-editor', { nonce: wp.media.view.settings.nonce.sendToEditor, attachment: options, - html: html + html: html, + post_id: wp.media.view.settings.postId }).done( function( resp ) { wp.media.editor.insert( resp ); });