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 ); });