[wp-trac] [WordPress Trac] #48132: Unsaved changes prompt triggered by "content_save_pre" filter

WordPress Trac noreply at wordpress.org
Wed Sep 25 05:32:13 UTC 2019


#48132: Unsaved changes prompt triggered by "content_save_pre" filter
--------------------------+-----------------------------
 Reporter:  elliotcondon  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi team,

 There is a bug in WordPress 5.3-beta1 causing the "Unsaved changes promp"
 to appear when navigating away from an updated post.

 The issue is triggered by any PHP code that modifies the "post_content"
 value outside of the editor, causing the block editor to incorrectly
 believe the user has unsaved changes. I believe this is due to some logic
 within the calculate the
 `wp.data.select('core/editor').isEditedPostDirty()` function.

 There are many filters available to modify the "post_content" value such
 as "content_save_pre".

 Adding a simple callback to perform a `str_replace()` will replicate the
 issue. A common example of this being used in the real-world would be a
 company name change.

 {{{#!php
 <?php
 add_filter('content_save_pre', function( $content ){
         return str_replace("Company Name 1", "Company Name 2", $content);
 });
 }}}


 Steps to reproduce:
 1. Add the above code to `functions.php`
 2. Edit a post and include the text "Company Name 1" anywhere in the
 content
 3. Publish the post
 4. Navigate away from the post
 5. Notice the unload prompt

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48132>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list