Make WordPress Core

Changeset 23796


Ignore:
Timestamp:
03/25/2013 11:43:06 PM (13 years ago)
Author:
azaozz
Message:

Local autosave: remove the locally stored data after a post is saved. This prevents false positives when several users edit the same post multiple times. See #23220

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/autosave.js

    r23735 r23796  
    424424
    425425        /**
    426          * Set (save) post data in the storage
    427          *
     426         * Set (save or delete) post data in the storage.
     427         *
     428         * If stored_data evaluates to 'false' the storage key for the current post will be removed
     429         *
     430         * $param stored_data The post data to store or null/false/empty to delete the key
    428431         * @return bool
    429432         */
     
    434437                        return false;
    435438
    436                 stored[ 'post_' + post_id ] = stored_data;
     439                if ( stored_data )
     440                        stored[ 'post_' + post_id ] = stored_data;
     441                else if ( stored.hasOwnProperty( 'post_' + post_id ) )
     442                        delete stored[ 'post_' + post_id ];
     443                else
     444                        return false;
    437445
    438446                return this.setStorage(stored);
     
    471479
    472480                // temp logging
    473                 if ( this.debug )
    474                         console.log( 'saved, post content = %s', post_data.content );
     481                if ( typeof console != 'undefined' )
     482                        console.log( 'Local autosave: saved, post content = %s', post_data.content );
    475483
    476484                if ( result )
     
    567575                        post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id );
    568576
     577                // temp logging
     578                if ( typeof console != 'undefined' )
     579                        console.log( 'Local autosave: checkPost, cookie = %s, post content = %s', cookie, post_data && post_data.content );
     580
    569581                if ( ! post_data )
    570582                        return;
    571583
    572                 if ( cookie )
     584                if ( cookie ) {
    573585                        wpCookies.remove( 'wp-saving-post-' + post_id );
     586
     587                        if ( cookie == 'saved' ) {
     588                                // The post was saved properly, remove old data and bail
     589                                this.setData( false );
     590                                return;
     591                        }
     592                }
    574593
    575594                // There is a newer autosave. Don't show two "restore" notices at the same time.
     
    577596                        return;
    578597
    579                 // temp logging
    580                 if ( typeof console != 'undefined' )
    581                         console.log( 'checkPost, post content = %s', post_data.content );
    582 
    583                 if ( cookie == 'saved' ) {
    584                         return;
    585                 } else if ( cookie != 'check' ) {
     598                // cookie == 'check' means the post was not saved properly, always show #local-storage-notice
     599                if ( cookie != 'check' ) {
    586600                        content = $('#content').val();
    587601                        check_data = $.extend( {}, post_data );
Note: See TracChangeset for help on using the changeset viewer.