Commit 26108675af3 for woocommerce
commit 26108675af374c28e3b3523507489b75efca75cf
Author: Pavel Dohnal <pavel.dohnal@automattic.com>
Date: Thu Nov 26 08:07:41 2026 +0100
Hide site Styles, Preferences and template creation in the WordPress 7.2 email editor (#71438)
* Hide core's site Styles, Preferences and Template UI on WP 7.2
WordPress 7.2 rebuilt the Options menu with the @wordpress/ui Menu, so
the rules that hid the site's Styles item and the Preferences item no
longer matched. It also always renders core's "Template: ..." panel in
the sidebar. From the email editor, the Styles item rewrote the site's
Global Styles, and the Template panel's "Create new" added a site
template, while its "Edit" skipped the shared-template warning.
Core has no option to remove any of these, so they stay hidden with
CSS. The Styles rule now matches by aria-controls on any element, which
covers 7.1 and 7.2. The 7.1 rules stay until 7.2 is the minimum.
* Check the email editor hides core UI that edits the site
Covers the site Styles item, Preferences and core's Template panel, so
the next change in core's markup shows up as a failing test instead of
a merchant changing their storefront from an email.
* Keep core's Template panel and hide only its actions
The previous rule hid the last document panel without a class of its
own, which was meant to be core's Template panel on WordPress 7.2. On
7.1 that panel doesn't exist, so the rule hid whatever plugin panel
came last instead, such as MailPoet's Tracking panel, and on 7.2 a
later core panel could take the Template panel's place.
Match core's own action class instead. The panel stays as a preview
of the email template, while "Create new" and "Edit" are hidden.
Editing the template is still available from the email's Template
menu in the Settings panel, which warns first.
* Check the Template panel actions only where core renders them
Split the check in two. The Options menu check runs on every version.
The Template panel check runs from WordPress 7.2, opens the panel and
sees its preview before checking that "Create new" and "Edit" are
hidden, so it can't pass on a panel that never rendered.
* Use the shared WordPress version helper in the Template panel check
The e2e utils already read the installed version through wp-env, as the
command palette test does. Reuse it instead of parsing the admin body
class, and skip before opening the editor.
* Keep Edit in core's Template panel and word its notice for emails
The Edit button next to the template preview helps people find where
to change the email template, in WooCommerce, MailPoet and other uses
of the editor. Only "Create new" stays hidden, because it adds a site
template rather than an email template.
Core's Edit opens the template directly, like the email editor's own
canvas button, and shows a notice with a Back action. That notice said
the changes affect "all posts and pages", so it now says they affect
all emails that use the template.
* Check Edit stays in the Template panel and its notice names emails
* Fit the Create new selector on one line for stylelint
Prettier wrapped the sibling selector so the + combinator started a line,
which stylelint's combinator spacing rule rejects. :not(:first-child)
hides the same button and keeps both tools happy.
* Add a dev changelog entry for the email editor e2e checks
The Validate changelog job needs a change file for every project the PR
touches, and the new e2e checks live in plugins/woocommerce.
* Read the WordPress version from the site under test
getInstalledWordPressVersion() asks the local wp-env container, so the
Template panel test failed instead of skipping when the suite ran
against a remote site such as Pressable or WordPress.com. Read the
version from the admin body class of the page under test instead.
* Read WordPress 7.0's branch-7 body class in the version check
WordPress builds the admin branch class from the float version, so 7.0.x
is branch-7 with no minor part. The check required one and failed on the
WP L-1 e2e job instead of skipping the Template panel test.
diff --git a/packages/js/email-editor/changelog/wooplug-8324-email-editor-wp72-core-ui b/packages/js/email-editor/changelog/wooplug-8324-email-editor-wp72-core-ui
new file mode 100644
index 00000000000..5b5b12ecca1
--- /dev/null
+++ b/packages/js/email-editor/changelog/wooplug-8324-email-editor-wp72-core-ui
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+In the email editor on WordPress 7.2, hide the site’s Styles panel, the Preferences item and the template panel’s Create new button.
diff --git a/packages/js/email-editor/src/components/header/style.scss b/packages/js/email-editor/src/components/header/style.scss
index cb7fe717011..32aebd85d8b 100644
--- a/packages/js/email-editor/src/components/header/style.scss
+++ b/packages/js/email-editor/src/components/header/style.scss
@@ -11,6 +11,14 @@
}
}
+// From WordPress 7.2 "Preferences" is the last item of the Options menu, after a separator.
+.editor-more-menu__popup > * {
+ > [role="menuitem"]:last-child,
+ > [role="separator"]:has(+ [role="menuitem"]:last-child) {
+ display: none;
+ }
+}
+
.woocommerce-email-editor__view-mode-toggle {
view-transition-name: toggle;
top: 0;
@@ -87,7 +95,8 @@
}
}
-// Hide core's Styles sidebar controls
-.components-button[aria-controls="edit-site:global-styles"] {
+// Hide core's Styles sidebar controls. They edit the site's Global Styles, not the email.
+// Not tied to an element, because WordPress 7.2 renders the menu item as a div.
+[aria-controls="edit-site:global-styles"] {
display: none !important;
}
diff --git a/packages/js/email-editor/src/components/sidebar/style.scss b/packages/js/email-editor/src/components/sidebar/style.scss
index 79293c57eb8..825a8740bc1 100644
--- a/packages/js/email-editor/src/components/sidebar/style.scss
+++ b/packages/js/email-editor/src/components/sidebar/style.scss
@@ -26,3 +26,9 @@
display: none;
}
}
+
+// From WordPress 7.2 core renders its "Template: ..." panel with "Edit" and "Create new".
+// Hide "Create new", which adds a site template instead of an email template.
+.editor-template-actions-panel__action:not(:first-child) {
+ display: none;
+}
diff --git a/packages/js/email-editor/src/text-hooks.ts b/packages/js/email-editor/src/text-hooks.ts
index bab053f43ba..5730f2cf19e 100644
--- a/packages/js/email-editor/src/text-hooks.ts
+++ b/packages/js/email-editor/src/text-hooks.ts
@@ -22,6 +22,15 @@ export const initTextHooks = (): void => {
__i18n_text_domain__
),
},
+ // Shown by "Edit" in core's Template panel from WordPress 7.2.
+ 'Editing template. Changes made here affect all posts and pages that use the template.':
+ {
+ domain: 'default',
+ replacementText: __(
+ 'Editing template. Changes made here affect all emails that use the template.',
+ __i18n_text_domain__
+ ),
+ },
};
addFilterForEmail(
diff --git a/plugins/woocommerce/changelog/wooplug-8324-email-editor-wp72-core-ui-e2e b/plugins/woocommerce/changelog/wooplug-8324-email-editor-wp72-core-ui-e2e
new file mode 100644
index 00000000000..1acfa2007d2
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-8324-email-editor-wp72-core-ui-e2e
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Add email editor e2e checks for hidden core UI on WordPress 7.2; no production change.
+
diff --git a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-loads.spec.ts b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-loads.spec.ts
index 4ed02a3ad1f..524446838af 100644
--- a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-loads.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-loads.spec.ts
@@ -19,6 +19,26 @@ import { setOption } from '../../utils/options';
// WP 7.2 renamed "Preview in new tab" to "Preview" with an "(opens in a new tab)" icon label.
const PREVIEW_IN_NEW_TAB = /^Preview (in new tab|\(opens in a new tab\))$/;
+// Reads the version from the admin body class of the site under test, for example
+// `branch-7-2`, or `branch-7` for 7.0. `getInstalledWordPressVersion()` asks the
+// local wp-env container, which doesn't exist when the suite runs against a remote site.
+const isWordPressAtLeast = async (
+ page: Page,
+ major: number,
+ minor: number
+) => {
+ const branch = await page.evaluate( () =>
+ document.body.className
+ .match( /\bbranch-(\d+)(?:-(\d+))?\b/ )
+ ?.slice( 1 )
+ );
+ expect( branch ).toBeDefined();
+ const [ siteMajor, siteMinor ] = ( branch ?? [] ).map( ( part ) =>
+ Number( part ?? 0 )
+ );
+ return siteMajor > major || ( siteMajor === major && siteMinor >= minor );
+};
+
test.describe(
'WooCommerce Email Editor Core',
{ lock: locks.EMAIL_FEATURE_FLAGS },
@@ -116,6 +136,78 @@ test.describe(
).toContainText( `New order: #[woocommerce/order-number]` );
} );
+ test( 'Hides core menu items that change the site', async ( {
+ page,
+ } ) => {
+ await accessAndTrackEmailPost( page );
+
+ // Each hidden item is checked after a visible item of the same menu, so a
+ // menu that failed to open can't pass as hidden.
+ await page.getByRole( 'button', { name: 'Options' } ).click();
+ await expect(
+ page.getByRole( 'menuitem', { name: 'Keyboard shortcuts' } )
+ ).toBeVisible();
+ await expect(
+ page.getByRole( 'menuitem', { name: 'Preferences' } )
+ ).toBeHidden();
+
+ // WP 7.2 moved the panels into a "Panels" submenu that opens on hover.
+ // Before 7.2 "Panels" is the label of a group in the menu itself.
+ await page
+ .getByRole( 'menuitem', { name: 'Panels' } )
+ .or( page.getByText( 'Panels', { exact: true } ) )
+ .first()
+ .hover();
+ await expect(
+ page.getByRole( 'menuitemcheckbox', { name: 'Email styles' } )
+ ).toBeVisible();
+ // The site's Global Styles, which would change the storefront. Core only
+ // adds the item for block themes.
+ await expect(
+ page.getByRole( 'menuitemcheckbox', {
+ name: 'Styles',
+ exact: true,
+ } )
+ ).toBeHidden();
+ } );
+
+ test( 'Core Template panel edits the email template only', async ( {
+ page,
+ } ) => {
+ await accessAndTrackEmailPost( page );
+ test.skip(
+ ! ( await isWordPressAtLeast( page, 7, 2 ) ),
+ 'Core renders the Template panel from WordPress 7.2.'
+ );
+
+ const templatePanelToggle = page.getByRole( 'button', {
+ name: /^Template:/,
+ } );
+ await templatePanelToggle.click();
+ const templatePanel = page
+ .locator( '.components-panel__body' )
+ .filter( { has: templatePanelToggle } );
+ const editButton = templatePanel.getByRole( 'button', {
+ name: 'Edit',
+ exact: true,
+ } );
+ await expect( editButton ).toBeVisible();
+ // "Create new" would add a site template, not an email template.
+ await expect(
+ templatePanel.getByRole( 'button', { name: 'Create new' } )
+ ).toBeHidden();
+
+ // Core's notice talks about posts and pages; the email editor rewords it.
+ await editButton.click();
+ await expect(
+ page
+ .locator( '.components-snackbar' )
+ .filter( { hasText: 'Editing template.' } )
+ ).toContainText(
+ 'Changes made here affect all emails that use the template.'
+ );
+ } );
+
test( 'Can preview in new tab', async ( { page } ) => {
await accessAndTrackEmailPost( page );
await page