Media: When inserting an attachment, if the item is unattached (no post_parent), attach it to the post. fixes #22085.

git-svn-id: http://core.svn.wordpress.org/trunk@22843 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-11-26 16:34:42 +00:00
parent 2105efa5bf
commit ab5c08a120
2 changed files with 7 additions and 1 deletions

View File

@ -1931,6 +1931,11 @@ function wp_ajax_send_attachment_to_editor() {
if ( 'attachment' != $post->post_type ) if ( 'attachment' != $post->post_type )
wp_send_json_error(); 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'] : ''; $html = isset( $attachment['title'] ) ? $attachment['title'] : '';
if ( ! empty( $attachment['url'] ) ) { if ( ! empty( $attachment['url'] ) ) {
$rel = ''; $rel = '';

View File

@ -450,7 +450,8 @@
return media.post( 'send-attachment-to-editor', { return media.post( 'send-attachment-to-editor', {
nonce: wp.media.view.settings.nonce.sendToEditor, nonce: wp.media.view.settings.nonce.sendToEditor,
attachment: options, attachment: options,
html: html html: html,
post_id: wp.media.view.settings.postId
}).done( function( resp ) { }).done( function( resp ) {
wp.media.editor.insert( resp ); wp.media.editor.insert( resp );
}); });