WordPress.org

Make WordPress Core

Ticket #23220: disable_save_while_disconnected.diff

File disable_save_while_disconnected.diff, 2.3 KB (added by dh-shredder, 5 years ago)

Disables Publish and Save Draft buttons during autosave and while disconnected.

  • wp-includes/js/autosave.js

    diff --git wp-includes/js/autosave.js wp-includes/js/autosave.js
    index 537d9b6..e57007f 100644
    function autosave_parse_response(response) { 
    179179// called when autosaving pre-existing post
    180180function autosave_saved(response) {
    181181        blockSave = false;
    182         autosave_parse_response(response); // parse the ajax response
    183         autosave_enable_buttons(); // re-enable disabled form buttons
     182
     183        var res = autosave_parse_response(response); // parse the ajax response
     184        if ( !res.errors )
     185                autosave_enable_buttons(); // re-enable disabled form buttons
    184186}
    185187
    186188// called when autosaving new post
    function autosave_saved_new(response) { 
    200202                        autosaveDelayPreview = false;
    201203                        doPreview();
    202204                }
    203         } else {
    204                 autosave_enable_buttons(); // re-enable disabled form buttons
    205205        }
    206206}
    207207
    function autosave_enable_buttons() { 
    236236        }, 500);
    237237}
    238238
    239 function autosave_disable_buttons() {
     239function autosave_disable_buttons( leaveDisabled ) {
    240240        jQuery(':button, :submit', '#submitpost').prop('disabled', true);
    241         // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions.
    242         setTimeout(autosave_enable_buttons, 5000);
     241
     242        if ( ! leaveDisabled ) {
     243                // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions.
     244                setTimeout(autosave_enable_buttons, 5000);
     245        }
    243246}
    244247
    245248function delayed_autosave() {
    autosave = function() { 
    256259        var rich = (typeof tinymce != "undefined") && tinymce.activeEditor && !tinymce.activeEditor.isHidden(),
    257260                post_data, doAutoSave, ed, origStatus, successCallback;
    258261
    259         autosave_disable_buttons();
     262        // Disable buttons until we know the save completed.
     263        autosave_disable_buttons( true );
    260264
    261265        post_data = wp.autosave.getPostData();
    262266
    wp.autosave.local = { 
    510514                if ( !this.blog_id )
    511515                        this.blog_id = typeof window.autosaveL10n != 'undefined' ? window.autosaveL10n.blog_id : 0;
    512516
     517                // When connection is lost, keep user from submitting changes.
     518                jQuery(document).on('heartbeat-connection-lost', function() {
     519                        autosave_disable_buttons( true ); // Leave buttons disabled.
     520                });
     521
     522                // When connection returns, make work all the things.
     523                jQuery(document).on('heartbeat-connection-restored', function() {
     524                        autosave_enable_buttons();
     525                });
     526
    513527                this.checkPost();
    514528                $(document).ready( self.run );
    515529        },