[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 04:14:40 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:  needs-patch has-screenshots  |     Focuses:
-----------------------------------------+---------------------

Comment (by hwk-fr):

 Hey everyone!

 I've been tired of this error message, so I decided to dig in. Found the
 solution which works in every cases

 - Post
 - Page
 - CPT with Editor
 - CPT without Editor

 Video showcase: [https://i.imgur.com/qpMYVc0.mp4]

 Here is the fix for core developers:

 In the file `\wp-includes\js\autosave.js`. Replace the line `Line 713`
 with:

 {{{#!php
 if ( ( $( '#' + field ).val() || '' ) !== initialCompareData[ field ] ) {
 }}}

 In the file `\wp-includes\js\autosave.js`. Replace the line `Line 724`
 with:

 {{{#!php
 if ( ( $( '#title' ).val() || '' ) !== initialCompareData.post_title ) {
 }}}

 This will meet the requirements of `initialCompareData` and fix the issue
 in all post types.

 For webmasters, here is a fix you can apply while waiting for the official
 patch.
 Copy paste the following code in your theme's `functions.php` file:

 {{{#!php
 <?php
 /*
  * 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 getCompareString() !== initialCompareString;

         }
     });
     </script>
     <?php
 }
 }}}

 Hope it helps!

 Have a nice day.

 Regards.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52440#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list