Make WordPress Core

Ticket #3757: 3757b.diff

File 3757b.diff, 2.3 KB (added by mdawaffe, 18 years ago)
  • wp-admin/admin-functions.php

     
    2222
    2323
    2424        // Check for autosave collisions
     25        $temp_id = false;
    2526        if ( isset($_POST['temp_ID']) ) {
    2627                $temp_id = (int) $_POST['temp_ID'];
    2728                if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
     
    3334                if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
    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();
    3939                }
     
    112112        add_meta( $post_ID );
    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 );
    120126        }
     
    139145
    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
    145151        if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) )
    146152                return;
    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 ) )
    152158                        continue;
     
    279285
    280286        add_meta( $post_ID );
    281287
    282         wp_update_post( $_POST);
     288        wp_update_post( $_POST );
    283289
     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 );
     295
    284296        // Now that we have an ID we can fix any attachment anchor hrefs
    285297        fix_attachment_links( $post_ID );
    286298