diff --git a/src/wp-admin/post.php b/src/wp-admin/post.php index 19c21a745d..805c46e6ed 100644 --- a/src/wp-admin/post.php +++ b/src/wp-admin/post.php @@ -229,8 +229,9 @@ case 'editpost': $post_id = edit_post(); // Session cookie flag that the post was saved - if ( isset( $_COOKIE['wp-saving-post-' . $post_id] ) ) - setcookie( 'wp-saving-post-' . $post_id, 'saved' ); + if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) { + setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS ); + } redirect_post($post_id); // Send user on their way while we keep working diff --git a/src/wp-includes/js/autosave.js b/src/wp-includes/js/autosave.js index dd08cb4e35..b338e94982 100644 --- a/src/wp-includes/js/autosave.js +++ b/src/wp-includes/js/autosave.js @@ -286,7 +286,7 @@ window.autosave = function() { }); } - wpCookies.set( 'wp-saving-post-' + post_id, 'check' ); + wpCookies.set( 'wp-saving-post', post_id + '-check', 24 * 60 * 60 ); }); } @@ -309,20 +309,17 @@ window.autosave = function() { function checkPost() { var content, post_title, excerpt, $notice, postData = getSavedPostData(), - cookie = wpCookies.get( 'wp-saving-post-' + post_id ); + cookie = wpCookies.get( 'wp-saving-post' ); - if ( ! postData ) { + if ( cookie === post_id + '-saved' ) { + wpCookies.remove( 'wp-saving-post' ); + // The post was saved properly, remove old data and bail + setData( false ); return; } - if ( cookie ) { - wpCookies.remove( 'wp-saving-post-' + post_id ); - - if ( cookie === 'saved' ) { - // The post was saved properly, remove old data and bail - setData( false ); - return; - } + if ( ! postData ) { + return; } // There is a newer autosave. Don't show two "restore" notices at the same time. @@ -334,9 +331,8 @@ window.autosave = function() { post_title = $( '#title' ).val() || ''; excerpt = $( '#excerpt' ).val() || ''; - // cookie == 'check' means the post was not saved properly, always show #local-storage-notice - if ( cookie !== 'check' && compare( content, postData.content ) && - compare( post_title, postData.post_title ) && compare( excerpt, postData.excerpt ) ) { + if ( compare( content, postData.content ) && compare( post_title, postData.post_title ) && + compare( excerpt, postData.excerpt ) ) { return; }