Skip to content

refactor(emails): move Emails from Settings to Audience Configuration#4759

Open
kmwilkerson wants to merge 2 commits into
nppd-1537-sync-site-styles-into-wc-email-optionsfrom
nppd-1538-move-emails-to-audience-configuration
Open

refactor(emails): move Emails from Settings to Audience Configuration#4759
kmwilkerson wants to merge 2 commits into
nppd-1537-sync-site-styles-into-wc-email-optionsfrom
nppd-1538-move-emails-to-audience-configuration

Conversation

@kmwilkerson
Copy link
Copy Markdown

@kmwilkerson kmwilkerson commented May 26, 2026

What this PR does

Moves the unified Emails management UI from Newspack → Settings → Emails to Audience → Configuration → Emails, where it sits alongside the other audience-configuration surfaces (NPPD-1538).

Nav-and-routing change only. The Emails screen itself (chips, DataViews, registry, preview thumbnails, toggle behavior) is unchanged. The REST API also stays at its existing path so no external callers break.

Final piece of the project's UI consolidation work — Emails now lives where publishers will look for it.

Depends on slice 2 (#4732), NPPD-1524 (#4756), and NPPD-1537 (#4758) — branched off that stack and inherits their changes.

Code changes

Backend — includes/wizards/newspack/class-emails-section.php

  • $wizard_slug changed from 'newspack-settings' to 'newspack-audience' so the section registers under the Audience wizard
  • New REST_BASE constant hardcoded to 'wizard/newspack-settings/emails' with a docblock explaining the historical naming for API stability. All register_rest_route() calls use self::REST_BASE instead of deriving from $wizard_slug — REST routes stay at their existing paths regardless of which parent wizard owns the admin screen

Backend — includes/class-wizards.php

  • Removed 'emails' section from the newspack-settings wizard instantiation
  • Passed 'emails' section to the audience wizard via the new $args parameter

Backend — includes/wizards/audience/class-audience-wizard.php

  • Constructor accepts and forwards $args to parent::__construct() so sections can be passed in
  • enqueue_scripts_and_styles() localizes the emails config (isEmailEnhancementsActive, dependencies, postType) onto window.newspackAudience.emails

Backend — includes/wizards/newspack/class-newspack-settings.php

  • Removed the emails block from get_local_data() and dropped the now-unused imports (Emails, Reader_Revenue_Emails, WooCommerce_Emails)
  • Added an inline redirect script on the Settings page: when window.location.hash === '#/emails', redirects to admin.php?page=newspack-audience#/emails before React mounts. Handles old bookmarks without a server-side redirect (the hash fragment is invisible to PHP)

Frontend — src/wizards/audience/views/setup/emails/ (moved from src/wizards/newspack/views/settings/emails/)

  • 8 files moved as a unit: index.tsx, emails.tsx, settings.tsx, email-preview.tsx, email-preview.scss, plus their tests. Directory nesting depth is unchanged, so existing relative imports continue resolving correctly without path edits
  • index.tsx: data source switched from window.newspackSettings.emails.sections.emails.isEmailEnhancementsActive to the flattened window.newspackAudience.emails.isEmailEnhancementsActive
  • emails.tsx: reads config from window.newspackAudience.emails

Frontend — src/wizards/audience/views/setup/index.js

  • Added Emails import, appended the "Emails" tab unconditionally (matches current Settings behavior — screen contents continue to adapt via isEmailEnhancementsActive)
  • Inline comment documents the array-end positioning: Emails stays last whether Content Gating (current state) or Access Control (future state, separate flag-gated project) is the preceding tab
  • Added /emails route

Frontend — src/wizards/newspack/views/settings/sections.tsx

  • Removed Emails import and the emails entry from the sections mapping

Frontend — TypeScript

  • src/wizards/types/window.d.ts: added emails property to the newspackAudience interface
  • src/wizards/newspack/types/index.d.ts: removed emails from the newspackSettings interface

Frontend — Tests

  • src/wizards/audience/views/setup/emails/emails.test.js: updated mock setup from window.newspackSettings to window.newspackAudience with the flattened structure
  • email-preview.test.js: existing mock paths unchanged (REST API paths stayed put)

Why this PR

The Emails management UI has grown into a comprehensive audience-configuration surface (registry, chips, WC integration, preview thumbnails, card expiry warning, branded WC Subs delivery). It belongs alongside the other Audience → Configuration screens — Configuration, Checkout & Payment, and eventually Access Control.

The single non-obvious choice in this PR is keeping the REST API at the old path (wizard/newspack-settings/emails). The motivation: REST paths are part of the contract with external callers (Newspack Manager, third-party integrations, tooling). Moving them would break things outside this repo for no UX benefit. The frontend doesn't care which path the API lives at — it just hits whatever path is configured.

Manual testing

Tested locally with Newspack, WooCommerce, WooCommerce Subscriptions, and the WC Block Email Editor feature enabled. Verified:

  • Audience → Configuration shows the Emails tab as the last item in the array (currently after Content Gating + Checkout & Payment)
  • Clicking the Emails tab renders the full screen — chips, search, toggles, preview thumbnails all work
  • Old bookmark admin.php?page=newspack-settings#/emails redirects to admin.php?page=newspack-audience#/emails
  • Newspack → Settings no longer surfaces an Emails tab; other Settings tabs (Reader Activation, Connections, etc.) still render correctly
  • REST API still responds at /newspack/v1/wizard/newspack-settings/emails (confirmed via network tab and direct curl)
  • Toggling, search, chip switching, preview rendering on the Emails screen all continue to work post-move

Note: 3 pre-existing TypeScript warnings on DataViews generics carried over from trunk — not introduced by this PR.

PHPUnit, Jest (49 suites / 438 tests), and webpack all green locally; PHPCS clean on changed files.

All Submissions:

@kmwilkerson kmwilkerson requested a review from Copilot May 26, 2026 22:13
@kmwilkerson kmwilkerson marked this pull request as ready for review May 26, 2026 22:17
@kmwilkerson kmwilkerson requested a review from a team as a code owner May 26, 2026 22:17
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

Moves the unified Emails management UI from Newspack → Settings to Audience → Configuration as the last tab. The Emails screen itself (chips, DataViews, registry, preview thumbnails, toggle behavior) is unchanged; REST API paths remain stable via a hardcoded REST_BASE constant on Emails_Section, and a small inline redirect forwards bookmarks from the old hash URL to the new one.

Changes:

  • Re-registers the Emails_Section under the Audience wizard (class-wizards.php, class-audience-wizard.php) while keeping the REST namespace wizard/newspack-settings/emails for backwards compatibility.
  • Removes the Emails tab/data from the Settings wizard (PHP localized data, TS types, sections registry) and adds it to the Audience wizard (route, tab, localized window.newspackAudience.emails).
  • Adds an inline redirect on the old Settings page from #/emails to the new Audience URL, plus a minor typo fix in settings.tsx ("transacitonal" → "transactional").

Reviewed changes

Copilot reviewed 10 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
includes/class-wizards.php Moves Emails_Section registration from Settings to Audience wizard.
includes/wizards/audience/class-audience-wizard.php Accepts $args in constructor; localizes emails data on window.newspackAudience.
includes/wizards/newspack/class-emails-section.php Switches wizard_slug to newspack-audience; introduces REST_BASE constant to preserve API path.
includes/wizards/newspack/class-newspack-settings.php Removes Emails tab data; adds inline JS redirect for old bookmarks.
src/wizards/audience/views/setup/index.js Adds Emails tab and route to Audience setup.
src/wizards/audience/views/setup/emails/index.tsx Reads new window.newspackAudience.emails shape; wraps screen with withWizardScreen.
src/wizards/audience/views/setup/emails/emails.tsx Reads emails config from window.newspackAudience instead of window.newspackSettings.
src/wizards/audience/views/setup/emails/settings.tsx Header doc update; fixes "transacitonal" typo.
src/wizards/audience/views/setup/emails/emails.test.js Updates mock to new window.newspackAudience.emails shape.
src/wizards/audience/views/setup/emails/email-preview.tsx / .scss / .test.js New EmailPreview component, styles, and tests (preview path uses stable newspack-settings/emails REST base).
src/wizards/audience/views/setup/emails/emails.scss Emails tab layout, chips, and trigger description styles.
src/wizards/newspack/views/settings/sections.tsx Removes Emails import and section component mapping.
src/wizards/newspack/types/index.d.ts Drops Emails entry from window.newspackSettings types.
src/wizards/types/window.d.ts Adds emails entry to window.newspackAudience types.

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

Comment thread includes/wizards/newspack/class-newspack-settings.php Outdated
@kmwilkerson kmwilkerson force-pushed the nppd-1537-sync-site-styles-into-wc-email-options branch from 3410271 to 643cb6d Compare May 26, 2026 23:21
@kmwilkerson kmwilkerson force-pushed the nppd-1538-move-emails-to-audience-configuration branch from bfb86d3 to a420a31 Compare May 26, 2026 23:23
kmwilkerson and others added 2 commits May 26, 2026 18:38
…NPPD-1538)

Move the Emails management UI from Newspack > Settings > Emails to
Audience > Configuration > Emails as the last tab. REST API paths
remain stable at /wizard/newspack-settings/emails via a hardcoded
REST_BASE constant for backward compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kmwilkerson kmwilkerson force-pushed the nppd-1538-move-emails-to-audience-configuration branch from a420a31 to 8b01984 Compare May 26, 2026 23:39
@kmwilkerson kmwilkerson force-pushed the nppd-1537-sync-site-styles-into-wc-email-options branch from 643cb6d to 43a03aa Compare May 26, 2026 23:39
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