[wp-trac] [WordPress Trac] #52440: "Leave site? Changes you made may not be saved" on custom taxonomy pages after WP 5.6.1 update
WordPress Trac
noreply at wordpress.org
Fri Feb 5 18:36:21 UTC 2021
#52440: "Leave site? Changes you made may not be saved" on custom taxonomy pages
after WP 5.6.1 update
---------------------------------------+---------------------
Reporter: archon810 | Owner: (none)
Type: defect (bug) | Status: new
Priority: high | Milestone: 5.6.2
Component: Editor | Version: 5.6.1
Severity: normal | Resolution:
Keywords: has-screenshots has-patch | Focuses:
---------------------------------------+---------------------
Comment (by hwk-fr):
After @viablethought report of early value validation problem before
TinyMCE initialization, also present in the original 5.6.1 version, (See
comment:27), here is the final fix:
- [https://core.trac.wordpress.org/raw-
attachment/ticket/52440/2021-02-05_19h23_28.mp4 Video: WordPress 5.6.1
Original Behavior]
- [https://core.trac.wordpress.org/raw-
attachment/ticket/52440/2021-02-05_19h21_41.mp4 Video: Final Fix Behavior]
In the file `wp-includes/js/autosave.js:704`, rewrite the `postChanged()`
to:
{{{#!js
function postChanged() {
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.isDirty() ) || ( $( '#' + field
).val() || '' ) !== initialCompareData[ field ] ) {
changed = true;
return false;
}
} );
if ( $( '#title' ).val() !== initialCompareData.post_title ) {
changed = true;
}
return changed;
}
return getCompareString() !== initialCompareString;
}
}}}
Standalone fix for webmasters: In the `functions.php` file, add the
following code.
{{{#!php
<?php
/*
* WordPress 5.6.1: Window Unload Error Final Fix
*/
add_action('admin_print_footer_scripts',
'wp_561_window_unload_error_final_fix');
function wp_561_window_unload_error_final_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.isDirty() ) || ( $( '#' +
field ).val() || '' ) !== initialCompareData[ field ] ) {
changed = true;
return false;
}
} );
if ( ( $( '#title' ).val() || '' ) !==
initialCompareData.post_title ) {
changed = true;
}
return changed;
}
return window.wp.autosave.getCompareString() !==
initialCompareString;
}
});
</script>
<?php
}
}}}
Hope it helps!
Regards.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52440#comment:28>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list