From 757e0dc15bc22f6b1e60f27e70654b285aa5c4ee Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 16 Feb 2021 20:23:59 +0000 Subject: [PATCH] Editor: Correct the check for unsaved content in `wp.autosave.server.postChanged()`. This fixes improper triggering of the "Are you sure?" prompt when navigating away from the old, "classic" Edit Post screen and there are no changes. The previous check did not account for Pages or any custom post types that don't have a Title, Content, or Excerpt field. Follow-up to [50031]. Props hwk-fr, mukesh27, audrasjb, archon810, Clorith, ibiza69, tonysandwich, roger995, bartosz777, viablethought, dbtedg, worldedu, hmabpera, magnuswebdesign. Merges [50232] to the 5.6 branch. Fixes #52440. Built from https://develop.svn.wordpress.org/branches/5.6@50366 git-svn-id: http://core.svn.wordpress.org/branches/5.6@49977 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/autosave.js | 4 ++-- wp-includes/js/autosave.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wp-includes/js/autosave.js b/wp-includes/js/autosave.js index a1bd570c68..1a57ead46a 100644 --- a/wp-includes/js/autosave.js +++ b/wp-includes/js/autosave.js @@ -710,7 +710,7 @@ window.autosave = function() { var editor = window.tinymce.get( field ); if ( ! editor || editor.isHidden() ) { - if ( $( '#' + field ).val() !== initialCompareData[ field ] ) { + if ( ( $( '#' + field ).val() || '' ) !== initialCompareData[ field ] ) { changed = true; // Break. return false; @@ -721,7 +721,7 @@ window.autosave = function() { } } ); - if ( $( '#title' ).val() !== initialCompareData.post_title ) { + if ( ( $( '#title' ).val() || '' ) !== initialCompareData.post_title ) { changed = true; } diff --git a/wp-includes/js/autosave.min.js b/wp-includes/js/autosave.min.js index f27e0e21a3..3acddc4142 100644 --- a/wp-includes/js/autosave.min.js +++ b/wp-includes/js/autosave.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -window.autosave=function(){return!0},function(c,a){function n(){T={post_title:c("#title").val()||"",content:c("#content").val()||"",excerpt:c("#excerpt").val()||""},w=r(T)}function i(t){var e=(new Date).getTime(),n=[],o=u();return o&&o.isDirty()&&!o.isHidden()&&H