Skip to content

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

Merged
rbcorrales merged 29 commits into
trunkfrom
feat/republish-button-block
Jul 10, 2026
Merged

feat(block): add block version of the republish button#320
rbcorrales merged 29 commits into
trunkfrom
feat/republish-button-block

Conversation

@rbcorrales

@rbcorrales rbcorrales commented Mar 31, 2026

Copy link
Copy Markdown
Member

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.

The block version of the block only support the modal version of the republication tracker for now. The block is just a button has the usual button options (editing the label, colour, typography, border, shadow), plus a toggle to show/hide the license graphic that's enabled by default. The original preamble text is included by using the pattern bundled with the block.

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.

Note: some of this code may throw errors about the WordPress version the plugin claims to support (5.3). I actually updated the supported version already in newspack-workspace, and left the files here as-is in case those two PRs clashed when these changes were synced.

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. Open the Site Editor and navigate to a single post template. Search the inserter for "Republish" or "creative commons". The Republish Button block should appear under the Widgets category.
  2. Insert the block. Verify the button and an image for the current license renders:
CleanShot 2026-05-18 at 15 07 31
  1. Edit the button label and message text inline. Change display mode in the sidebar inspector.
  2. Apply color, typography, spacing, border, and anchor settings. Verify they render in the editor.
  3. Try toggling on and off the 'Show license badge' option in the Settings tab in the right sidebar. Confirm it works.
  4. Using the pattern inserter, confirm there's a section for Republication that contains one pattern. Try inserting the pattern - it should insert the original default text blurb, plus the button and license.

Frontend (modal mode):

  1. View a post; confirm the block renders and respects your settings.
  2. Click the button. A modal should open with the article content, policy, license info, and a Copy to Clipboard button. Note: The modal's updated styles are in the Classic theme, so they won't be applied -- the modal may be a little janky looking but we'll fix that in a future PR!
CleanShot 2026-05-18 at 15 13 55
  1. Close the modal via X button, Escape key, or clicking outside. Focus should return to the trigger button.
  2. Navigate to the post URL with #show-republish appended. The modal should auto-open on page load.

Post meta and filters:

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

Republication Tracker settings

  1. Navigate to Settings > Reading and scroll down to the Republication Tracker settings. And test the different options:
  2. Edit the policy text and ensure the popup picks it up.
  3. Edit the Google Analytics settings; confirm the value you add to the "Google Analytics 4 ID" is picked up in the tracking pixel that's added to the content to copy in the modal.
  4. Go through the other options and ensure that they're picked up by the site, excluding "Display attribution" - this option should now say it's "classic theme only".

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.
  2. 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>

Copilot AI left a comment

Copy link
Copy Markdown

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.

Comment thread includes/class-republish-button-block.php Outdated
Comment thread includes/class-republish-button-block.php Outdated
Comment thread src/blocks/republish-button/class-republish-button-block.php Outdated
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
@laurelfulford

Copy link
Copy Markdown
Contributor

I made some changes to the block:

  • I update the block so it's just a button with regular button settings that shows a license image after it that can be toggled on and off. The paragraph has been removed, and a pattern has been created to include the paragraph with the button and license.
  • I removed the option to open the block version in a page, and just left it as an overlay. The full page functionality expects a classic WordPress theme with a header.php and footer.php. The block theme does do kind of a fallback thing, but it doesn't match the look of the theme. We can add support for the page version if needed later!

I'm going to update the testing steps to reflect this!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 21 changed files in this pull request and generated 4 comments.

Comment thread src/blocks/republish-button/block.json
Comment thread src/blocks/republish-button/block.json
Comment thread includes/class-republish-pattern.php Outdated
Comment thread src/blocks/republish-button/view.js Outdated
@laurelfulford

laurelfulford commented May 27, 2026

Copy link
Copy Markdown
Contributor

Annnd now we're just waiting for #340 to land and clean up some dependency weirdness merging trunk into this PR caused 😅

Edited to add: this has been fixed and merged in 4a1926a. Going to have Copilot go over it one more time, then mark it as ready tor review!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.

Comment thread includes/class-republish-pattern.php
Comment thread src/blocks/republish-button/class-republish-button-block.php Outdated
Comment thread src/blocks/republish-button/block.json
Comment thread tests/bootstrap.php
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@laurelfulford laurelfulford marked this pull request as ready for review June 4, 2026 19:35
@laurelfulford laurelfulford requested a review from a team as a code owner June 4, 2026 19:35

@jason10lee jason10lee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Picking up a few old PRs from projects that were absorbed into the monorepo! The ownership/review history on this one's a little odd, so just commenting here--but I've added some notes inline that the agents and I largely agree on. Four suggestions, the rest nits. None really blocking, so if an approval is appropriate here, I'm happy to do so.

Comment thread includes/class-republish-pattern.php Outdated
Comment thread src/blocks/republish-button/class-republish-button-block.php
Comment thread src/blocks/republish-button/class-republish-button-block.php
Comment thread src/blocks/republish-button/view.js
Comment thread .gitignore Outdated
Comment thread src/blocks/republish-button/class-republish-button-block.php Outdated
Comment thread src/blocks/republish-button/class-republish-button-block.php
Comment thread src/blocks/republish-button/class-republish-button-block.php
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rbcorrales rbcorrales requested a review from jason10lee July 10, 2026 02:38

@jason10lee jason10lee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, @rbcorrales! Approved.

@rbcorrales

Copy link
Copy Markdown
Member Author

Thanks for the review @jason10lee!

@rbcorrales rbcorrales merged commit 2a6f937 into trunk Jul 10, 2026
23 checks passed
@rbcorrales rbcorrales deleted the feat/republish-button-block branch July 10, 2026 20:20
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.

4 participants