Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Comments and Pingbacks get cleared out when a pattern is edited. #62507

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@wordpress/editor';
import deprecated from '@wordpress/deprecated';
import { addFilter } from '@wordpress/hooks';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -289,9 +290,21 @@ export const requestMetaBoxUpdates =
window.tinyMCE.triggerSave();
}

// We gather the base form data.
const baseFormData = new window.FormData(
document.querySelector( '.metabox-base-form' )
);

const postId = baseFormData.get( 'post_ID' );
const postType = baseFormData.get( 'post_type' );

// Additional data needed for backward compatibility.
// If we do not provide this data, the post will be overridden with the default values.
const post = registry.select( editorStore ).getCurrentPost();
// We cannot rely on getCurrentPost because right now on the editor we may be editing a pattern or a template.
// We need to retrieve the post that the base form data is referring to.
const post = registry
.select( coreStore )
.getEditedEntityRecord( 'postType', postType, postId );
const additionalData = [
post.comment_status
? [ 'comment_status', post.comment_status ]
Expand All @@ -301,10 +314,7 @@ export const requestMetaBoxUpdates =
post.author ? [ 'post_author', post.author ] : false,
].filter( Boolean );

// We gather all the metaboxes locations data and the base form data.
const baseFormData = new window.FormData(
document.querySelector( '.metabox-base-form' )
);
// We gather all the metaboxes locations.
const activeMetaBoxLocations = select.getActiveMetaBoxLocations();
const formDataToMerge = [
baseFormData,
Expand Down
Loading