UPDATE: This has been patched in WordPress Core files as of 5.62
WordPress 5.6.1 appears to have introduced a very annoyed bug where clicking away from any post in the admin, even if you haven’t modified anything, will throw up the javascript popup asking you to confirm you want to leave the site. It implies you have made changes that aren’t going to be saved even though you have not. “Leave Site? Changes you made may not be saved.”.
Luckily the smart fellow @hwk-fr has shared a patch we can put right into our functions.php file to stop this from happening ( and should be removed once wordpress updates to fix the bug ). The patch is found here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /* * WordPress 5.6.1: Window Unload Error Fix */ add_action('admin_print_footer_scripts', 'wp_561_window_unload_error_fix'); function wp_561_window_unload_error_fix(){ ?> <script> jQuery(document).ready(function($){ // Check screen if(typeof window.wp.autosave === 'undefined') return; // Data Hack var initialCompareData = { post_title: $( '#title' ).val() || '', content: $( '#content' ).val() || '', excerpt: $( '#excerpt' ).val() || '' }; var initialCompareString = window.wp.autosave.getCompareString(initialCompareData); // Fixed postChanged() window.wp.autosave.server.postChanged = function(){ var changed = false; // If there are TinyMCE instances, loop through them. if ( window.tinymce ) { window.tinymce.each( [ 'content', 'excerpt' ], function( field ) { var editor = window.tinymce.get( field ); if ( ! editor || editor.isHidden() ) { if ( ( $( '#' + field ).val() || '' ) !== initialCompareData[ field ] ) { changed = true; // Break. return false; } } else if ( editor.isDirty() ) { changed = true; return false; } } ); if ( ( $( '#title' ).val() || '' ) !== initialCompareData.post_title ) { changed = true; } return changed; } return window.wp.autosave.getCompareString() !== initialCompareString; } }); </script> <?php } |