Skip to content

feat(components): addToolbarBackButton util in newspack-components#4619

Open
dkoo wants to merge 6 commits intotrunkfrom
feat/editor-back-button
Open

feat(components): addToolbarBackButton util in newspack-components#4619
dkoo wants to merge 6 commits intotrunkfrom
feat/editor-back-button

Conversation

@dkoo
Copy link
Copy Markdown
Contributor

@dkoo dkoo commented Apr 1, 2026

All Submissions:

Changes proposed in this Pull Request:

Adds a small utility function to the Newspack Components package that adds a back button to the WP block editor toolbar:

Screenshot 2026-03-31 at 5 19 44 PM

The util function relies on DOM manipulation because the WP block editor currently doesn't provide any filters or SlotFill areas to add elements to the editor toolbar. It's in the Components package so that it can be consumed and used in other Newspack repositories.

Also adds a redirect for the wp-admin/edit.php?post_type=np_gate_layout link to redirect to the main Access Control wizard page, as the core post list UI shouldn't be accessible for gate layout posts.

Closes NPPD-1393.

How to test the changes in this Pull Request:

  1. Check out this branch
  2. Visit Audience > Access Control and create a content gate
  3. Click the "Customize registered/paid access layout" buttons to edit a gate layout in the block editor
  4. Confirm that the back button is added to the top-left of the editor toolbar and that clicking it returns to the main Access Control wizard page
  5. Back in the gate layout block editor, enable Fullscreen mode (in the kebab menu at the upper-right corner)
  6. Confirm that the Newspack logo in the top-left corner of the full-screen editor also links back to the main Access Control wizard page

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo requested a review from thomasguillot April 1, 2026 15:37
@dkoo dkoo self-assigned this Apr 1, 2026
@dkoo dkoo requested a review from a team as a code owner April 1, 2026 15:37
Copilot AI review requested due to automatic review settings April 1, 2026 15:37
@dkoo dkoo added [Status] Needs Review The issue or pull request needs to be reviewed [Status] Needs Design Review labels Apr 1, 2026
@dkoo dkoo changed the title feat(components): addToolbarBackButton util in newspack-components' feat(components): addToolbarBackButton util in newspack-components Apr 1, 2026
Copy link
Copy Markdown
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 introduces a reusable utility for injecting a “back” button into the WordPress block editor toolbar (via DOM manipulation), and updates admin redirects to prevent accessing the core post list UI for gate layout posts.

Changes:

  • Add addToolbarBackButton utility in newspack-components to render a back button in the editor toolbar.
  • Use the new utility in the content gate layout editor to link back to the Access Control wizard.
  • Redirect edit.php?post_type=np_gate_layout (and gates) away from the core post list screen to the appropriate wizard page.

Reviewed changes

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

File Description
src/content-gate/editor/editor.js Calls the new toolbar back button utility from the gate layout editor UI.
packages/components/src/utils/editor-toolbar-back-button.tsx Implements the DOM + React-root injection utility for the editor toolbar back button.
includes/content-gate/class-content-gate.php Expands CPT list-screen redirects to include gate layouts and adjusts target based on Memberships state.

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

dkoo and others added 2 commits April 1, 2026 09:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@thomasguillot
Copy link
Copy Markdown
Contributor

Screenshot 2026-04-01 at 17 23 50@2x

It's a little bit odd having 2 back buttons next to each other but not behaving the same. Is it not possible to move ours on top of Core's and force Core's to stay hidden?

@dkoo
Copy link
Copy Markdown
Contributor Author

dkoo commented Apr 1, 2026

It's a little bit odd having 2 back buttons next to each other but not behaving the same. Is it not possible to move ours on top of Core's and force Core's to stay hidden?

Ah, that's in full-screen only mode, right? What if we just hid our custom one in full-screen mode? I think the main issue we're trying to solve is that Core's back button only appears in full-screen mode, so without that there's no back button.

@dkoo
Copy link
Copy Markdown
Contributor Author

dkoo commented Apr 1, 2026

@thomasguillot fb7497d hides the custom back button when the editor is in full-screen mode, avoiding the double back button issue you mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Design Review [Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants