Make sure attachments uploaded on unsaved drafts get reunited with their parent post. Props mdawaffe. fixes #3757

git-svn-id: https://develop.svn.wordpress.org/trunk@4884 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2007-02-15 01:03:06 +00:00
parent f2bedff370
commit 03b8080356

View File

@ -22,6 +22,7 @@ function wp_write_post() {
// Check for autosave collisions
$temp_id = false;
if ( isset($_POST['temp_ID']) ) {
$temp_id = (int) $_POST['temp_ID'];
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
@ -33,7 +34,6 @@ function wp_write_post() {
if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
$_POST['post_ID'] = $draft_ids[$temp_id];
unset($_POST['temp_ID']);
relocate_children( $temp_id, $_POST['post_ID'] );
update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
return edit_post();
}
@ -112,9 +112,15 @@ function wp_write_post() {
add_meta( $post_ID );
// Reunite any orphaned attachments with their parent
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
$draft_ids = array();
if ( $draft_temp_id = array_search( $post_ID, $draft_ids ) )
relocate_children( $draft_temp_id, $post_ID );
if ( $temp_id && $temp_id != $draft_temp_id )
relocate_children( $temp_id, $post_ID );
// Update autosave collision detection
if ( $temp_id ) {
relocate_children( $temp_id, $post_ID );
$draft_ids[$temp_id] = $post_ID;
update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
}
@ -281,6 +287,12 @@ function edit_post() {
wp_update_post( $_POST );
// Reunite any orphaned attachments with their parent
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
$draft_ids = array();
if ( $draft_temp_id = array_search( $post_ID, $draft_ids ) )
relocate_children( $draft_temp_id, $post_ID );
// Now that we have an ID we can fix any attachment anchor hrefs
fix_attachment_links( $post_ID );