[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
Tue Feb 16 16:45:56 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:
                                                 |  SergeyBiryukov
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  high                                 |   Milestone:  5.6.2
Component:  Editor                               |     Version:  5.6.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-screenshots has-patch commit     |     Focuses:
  fixed-major                                    |
-------------------------------------------------+-------------------------

Comment (by papijo):

 Replying to [comment:28 hwk-fr]:
 > ''This new version include a fix for an another issue and may not be
 working as it wasn't fully tested. Please refer to the original version
 for a fully functional fix. See comment:18''
 >
 > ----
 >
 >
 > After @viablethought report of early value validation problem before
 TinyMCE initialization, also present in the original 5.6.1 version, (See
 comment:27), I enhanced the original 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]
 >
 > For Core developers: In the file `wp-includes/js/autosave.js:709`,
 rewrite the `window.tinymce.each` loop to:
 >
 > {{{#!js
 > 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;
 > }
 > }}}
 >
 > For Webmasters: Here is the Standalone Fix. 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:52>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list