fix: remove stale Note references from cloned posts - #550
Open
faisalahammad wants to merge 1 commit into
Open
faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
WordPress 6.9 stores editor Notes as comments with the note type, and blocks reference them through attrs.metadata.noteId. Comments of the note type are not copied when a post is cloned, so the copy kept block markup pointing at Notes that only exist on the original post. The new Notes_Cleaner service collects the note IDs that belong to the duplicated post and removes every other noteId reference from the block markup, including references nested in inner blocks. Valid references are kept, so the fix works alongside copying Notes. Rewrite and Republish is left alone, because its copy is written back to the original post, where the referenced Notes still exist. The hook runs at priority 46, after comments are copied, so Notes copied to the duplicate are already in place when the validation runs. Adds WP integration tests for the clone flow and for the retention of valid references. Fixes Yoast#420
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
WordPress 6.9 stores the editor Notes as comments with
comment_typenote, and the block markup keeps a reference to the note in the blockmetadata.noteIdattribute. Notes are not copied when a post is cloned, so the copy kept block references pointing at Notes that only exist on the original post. The editor shows these as broken references on the copy.Fixes #420
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Notes_Cleanerclass insrc/notes-cleaner.php. It collects the note IDs that belong to the duplicated post withget_comments( [ 'type' => 'note' ] )and removes every othermetadata.noteIdreference from the block markup, including references inside nested blocks.parse_blocks()and saved back withserialize_blocks(), so only block metadata is touched and the rest of the content stays as it is.metadata.noteIdare handled, since newer block markup stores a list of note IDs.duplicate_post_after_duplicatedhook at priority 46, right after the comments handler at 40 and before taxonomies at 50, so Notes copied to the duplicate (when that option is on) are already in place before the validation runs.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Relevant test scenarios
The check was limited to the block editor on posts and pages. Classic editor posts have no block metadata, so nothing changes for them.
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Use the same steps as above.
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Documentation
Quality assurance
Innovation
innovationlabel and noted the work hours.Fixes #420