#48132 closed defect (bug) (reported-upstream)
Unsaved changes prompt triggered by "content_save_pre" filter
Reported by: | elliotcondon | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Editor | Keywords: | |
Focuses: | Cc: |
Description
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 add_filter('content_save_pre', function( $content ){ return str_replace("Company Name 1", "Company Name 2", $content); });
Steps to reproduce:
- Add the above code to
functions.php
- Edit a post and include the text "Company Name 1" anywhere in the content
- Publish the post
- Navigate away from the post
- Notice the unload prompt
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
Unload prompt