Make WordPress Core

Changeset 29572


Ignore:
Timestamp:
08/22/2014 12:24:56 AM (10 years ago)
Author:
azaozz
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/post.php

    r28312 r29572  
    230230
    231231    // Session cookie flag that the post was saved
    232     if ( isset( $_COOKIE['wp-saving-post-' . $post_id] ) )
    233         setcookie( 'wp-saving-post-' . $post_id, 'saved' );
     232    if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
     233        setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS );
     234    }
    234235
    235236    redirect_post($post_id); // Send user on their way while we keep working
  • trunk/src/wp-includes/js/autosave.js

    r29192 r29572  
    287287                    }
    288288
    289                     wpCookies.set( 'wp-saving-post-' + post_id, 'check' );
     289                    wpCookies.set( 'wp-saving-post', post_id + '-check', 24 * 60 * 60 );
    290290                });
    291291            }
     
    310310                var content, post_title, excerpt, $notice,
    311311                    postData = getSavedPostData(),
    312                     cookie = wpCookies.get( 'wp-saving-post-' + post_id );
     312                    cookie = wpCookies.get( 'wp-saving-post' );
     313
     314                if ( cookie === post_id + '-saved' ) {
     315                    wpCookies.remove( 'wp-saving-post' );
     316                    // The post was saved properly, remove old data and bail
     317                    setData( false );
     318                    return;
     319                }
    313320
    314321                if ( ! postData ) {
    315322                    return;
    316                 }
    317 
    318                 if ( cookie ) {
    319                     wpCookies.remove( 'wp-saving-post-' + post_id );
    320 
    321                     if ( cookie === 'saved' ) {
    322                         // The post was saved properly, remove old data and bail
    323                         setData( false );
    324                         return;
    325                     }
    326323                }
    327324
     
    335332                excerpt = $( '#excerpt' ).val() || '';
    336333
    337                 // cookie == 'check' means the post was not saved properly, always show #local-storage-notice
    338                 if ( cookie !== 'check' && compare( content, postData.content ) &&
    339                     compare( post_title, postData.post_title ) && compare( excerpt, postData.excerpt ) ) {
     334                if ( compare( content, postData.content ) && compare( post_title, postData.post_title ) &&
     335                    compare( excerpt, postData.excerpt ) ) {
    340336
    341337                    return;
Note: See TracChangeset for help on using the changeset viewer.