diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2007-01-18 11:27:26 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2007-01-18 11:27:26 +0000 |
commit | acdcdacc2fe65422a3f52e3320283feba13d9c40 (patch) | |
tree | bad2b7ef0aef1f89e9abc6bafa0264a3ba302f46 /wp-admin/admin-functions.php | |
parent | 26b0392f7796ed87daa7725a33ac87057b3b2a4c (diff) | |
download | wordpress-mu-acdcdacc2fe65422a3f52e3320283feba13d9c40.tar.gz wordpress-mu-acdcdacc2fe65422a3f52e3320283feba13d9c40.tar.xz wordpress-mu-acdcdacc2fe65422a3f52e3320283feba13d9c40.zip |
WP Merge to rev 4763
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@851 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/admin-functions.php')
-rw-r--r-- | wp-admin/admin-functions.php | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index aa9fa78..e2ef065 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -20,6 +20,25 @@ function wp_write_post() { return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) ); } + + // Check for autosave collisions + if ( isset($_POST['temp_ID']) ) { + $temp_id = (int) $_POST['temp_ID']; + if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) + $draft_ids = array(); + foreach ( $draft_ids as $temp => $real ) + if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then ) + unset($draft_ids[$temp]); + + 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(); + } + } + // Rename. $_POST['post_content'] = $_POST['content']; $_POST['post_excerpt'] = $_POST['excerpt']; @@ -88,12 +107,17 @@ function wp_write_post() { } // Create the post. - $post_ID = wp_insert_post( $_POST); + $post_ID = wp_insert_post( $_POST ); + add_meta( $post_ID ); // Reunite any orphaned attachments with their parent - if ( $_POST['temp_ID'] ) - relocate_children( $_POST['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 ); + } // Now that we have an ID we can fix any attachment anchor hrefs fix_attachment_links( $post_ID ); @@ -165,6 +189,17 @@ function edit_post() { wp_die( __('You are not allowed to edit this post.' )); } + // Autosave shouldn't save too soon after a real save + if ( 'autosave' == $_POST['action'] ) { + $post =& get_post( $post_ID ); + $now = time(); + $then = strtotime($post->post_date_gmt . ' +0000'); + // Keep autosave_interval in sync with autosave-js.php. + $delta = apply_filters( 'autosave_interval', 120 ) / 2; + if ( ($now - $then) < $delta ) + return $post_ID; + } + // Rename. $_POST['ID'] = (int) $_POST['post_ID']; $_POST['post_content'] = $_POST['content']; |