Skip to content

feat(block): add block version of the republish button#320

Draft
rbcorrales wants to merge 15 commits intotrunkfrom
feat/republish-button-block
Draft

feat(block): add block version of the republish button#320
rbcorrales wants to merge 15 commits intotrunkfrom
feat/republish-button-block

Conversation

@rbcorrales
Copy link
Copy Markdown
Member

@rbcorrales rbcorrales commented Mar 31, 2026

All Submissions:

Changes proposed in this Pull Request:

Block themes don't have widget areas, so the existing classic widget can't be used on them. This adds a Gutenberg block (republication-tracker-tool/republish-button) that provides the same republication functionality for block themes.

The block is only registered when a block theme is active, so it doesn't interfere with the existing widget on classic themes.

It supports two display modes: modal (opens an overlay with copyable HTML and plain text content) and page (links to the /republish/ endpoint). The button label and description message are editable inline, and the block supports color, typography, spacing, border, shadow, and anchor.

All existing plugin settings are respected: policy text, license, GA4 tracking, attribution, media distribution, plain text toggle, post meta to hide the widget, and post type filters.

Also includes a small backwards compatible refactor to share the modal rendering flag between the widget and the block, so only one modal is ever rendered per page regardless of how many buttons exist.

Closes NPPD-1347.

How to test the changes in this Pull Request:

Prerequisites:

  1. Activate a block theme (e.g., newspack-block-theme or Twenty Twenty-Five)
  2. Build assets: npm ci && npm run build
  3. Configure settings at Settings > Reading (policy text, license, enable plain text)
  4. Flush permalinks at Settings > Permalinks > Save Changes

Block editor:

  1. Edit a published post. Search the inserter for "Republish" or "creative commons". The Republish Button block should appear under the Widgets category
  2. Insert the block. Verify the default message and button text render
  3. Edit the button label and message text inline. Change display mode in the sidebar inspector
  4. Apply color, typography, spacing, border, and anchor settings. Verify they render in the editor

Frontend (modal mode):

  1. View the post. The block should render with the styled wrapper, button, message, and CC license badge
  2. Click the button. A modal should open with the article content, policy, license info, HTML/Plain Text tabs, and a Copy to Clipboard button
  3. Close the modal via X button, Escape key, or clicking outside. Focus should return to the trigger button
  4. Navigate to the post URL with #show-republish appended. The modal should auto-open on page load

Frontend (page mode):

  1. Switch the block to "Page" mode in the editor and save
  2. The button should render as a link pointing to /republish/<post-permalink-path>/
  3. Click it. The full page republish template should load. No modal JS or CSS should be enqueued

Post meta and filters:

  1. Enable "Hide Republication Widget" on a post. The block should not render on the frontend
  2. Disable it. The block should render again

Widget backwards compatibility (classic theme):

  1. Switch to a classic theme (e.g., newspack-theme). The block should NOT appear in the inserter
  2. Add the Republication Tracker Tool widget to a sidebar. View a single post. The widget should render and the modal should work correctly
  3. Verify the copy button uses data-copy-active (no inline onclick) and clipboard copy works

Coexistence:

  1. On a block theme, insert two Republish Button blocks in the same post. Both buttons should render, but only one modal should exist in the DOM. Clicking either button opens the shared modal, and focus returns to the correct trigger on close

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?

rbcorrales and others added 10 commits March 30, 2026 20:11
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…and layout support

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

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

Adds a dynamic Gutenberg “Republish Button” block intended for block themes, reusing the existing republication modal/content infrastructure while avoiding duplicate modal rendering across multiple buttons/widgets.

Changes:

  • Introduces a new dynamic block (republication-tracker-tool/republish-button) with editor UI, styles, and a frontend script for modal behavior.
  • Refactors modal rendering deduplication so both widget and block share a single “modal rendered” flag.
  • Updates build tooling to generate dist/ assets (webpack config + package scripts) and adjusts packaging ignores accordingly.

Reviewed changes

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

Show a summary per file
File Description
webpack.config.js Adds webpack entries for the block editor bundle and frontend “view” bundle.
src/blocks/republish-button/index.js Registers the block client-side (editor).
src/blocks/republish-button/edit.js Implements inline-editable message/button text and inspector control for display mode.
src/blocks/republish-button/block.json Declares block metadata, supports, attributes, and built asset references in dist/.
src/blocks/republish-button/style.scss Adds minimal frontend/editor styling for the block wrapper elements.
src/blocks/republish-button/view.js Adds vanilla JS modal handling for block triggers + copy/tab behaviors.
includes/class-republish-button-block.php Registers (conditionally) and server-renders the dynamic block; enqueues modal assets when needed.
republication-tracker-tool.php Requires the new block class and introduces a shared static flag for modal deduplication.
includes/class-widget.php Switches modal deduplication to the shared static flag and updates modal include behavior.
includes/shareable-content.php Replaces inline onclick copy handler with a data-copy-active hook.
assets/widget.js Binds the copy handler via data-copy-active (matching the shareable-content change).
package.json Adds build/watch/clean + JS/SCSS lint scripts and ensures release archives include built dist/.
.gitignore Ignores dist/ in git.
.distignore Excludes src/** JS/SCSS and webpack config from release artifacts (expects built dist/).
readme.txt Updates “Requires at least” and “Tested up to” metadata.

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

rbcorrales and others added 5 commits March 30, 2026 23:11
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rbcorrales rbcorrales changed the title feat(block): add Gutenberg block version of the republish button feat(block): add block version of the republish button Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants