Skip to content

Conversation

@enricobattocchi
Copy link
Member

Context

This PR introduces a new sidebar panel in the document settings of the block editor (Gutenberg) to manage the removal of the reference to the original post for regular copies created with Duplicate Post. The goal is to improve the user experience and make this functionality clearer and more accessible. This panel replaces the classic editor metabox for this feature in the block editor.

Summary

This PR can be summarized in the following changelog entry:

  • Replaces the metabox with a sidebar panel in the Block editor.

Relevant technical choices:

  • Use of React hooks (useState, useEffect) to manage the toggle state and synchronize with the _dp_remove_original meta field.
  • Update of the meta field via dispatch('core/editor').editPost.
  • Listening to save events to dynamically update the UI.
  • Refactoring and addition of unit tests for the new UI features.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  1. Access the block editor (Gutenberg) on a post created as a regular copy with Duplicate Post.
  2. Check for the presence of the new sidebar panel in the document settings.
  3. Toggle “Remove reference to original” on and off, then save the post.
  4. Verify that the reference is actually removed and the UI updates accordingly.
  5. Repeat the test on different post types (posts, pages, custom post types).
  6. Ensure the feature is not present in the classic editor or where not expected.
  7. In the classic editor, verify that the metabox for removing the reference to the original is still present and works as expected.
  8. Test the classic editor metabox for regressions (it should not be affected by the new sidebar panel).

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following the instructions above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Documentation

  • I have written documentation for this change. Code comments and inline instructions have been updated.

Quality assurance

  • I have tested this code to the best of my abilities
  • I have added unittests to verify the code works as intended

Innovation

  • No innovation project is applicable for this PR.

Fixes #

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the classic editor metabox with a sidebar panel in the Block editor (Gutenberg) for managing the removal of references to original posts in Duplicate Post copies. The feature uses React hooks to manage toggle state and synchronize with the _dp_remove_original meta field, improving UX by making this functionality more accessible in the block editor while maintaining backward compatibility with the classic editor.

Changes:

  • Added a new sidebar panel in the Block editor's document settings with a toggle control for removing references to original items
  • Registered the _dp_remove_original meta field for REST API access to enable block editor integration
  • Updated the metabox to not render in the block editor, delegating to the new sidebar panel instead

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
js/src/duplicate-post-edit-script.js Implements the new sidebar panel with React hooks for state management and save event handling
src/ui/block-editor.php Adds original item data and meta box visibility flag to JavaScript object for block editor
src/handlers/save-post-handler.php Registers _dp_remove_original meta field and updates save logic to handle both classic and block editor inputs
src/ui/metabox.php Prevents metabox rendering in block editor
tests/Unit/UI/Metabox_Test.php Adds test coverage for block editor metabox suppression
tests/Unit/UI/Block_Editor_Test.php Updates existing tests to handle new JavaScript object properties
css/duplicate-post.css Adds styling for the new sidebar panel

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'single' => true,
'type' => 'boolean',
'default' => false,
'auth_callback' => static function ( $allowed, $meta_key, $post_id ) {
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auth_callback function signature is incorrect. The first parameter should be named $allowed but it's not used. According to WordPress documentation, the auth_callback should return true/false based on whether the current user has permission, and it receives $allowed, $meta_key, $object_id, $meta_value as parameters. Since $allowed is unused, the parameter list is misleading. Consider removing the unused $allowed parameter or using the correct signature.

Suggested change
'auth_callback' => static function ( $allowed, $meta_key, $post_id ) {
'auth_callback' => static function ( $allowed, $meta_key, $post_id, $meta_value ) {

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +137
const [ willBeDeletedReference, setWillBeDeletedReference ] = useState( false );
const [ referenceRemoved, setReferenceRemoved ] = useState( false );
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state variable name willBeDeletedReference is ambiguous. Consider renaming to shouldRemoveReference or removeReferenceOnSave to better reflect that it represents the user's intent to remove the reference upon saving, not a future passive state.

Copilot uses AI. Check for mistakes.
>
{ ! isRewriting &&
<ToggleControl
label={ __( "Delete reference to original item.", "duplicate-post" ) }
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label text 'Delete reference to original item.' uses 'Delete' which might be confusing since the toggle help text uses 'will be deleted'. Consider using 'Remove reference to original item' for consistency with the help text and the actual functionality described.

Suggested change
label={ __( "Delete reference to original item.", "duplicate-post" ) }
label={ __( "Remove reference to original item.", "duplicate-post" ) }

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant