Skip to content

Add subscriber gating blocks and settings - #201

Open
phpbits wants to merge 45 commits into
mainfrom
feature/19815117-subscriber-gating
Open

phpbits wants to merge 45 commits into
mainfrom
feature/19815117-subscriber-gating

Conversation

@phpbits

@phpbits phpbits commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds subscriber gating to the plugin (Teamwork task 19815117). Editors wrap content in a Gated Content block. Readers see a preview, then blurred locked content behind a subscribe card. Submitting the block's own beehiiv form unlocks the content in place and sets a site-wide cookie.

  • Gated Content block (beehiiv/gated-content) holds inner blocks and renders on the server. The first inner block is the preview, or everything before an optional Gate Divider block. Per-block form ID, headline and text, plus card background and text colours.
  • Gate Divider block (beehiiv/gated-content-divider) is allowed only directly inside a gated block.
  • Settings page: a new "Subscriber gating" section with the default headline, text, subscribe form ID and unlock cookie lifetime (1 to 365 days, default 30).
  • Front end: the script listens for BEEHIIV_SUBSCRIBER_FORM_SUBMITTED from subscribe-forms.beehiiv.com (and the legacy embed host) and unlocks only when externalEmbedId matches the block's form ID.
  • Editor: missing-publication notice with a link to the settings page, dotted block outline, and an editor marker where the wall falls.

Behavior worth knowing

  • Logged-in users always see the full post (client decision).
  • Only the first gated block on a page counts.
  • The server always renders the gate and the browser removes it when the cookie exists, so it works behind page caching. Returning readers may see a brief flash.
  • Gated content stays in the page source (soft wall).
  • Added at the team's request, not in the client's original spec: card colour options and the default subscribe form ID.

Testing

  • Jest: tests/js/gated-content-view.test.js (6 tests) passes.
  • Lint: ESLint, stylelint and phpcs clean on the changed source.
  • Confirmed manually against a real beehiiv form: the submit message matches and the gate unlocks.
  • Not run: PHPUnit (GatedContentRenderTest, SubscriberGateDefaultsTest) and the Playwright e2e suite for this feature.

Known gaps

  • Publication select on the settings page is a required field, so gate defaults cannot be saved until a publication is chosen.
  • The missing-publication notice only shows on post screens, because the plugin loads its editor settings there only.

Feature: admin-interface/settings-page/subscriber-gate-defaults

Implements:
- US-001: default gate headline and text with fallback on read
- US-002: unlock cookie lifetime, whole days 1 to 365, else 30
- US-003: Publication and Subscriber gating saves keep each other's values

The Subscriber gating section prints for every administrator, including
when the Publication section is hidden. Options::get_gate_settings()
returns final values for the gated content block.
Feature: custom-blocks/gated-content-block/gated-content-block

Implements:
- US-001: gated block with Subscribe form ID, Headline and Text
- US-002: optional gate divider, valid only directly inside the gated block
- US-003: server-rendered gate card over blurred, height-limited locked content
- US-004: unlock in place when the block's own form is submitted
- US-005: site-wide unlock cookie, logged-in bypass, first gate per page
- US-006: locked content is inert and hidden from assistive technology

The gate view script loads only on pages that render a gated block.
…ew blocks

has_divider() re-iterated the shared inner block list from inside the loop
over that same list, so the cursor reset and the loop never ended whenever
two or more blocks came before the divider (or no divider was present).
…gated block, restore publication reset on save
…ard"

The form's alignment is set inside the beehiiv form itself, so the card CSS had no effect.
…editor (#195)

* feat(editor-integration): preview the real beehiiv email of a saved post in the editor

Adds a Preview email button and modal (desktop and mobile views, from, subject and
preview text, sandboxed inert frame), a REST route that syncs a linked beehiiv draft
from the saved post and fetches the rendered email, and the draft lifecycle it needs:
created on first preview, updated in place, recreated when the publication or template
changes, kept across status changes, removed when Send to newsletter is turned off or
the post is deleted.

* fix(newsletter-publishing): import WP_Error in the sender

* chore: revert unrelated whitespace change in the publication send test

* fix(newsletter-publishing): replace a previewed draft with a real send on publish or schedule

* fix(newsletter-publishing): lock simultaneous previews so only one draft is created

* fix(editor-integration): poll for the preview email from the editor instead of waiting in PHP

* refactor(editor-integration): harden the preview frame, share the post read, and fix the preview E2E expectations

* refactor(editor-integration): share one preview eligibility check, purge stale locks, memoize the inert email, and cover the new paths

* refactor(editor-integration): move preview eligibility into its own class and lengthen the preview lock
* feat: meet WordPress VIP Integration Center conformance checks

Add vip-manifest.yaml, run PHPUnit and Playwright from composer test,
and widen the CI matrix to WP 6.9/7.0 and PHP 8.2-8.5.

* feat: read WordPress VIP runtime config

Read the VIP_BEEHIIV_CONFIG array for the API base URL, falling back to the
wp-config constant and the default. Missing or invalid config is ignored.
Add fixtures, tests, and README examples.
…specs

Options::sanitize() ignored the publication fields unless the section flag was present. WordPress runs the callback twice on the first save, when no option row exists, and the second run has no flag. The first save therefore stored a blank publication and template. Submitted fields are now always applied, and a shown section still clears missing ones.

E2E specs now send the section flag as the real form does, expect the gate defaults and the gateFormId key, and no longer expect a required publication select. The gated-content spec makes sure a theme is active, because a tests site with a missing theme renders blank front-end pages.
The settings page left the post template select enabled when no publication was chosen, which did not match the PRD. It is now disabled on page load when there is no publication, and the settings script disables it again when the publication is cleared. A disabled field is not submitted, and the shown Publication section already saves a missing template as blank.

The publication spec no longer expects this to fail and now checks the field both ways. One PHPUnit case used a lone paragraph as the nothing-to-gate example, but a block with no divider is fully gated. It now uses a divider with nothing after it.
Choosing a publication and then clearing it started two template loads. The first load finished last and re-enabled the post template dropdown with templates for a publication that was no longer selected. Each load now checks that it is still the newest one before it changes the page. Clearing the publication also resets the refresh button label.
* test(e2e): add intake demo recording scripts

Playwright config, helpers and per-intake walkthrough scripts that record
one captioned demo video per intake. Output goes to the gitignored
tests/e2e/test-results/demo/ folder.

* test(e2e): add demo walkthrough for the require-template-choice intake

Records the settings toggle, the empty template field, the blocked send and
the unblocked send on the feature/19814561-settings-require-template build.

* test(e2e): show the pre-publish panel notice in the require-template demo

* test(e2e): add demo walkthrough for the email preview intake

Records the Preview email control, the sandboxed preview modal, the
save-before-preview rule, a failed preview with retry, and the unavailable
state on an already scheduled post.

* test(e2e): add mobile view to the email preview demo

* test(e2e): add demo walkthrough for the subscriber gating intake

* test(e2e): add demo walkthrough for the Group section intake
* feat(newsletter-publishing): convert Group blocks to beehiiv sections

Feature: newsletter-publishing/block-conversion/block-conversion-framework

Implements:
- US-006: A Group block becomes a beehiiv section holding its converted inner blocks

Posts first synced with this change keep sections on later syncs. Posts synced before it keep omitting Group blocks.

* test(e2e): cover block conversion framework acceptance criteria

* fix(newsletter-publishing): omit Groups nested in a Group from the beehiiv payload

beehiiv rejects a section inside a section, so the post failed to sync.
A Group inside a Group is now omitted with its inner blocks, and the editor
counts it in the omitted-block notice and marks it with the hidden icon.

* test(e2e): cover the editor notice for a Group nested in a Group

* fix(editor): show the omitted-block notice on scheduled posts linked to beehiiv

A linked post turns Send to newsletter off, which hid the notice and the
hidden-block icon while its newsletter was still scheduled and syncing edits.

* style(editor): remove the top margin on the omitted-block notice

* fix(editor): mark omitted blocks on the block element and only while the beehiiv sidebar is open

The marker no longer wraps the block in an extra element. The hidden-eye icon is
drawn on the block itself and stays visible without hovering.

* style(editor): add a gap above the omitted-blocks line only when it follows the send warning text

* Send a Group's background color, text color and padding as the section's visual settings

Colors come from custom values or the theme palette. Padding is sent in whole pixels
per side; rem and em convert at 16 pixels, and sides in percent or fluid units keep
beehiiv's default. Borders and other Group styling are not sent yet.

* Send a Group's border color, width, style and radius as the section's visual settings

A border with a color or width and no style is sent as solid. Palette colors, including
the var:preset|color|slug values the editor stores on a border with a different width
on each side, are sent as their color value. Styles beehiiv does not accept, colors and
styles that differ by side, and widths or radii in percent are not sent.

* Send a Group's margin as outer spacing and resolve theme and fluid spacing sizes

A Group's margin is sent as the section's outer spacing, next to padding as inner
spacing. A size chosen by name from the theme is read from the theme's own definition:
presets are applied in WordPress's order (default, theme, custom), and the default sizes
and colors are skipped when the theme turns them off, so a theme that redefines a default
name no longer gets WordPress's default value. A fluid size (clamp, min or max) is sent
at its widest fixed value.
* feat(admin-interface): add require-template-choice setting

Feature: admin-interface/settings-page/publication-template-config

Implements:
- US-007: Require editors to choose a template (setting only; enforcement and editor display live in other PRDs)

Verified:
- AC-014: toggle with the agreed label
- AC-015: off by default
- AC-016: saved state persists
- AC-017: help text covers the three points
- AC-018: shown in the existing connected-only section
- AC-019: publication and template selections unchanged

* test(admin-interface): cover require-template-choice setting in e2e

* feat(newsletter-publishing): block sending until an editor chooses a template

Feature: newsletter-publishing/newsletter-template-selection/post-template-selection

Implements:
- US-004: Require an editor-chosen template (send-time rule)

Verified:
- AC-009: default used when setting off or post already sent
- AC-012: no automatic template when the rule applies
- AC-013: send blocked even with a site default
- AC-014: agreed message, no beehiiv request
- AC-015: all roles
- AC-016: sent posts exempt
- AC-017: chosen template continues
- AC-018: setting off behaves as before

* test(newsletter-publishing): cover required-template rule in e2e

* feat(editor-integration): ask editors to choose a template when required

Feature: editor-integration/editor-sidebar/newsletter-template-selection

Implements:
- US-007: Required template prompt in the editor sidebar

Verified:
- AC-002: default behavior unchanged when the setting is off or the post was sent
- AC-014: empty field with the Choose a template prompt
- AC-015: no pre-selected template and no default label
- AC-016: help text under the empty field
- AC-017: blocked send shows the message through the existing error notice
- AC-018: prompt and help clear once a template is chosen
- AC-019: unchanged when the setting is off or the post was sent

* test(editor-integration): cover required-template prompt in e2e

* fix(editor-integration): show required-template notice as an error in the publish panel

Open the pre-publish panel when the newsletter still needs a template,
show the required-template message as an error, and add top spacing to
beehiiv notices outside the sidebar.

* fix(editor-integration): meet template picker ACs and update tests for the new setting

Show help text for the default template, a loading spinner while templates
load, and an unavailable label for deleted templates. Add publish-panel e2e
tests, and update the settings storage and validation e2e specs for the new
require-template setting.
…iiv columns (#199)

* feat(newsletter-publishing): convert top-level Columns blocks to beehiiv columns

Feature: newsletter-publishing/block-conversion/structured-content-blocks

Implements:
- US-006: A Columns block in a post becomes one beehiiv columns block

Verified:
- AC-008, AC-011 to AC-019 covered by PHPUnit tests
- Up to 3 columns per block; more columns, or columns nested in a column, put their inner blocks at the top level
- px/em/rem widths become a share of the row; percent widths round per column

* test(newsletter-publishing): add E2E specs for block conversion PRDs

Covers structured-content-blocks (AC-001 to AC-019) and block-conversion-framework (AC-001 to AC-008). Two specs assert known gaps and currently fail: table background color (AC-010) and a non-breaking-space paragraph (AC-005).

* fix(newsletter-publishing): send table block background color to beehiiv

A table with a block background color sent no color. The color is now read from the
block attributes, the table tag, or the figure wrapper, and sent as visual settings
the same way lists and paragraphs send it.

* fix(newsletter-publishing): omit paragraphs that hold only a non-breaking space

A paragraph with only a non-breaking space was still sent as a text block. The check
now treats non-breaking spaces as blank.

* fix(newsletter-publishing): omit Media & Text blocks that have no valid image

The PRD says a Media & Text block with no valid image URL is omitted. The converter
kept the text column instead. The whole block is now omitted.

* feat(editor): mark omitted blocks on the block itself while the beehiiv sidebar is open

The marker adds a class and tooltip to the block's own element instead of wrapping
the block, shows only while the beehiiv sidebar is open, keeps the hidden-eye icon
visible, and also covers posts linked to a scheduled newsletter.

* style(editor): add a gap above the omitted-blocks line only when it follows the send warning text

* feat(newsletter-publishing): omit Columns blocks with more than 3 columns and mark them in the editor

A Columns block with more than 3 columns was sent as top-level blocks. It is now
omitted from the newsletter, and the editor marks it and counts it in the omitted
blocks notice, the same as other blocks the newsletter leaves out. The column limit
is shared with the editor through the block support config.

* Send a Columns block's colors, padding, margin and border as the columns block's visual settings

A Columns block's background color, text color, padding, margin and border are now sent
as the visual settings of the beehiiv columns block, the same way a Group's styling is
sent for its section. Colors come from custom values or the theme palette. Padding and
margin are sent in whole pixels per side as inner and outer spacing, and rem and em
convert at 16 pixels. The border sends its color, width, style and radius, and a border
with a color or width and no style is sent as solid. Sides, styles and units beehiiv
cannot take are left out so it keeps its default.

The styling code is a self-contained copy of the Group version, so this branch does not
depend on the Group branch. The two can share one class after both land.

* Wrap a styled Columns block in a beehiiv section that carries its styling

beehiiv holds a container's styling on a section, so a Columns block with a background
color, text color, padding, margin or border that beehiiv can take is now sent as a
section with those visual settings, holding the plain columns block. A Columns block
with no styling that converts stays a plain columns block, and a Columns block with
more than 3 columns, or with nothing convertible inside, is still not sent.

* Revert "Wrap a styled Columns block in a beehiiv section that carries its styling"

This reverts commit 34dd1c4.

* Revert "Send a Columns block's colors, padding, margin and border as the columns block's visual settings"

This reverts commit 2a5305b.

* Use theme palette colors and a full title replace in the e2e specs after the release merge
@phpbits
phpbits changed the base branch from main to release/1.2.0 November 13, 2026 09:48
@phpbits
phpbits marked this pull request as ready for review November 13, 2026 09:48
…5117-subscriber-gating

# Conflicts:
#	.github/workflows/test.yml
#	includes/Admin/Options.php
#	includes/Editor/PostSettings.php
#	languages/beehiiv.pot
#	readme.txt
#	src/js/editor/post-settings/hooks/use-beehiiv-editor-config.js
#	tests/e2e/specs/publication-template-config.spec.js
#	tests/e2e/specs/settings-storage-retrieval.spec.js
Base automatically changed from release/1.2.0 to main November 16, 2026 17:38
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.

1 participant