WordPress.org

Make WordPress Core

Changeset 24209


Ignore:
Timestamp:
05/08/2013 10:52:55 PM (8 years ago)
Author:
azaozz
Message:

Post locks and autosave:

  • Move nonces refreshing from autosave to lock checking.
  • Do autosave only when there is something to save.

See #23295

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ajax-actions.php

    r24206 r24209  
    10391039    define( 'DOING_AUTOSAVE', true );
    10401040
    1041     $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce' );
     1041    check_ajax_referer( 'autosave', 'autosavenonce' );
    10421042
    10431043    $_POST['post_category'] = explode(",", $_POST['catslist']);
     
    10891089        else
    10901090            $id = $post->ID;
    1091     }
    1092 
    1093     if ( $nonce_age == 2 ) {
    1094         $supplemental['replace-autosavenonce'] = wp_create_nonce('autosave');
    1095         $supplemental['replace-getpermalinknonce'] = wp_create_nonce('getpermalink');
    1096         $supplemental['replace-samplepermalinknonce'] = wp_create_nonce('samplepermalink');
    1097         $supplemental['replace-closedpostboxesnonce'] = wp_create_nonce('closedpostboxes');
    1098         $supplemental['replace-_ajax_linking_nonce'] = wp_create_nonce( 'internal-linking' );
    1099         $supplemental['replace-_wpnonce'] = wp_create_nonce( 'update-post_' . $post->ID );
    11001091    }
    11011092
  • trunk/wp-admin/includes/misc.php

    r24207 r24209  
    624624        }
    625625
     626        if ( ! empty( $received['post_nonce'] ) && 2 === wp_verify_nonce( $received['post_nonce'], 'update-post_' . $post_id ) ) {
     627            $send['update_nonces'] = array(
     628                'replace-autosavenonce' => wp_create_nonce('autosave'),
     629                'replace-getpermalinknonce' => wp_create_nonce('getpermalink'),
     630                'replace-samplepermalinknonce' => wp_create_nonce('samplepermalink'),
     631                'replace-closedpostboxesnonce' => wp_create_nonce('closedpostboxes'),
     632                'replace-_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ),
     633                'replace-_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
     634            );
     635        }
     636
    626637        $response['wp-refresh-post-lock'] = $send;
    627638    }
  • trunk/wp-admin/js/post.js

    r24116 r24209  
    253253
    254254$(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
    255     var lock = $('#active_post_lock').val(), post_id = $('#post_ID').val(), send = {};
     255    var lock = $('#active_post_lock').val(),
     256        post_id = $('#post_ID').val(),
     257        post_nonce = $('#_wpnonce').val(),
     258        send = {};
    256259
    257260    if ( !post_id )
     
    262265    if ( lock )
    263266        send['lock'] = lock;
     267
     268    if ( post_nonce )
     269        send['post_nonce'] = post_nonce;
    264270
    265271    data['wp-refresh-post-lock'] = send;
     
    287293
    288294                    // Save the latest changes and disable
    289                     autosave();
     295                    if ( ! autosave() )
     296                        window.onbeforeunload = null;
     297
    290298                    autosave = function(){};
    291299                }
     
    301309        } else if ( received.new_lock ) {
    302310            $('#active_post_lock').val( received.new_lock );
     311        }
     312
     313        if ( received.update_nonces ) {
     314            $.each( received.update_nonces, function( selector, value ) {
     315                if ( selector.match(/^replace-/) )
     316                    $( '#' + selector.replace('replace-', '') ).val( value );
     317            });
    303318        }
    304319    }
  • trunk/wp-includes/js/autosave.js

    r24042 r24209  
    255255
    256256autosave = function() {
    257     // (bool) is rich editor enabled and active
     257    var post_data = wp.autosave.getPostData(),
     258        doAutoSave = post_data.autosave,
     259        successCallback;
     260
    258261    blockSave = true;
    259     var rich = (typeof tinymce != "undefined") && tinymce.activeEditor && !tinymce.activeEditor.isHidden(),
    260         post_data, doAutoSave, ed, origStatus, successCallback;
    261 
    262     // Disable buttons until we know the save completed.
    263     autosave_disable_buttons();
    264 
    265     post_data = wp.autosave.getPostData();
    266 
    267     // We always send the ajax request in order to keep the post lock fresh.
    268     // This (bool) tells whether or not to write the post to the DB during the ajax request.
    269     doAutoSave = post_data.autosave;
    270262
    271263    // No autosave while thickbox is open (media buttons)
     
    282274        jQuery(document).triggerHandler('wpcountwords', [ post_data["content"] ]);
    283275    } else {
    284         post_data['autosave'] = 0;
    285     }
     276        return false;
     277    }
     278
     279    // Disable buttons until we know the save completed.
     280    autosave_disable_buttons();
    286281
    287282    if ( post_data["auto_draft"] == '1' ) {
     
    298293        success: successCallback
    299294    });
     295
     296    return true;
    300297}
    301298
Note: See TracChangeset for help on using the changeset viewer.