mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-12 13:44:21 +01:00
Autosave: prevent setting multiple stale wp-saving-post-*
cookies when the browser disregards "session cookies" expiration on quit:
- Add expiration time of 24 hours for these cookies. - Rename them to `wp-saving-post` (no post_id) so there is never more than one cookie per domain. Fixes #29294. Built from https://develop.svn.wordpress.org/trunk@29572 git-svn-id: http://core.svn.wordpress.org/trunk@29346 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5545f24b4f
commit
3d60d9f875
@ -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
|
||||
|
||||
|
@ -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 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( cookie ) {
|
||||
wpCookies.remove( 'wp-saving-post-' + post_id );
|
||||
|
||||
if ( cookie === 'saved' ) {
|
||||
if ( cookie === post_id + '-saved' ) {
|
||||
wpCookies.remove( 'wp-saving-post' );
|
||||
// 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;
|
||||
}
|
||||
|
2
wp-includes/js/autosave.min.js
vendored
2
wp-includes/js/autosave.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user