WordPress.org

Make WordPress Core

Changeset 4884


Ignore:
Timestamp:
02/15/07 01:03:06 (7 years ago)
Author:
markjaquith
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r4809 r4884  
    2323 
    2424    // Check for autosave collisions 
     25    $temp_id = false; 
    2526    if ( isset($_POST['temp_ID']) ) { 
    2627        $temp_id = (int) $_POST['temp_ID']; 
     
    3435            $_POST['post_ID'] = $draft_ids[$temp_id]; 
    3536            unset($_POST['temp_ID']); 
    36             relocate_children( $temp_id, $_POST['post_ID'] ); 
    3737            update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); 
    3838            return edit_post(); 
     
    113113 
    114114    // Reunite any orphaned attachments with their parent 
     115    if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) 
     116        $draft_ids = array(); 
     117    if ( $draft_temp_id = array_search( $post_ID, $draft_ids ) ) 
     118        relocate_children( $draft_temp_id, $post_ID ); 
     119    if ( $temp_id && $temp_id != $draft_temp_id ) 
     120        relocate_children( $temp_id, $post_ID ); 
     121 
    115122    // Update autosave collision detection 
    116123    if ( $temp_id ) { 
    117         relocate_children( $temp_id, $post_ID ); 
    118124        $draft_ids[$temp_id] = $post_ID; 
    119125        update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); 
     
    140146    $post = & get_post( $post_ID, ARRAY_A ); 
    141147 
    142     $search = "#<a[^>]+rel=('|\" )[^'\"]*attachment[^>]*>#ie"; 
     148    $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; 
    143149 
    144150    // See if we have any rel="attachment" links 
     
    147153 
    148154    $i = 0; 
    149     $search = "#[\s]+rel=(\"|' )(.*? )wp-att-(\d+ )\\1#i"; 
     155    $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; 
    150156    foreach ( $anchor_matches[0] as $anchor ) { 
    151157        if ( 0 == preg_match( $search, $anchor, $id_matches ) ) 
     
    280286    add_meta( $post_ID ); 
    281287 
    282     wp_update_post( $_POST); 
     288    wp_update_post( $_POST ); 
     289 
     290    // Reunite any orphaned attachments with their parent 
     291    if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) 
     292        $draft_ids = array(); 
     293    if ( $draft_temp_id = array_search( $post_ID, $draft_ids ) ) 
     294        relocate_children( $draft_temp_id, $post_ID ); 
    283295 
    284296    // Now that we have an ID we can fix any attachment anchor hrefs 
Note: See TracChangeset for help on using the changeset viewer.