Commit 105f33a86e9 for woocommerce
commit 105f33a86e9ddc4a986eeb993c0dee9ec7ee50d6
Author: Rostislav Wolný <1082140+costasovo@users.noreply.github.com>
Date: Tue Dec 1 12:53:40 2026 +0100
Make Site Title and Site Logo read-only in the email editor (#71323)
* Make Site Title and Site Logo read-only in the email editor
The core Site Title and Site Logo blocks edit the site's title, logo and icon, and the email editor saves those edits together with the email, so editing one of these blocks in an email changed site-wide settings. The new opt-in readOnlySiteIdentityBlocks editor setting renders read-only versions of both blocks and adds Heading and Image transforms for using a different title or image in one email. WooCommerce turns the setting on; other integrations keep core's behaviour until they opt in.
diff --git a/packages/js/email-editor/README.md b/packages/js/email-editor/README.md
index e4fc5770832..541661aa0ba 100644
--- a/packages/js/email-editor/README.md
+++ b/packages/js/email-editor/README.md
@@ -50,11 +50,12 @@ Make sure to set up the required data on `window.WooCommerceEmailEditor` before
The `editor_settings` object (or `config.editorSettings` when using `ExperimentalEmailEditor`) accepts all standard WordPress block editor settings plus the following email-editor-specific options:
-| Setting | Type | Default | Description |
-| ------------------------ | --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `isFullScreenForced` | `boolean` | `false` | When `true`, the editor is always rendered in fullscreen mode and the user cannot toggle it off. The "More menu" is hidden and a back button is shown in the header. |
-| `displaySendEmailButton` | `boolean` | `false` | When `true`, a "Send" button is displayed in the editor header, allowing users to publish/send the email directly from the editor. |
-| `disableSnackbarNotices` | `boolean` | `false` | When `true`, the editor does not render its own snackbar notices. Pinned and validation notices are unaffected. |
+| Setting | Type | Default | Description |
+| ---------------------------- | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `isFullScreenForced` | `boolean` | `false` | When `true`, the editor is always rendered in fullscreen mode and the user cannot toggle it off. The "More menu" is hidden and a back button is shown in the header. |
+| `displaySendEmailButton` | `boolean` | `false` | When `true`, a "Send" button is displayed in the editor header, allowing users to publish/send the email directly from the editor. |
+| `disableSnackbarNotices` | `boolean` | `false` | When `true`, the editor does not render its own snackbar notices. Pinned and validation notices are unaffected. |
+| `readOnlySiteIdentityBlocks` | `boolean` | `false` | When `true`, the Site Title and Site Logo blocks show the site's title and logo but can't change them, so saving an email never changes site settings. Users can transform them into a Heading or Image block to use a different title or image in the email. |
## Exports
diff --git a/packages/js/email-editor/changelog/wooplug-7933-email-editor-site-logo-and-site-title-blocks b/packages/js/email-editor/changelog/wooplug-7933-email-editor-site-logo-and-site-title-blocks
new file mode 100644
index 00000000000..76c8b603251
--- /dev/null
+++ b/packages/js/email-editor/changelog/wooplug-7933-email-editor-site-logo-and-site-title-blocks
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add the `readOnlySiteIdentityBlocks` editor setting, which stops Site Title and Site Logo blocks from changing site settings.
diff --git a/packages/js/email-editor/src/blocks/core/site-logo.ts b/packages/js/email-editor/src/blocks/core/site-logo.ts
deleted file mode 100644
index 44bfbd357e0..00000000000
--- a/packages/js/email-editor/src/blocks/core/site-logo.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Internal dependencies
- */
-import { registerBlockVariationForEmail } from '../../config-tools';
-
-/**
- * Register a custom variation for the site logo block
- * This variation is used to display the site logo in the email editor by automatically adding some preset options.
- */
-function registerCustomSiteLogoBlockVariation() {
- registerBlockVariationForEmail( 'core/site-logo', {
- name: 'site-logo-default',
- title: 'Site Logo',
- attributes: {
- align: 'center',
- width: 120, // set a default width for the site logo
- },
- isDefault: true, // set this as the default variation
- } );
-}
-
-/**
- * Enhance the Site Logo block.
- */
-function enhanceSiteLogoBlock() {
- registerCustomSiteLogoBlockVariation();
-}
-
-export { enhanceSiteLogoBlock };
diff --git a/packages/js/email-editor/src/blocks/core/site-logo.tsx b/packages/js/email-editor/src/blocks/core/site-logo.tsx
new file mode 100644
index 00000000000..b4eadae57fe
--- /dev/null
+++ b/packages/js/email-editor/src/blocks/core/site-logo.tsx
@@ -0,0 +1,328 @@
+/**
+ * External dependencies
+ */
+import clsx from 'clsx';
+import {
+ InspectorControls,
+ store as blockEditorStore,
+ useBlockProps,
+} from '@wordpress/block-editor';
+import { createBlock, getBlockType } from '@wordpress/blocks';
+import type { BlockConfiguration, BlockEditProps } from '@wordpress/blocks';
+import {
+ PanelBody,
+ Placeholder,
+ RangeControl,
+ Spinner,
+ ToggleControl,
+ __experimentalToolsPanel as ToolsPanel,
+ __experimentalToolsPanelItem as ToolsPanelItem,
+} from '@wordpress/components';
+import { store as coreStore } from '@wordpress/core-data';
+import { select, useSelect } from '@wordpress/data';
+import { decodeEntities } from '@wordpress/html-entities';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import { registerBlockVariationForEmail } from '../../config-tools';
+import { updateBlockSettings } from '../../config-tools/block-config';
+import { storeName } from '../../store';
+
+// Core renders a site logo without a width at 120px.
+const DEFAULT_WIDTH = 120;
+const MIN_WIDTH = 20;
+
+type SiteLogoAttributes = {
+ width?: number;
+ isLink: boolean;
+ linkTarget: string;
+ shouldSyncIcon?: boolean;
+};
+
+type SiteLogoEditProps = BlockEditProps< SiteLogoAttributes >;
+
+type SelectFunction = typeof select;
+
+type SiteLogo = {
+ id?: number;
+ url?: string;
+ alt?: string;
+ homeUrl?: string;
+ siteTitle?: string;
+ isLoading: boolean;
+};
+
+function getSiteLogo( selectFn: SelectFunction ): SiteLogo {
+ const { getEntityRecord, hasFinishedResolution } = selectFn( coreStore );
+ const site = getEntityRecord( 'root', '__unstableBase' ) as
+ { name?: string; home?: string; site_logo?: number } | undefined;
+ const id = site?.site_logo || undefined;
+ const mediaQuery = [ 'postType', 'attachment', id, { context: 'view' } ];
+ const media = id
+ ? ( getEntityRecord( 'postType', 'attachment', id, {
+ context: 'view',
+ } ) as { source_url?: string; alt_text?: string } | undefined )
+ : undefined;
+ return {
+ id,
+ url: media?.source_url,
+ alt: media?.alt_text,
+ homeUrl: site?.home,
+ siteTitle: decodeEntities( site?.name ?? '' ),
+ isLoading:
+ ! site ||
+ ( !! id &&
+ ! hasFinishedResolution( 'getEntityRecord', mediaQuery ) ),
+ };
+}
+
+function isReadOnly( selectFn: SelectFunction ): boolean {
+ return !! selectFn( storeName ).getInitialEditorSettings()
+ ?.readOnlySiteIdentityBlocks;
+}
+
+function ReadOnlySiteLogoEdit( {
+ attributes,
+ setAttributes,
+}: SiteLogoEditProps ) {
+ const { width, isLink, linkTarget } = attributes;
+ const logo = useSelect( getSiteLogo, [] );
+ const maxWidth = useSelect(
+ ( selectFn ) =>
+ (
+ selectFn( blockEditorStore ).getSettings() as {
+ maxWidth: number;
+ }
+ ).maxWidth,
+ []
+ );
+ const blockProps = useBlockProps( {
+ className: clsx( { 'is-default-size': ! width } ),
+ } );
+
+ let image = (
+ <img
+ className="custom-logo"
+ src={ logo.url }
+ alt={ logo.alt }
+ width={ width }
+ />
+ );
+ if ( isLink ) {
+ image = (
+ <a
+ href={ logo.homeUrl }
+ className="custom-logo-link"
+ rel="home"
+ title={ logo.siteTitle }
+ onClick={ ( event ) => event.preventDefault() }
+ >
+ { image }
+ </a>
+ );
+ }
+
+ return (
+ <div { ...blockProps }>
+ <InspectorControls>
+ <PanelBody>
+ <p>
+ { __(
+ 'This shows your site logo. To change it for the whole site, go to Appearance > Editor, or Appearance > Customize > Site Identity in classic themes. To use a different image in this email only, transform this block into an Image block.',
+ __i18n_text_domain__
+ ) }
+ </p>
+ </PanelBody>
+ <ToolsPanel
+ label={ __( 'Settings', __i18n_text_domain__ ) }
+ resetAll={ () =>
+ setAttributes( {
+ width: undefined,
+ isLink: true,
+ linkTarget: '_self',
+ } )
+ }
+ >
+ <ToolsPanelItem
+ hasValue={ () => !! width }
+ label={ __( 'Image width', __i18n_text_domain__ ) }
+ onDeselect={ () =>
+ setAttributes( { width: undefined } )
+ }
+ isShownByDefault
+ >
+ <RangeControl
+ __nextHasNoMarginBottom
+ __next40pxDefaultSize
+ label={ __( 'Image width', __i18n_text_domain__ ) }
+ onChange={ ( newWidth ) =>
+ setAttributes( { width: newWidth } )
+ }
+ min={ MIN_WIDTH }
+ max={ maxWidth * 2.5 }
+ initialPosition={ DEFAULT_WIDTH }
+ value={ width }
+ />
+ </ToolsPanelItem>
+ <ToolsPanelItem
+ hasValue={ () => ! isLink }
+ label={ __(
+ 'Link image to home',
+ __i18n_text_domain__
+ ) }
+ onDeselect={ () => setAttributes( { isLink: true } ) }
+ isShownByDefault
+ >
+ <ToggleControl
+ __nextHasNoMarginBottom
+ label={ __(
+ 'Link image to home',
+ __i18n_text_domain__
+ ) }
+ onChange={ () =>
+ setAttributes( { isLink: ! isLink } )
+ }
+ checked={ isLink }
+ />
+ </ToolsPanelItem>
+ { isLink && (
+ <ToolsPanelItem
+ hasValue={ () => linkTarget === '_blank' }
+ label={ __(
+ 'Open in new tab',
+ __i18n_text_domain__
+ ) }
+ onDeselect={ () =>
+ setAttributes( { linkTarget: '_self' } )
+ }
+ isShownByDefault
+ >
+ <ToggleControl
+ __nextHasNoMarginBottom
+ label={ __(
+ 'Open in new tab',
+ __i18n_text_domain__
+ ) }
+ onChange={ ( value ) =>
+ setAttributes( {
+ linkTarget: value ? '_blank' : '_self',
+ } )
+ }
+ checked={ linkTarget === '_blank' }
+ />
+ </ToolsPanelItem>
+ ) }
+ </ToolsPanel>
+ </InspectorControls>
+ { logo.url ? (
+ <div style={ { width } }>{ image }</div>
+ ) : (
+ <Placeholder className="site-logo_placeholder" withIllustration>
+ { logo.isLoading && (
+ <span className="components-placeholder__preview">
+ <Spinner />
+ </span>
+ ) }
+ </Placeholder>
+ ) }
+ </div>
+ );
+}
+
+// Core's site logo edit writes the site-wide logo and icon, which the email editor saves together with the email.
+function SiteLogoEdit(
+ OriginalEditComponent: React.ComponentType< SiteLogoEditProps >
+) {
+ return function Edit( props: SiteLogoEditProps ) {
+ const readOnly = useSelect( isReadOnly, [] );
+ if ( readOnly ) {
+ return <ReadOnlySiteLogoEdit { ...props } />;
+ }
+ return <OriginalEditComponent { ...props } />;
+ };
+}
+
+const imageTransform = {
+ type: 'block' as const,
+ blocks: [ 'core/image' ],
+ isMatch: () => isReadOnly( select ),
+ transform: ( {
+ width,
+ isLink,
+ linkTarget,
+ shouldSyncIcon,
+ ...rest
+ }: SiteLogoAttributes & Record< string, unknown > ) => {
+ const logo = getSiteLogo( select );
+ return createBlock( 'core/image', {
+ ...rest,
+ url: logo.url,
+ alt: logo.alt,
+ id: logo.id,
+ width: `${ width || DEFAULT_WIDTH }px`,
+ ...( isLink && {
+ href: logo.homeUrl,
+ linkTarget: linkTarget === '_blank' ? '_blank' : undefined,
+ linkDestination: 'custom',
+ } ),
+ } );
+ },
+};
+
+/**
+ * Register a custom variation for the site logo block
+ * This variation is used to display the site logo in the email editor by automatically adding some preset options.
+ */
+function registerCustomSiteLogoBlockVariation() {
+ registerBlockVariationForEmail( 'core/site-logo', {
+ name: 'site-logo-default',
+ title: 'Site Logo',
+ attributes: {
+ align: 'center',
+ width: 120, // set a default width for the site logo
+ },
+ isDefault: true, // set this as the default variation
+ } );
+}
+
+function addReadOnlyMode() {
+ updateBlockSettings( 'core/site-logo', ( current ) => {
+ const settings = current as BlockConfiguration & {
+ transforms?: { to?: unknown[] };
+ };
+ return {
+ ...current,
+ edit: SiteLogoEdit(
+ current.edit as React.ComponentType< SiteLogoEditProps >
+ ),
+ transforms: {
+ ...settings.transforms,
+ to: [ ...( settings.transforms?.to ?? [] ), imageTransform ],
+ },
+ } as typeof current;
+ } );
+ // The inspector shows the description of the active variation instead of core's, which says that edits apply everywhere.
+ registerBlockVariationForEmail( 'core/site-logo', {
+ name: 'read-only-site-logo',
+ title: getBlockType( 'core/site-logo' )?.title ?? '',
+ description: __(
+ 'Display an image to represent this site.',
+ __i18n_text_domain__
+ ),
+ isActive: () => isReadOnly( select ),
+ // An empty scope keeps the variation out of the inserter and the block switcher.
+ scope: [],
+ } );
+}
+
+/**
+ * Enhance the Site Logo block.
+ */
+function enhanceSiteLogoBlock() {
+ registerCustomSiteLogoBlockVariation();
+ addReadOnlyMode();
+}
+
+export { enhanceSiteLogoBlock };
diff --git a/packages/js/email-editor/src/blocks/core/site-title.tsx b/packages/js/email-editor/src/blocks/core/site-title.tsx
new file mode 100644
index 00000000000..7fcbb952450
--- /dev/null
+++ b/packages/js/email-editor/src/blocks/core/site-title.tsx
@@ -0,0 +1,265 @@
+/**
+ * External dependencies
+ */
+import clsx from 'clsx';
+import {
+ AlignmentControl,
+ BlockControls,
+ HeadingLevelDropdown,
+ InspectorControls,
+ useBlockEditingMode,
+ useBlockProps,
+} from '@wordpress/block-editor';
+import { createBlock, getBlockType } from '@wordpress/blocks';
+import type { BlockConfiguration, BlockEditProps } from '@wordpress/blocks';
+import {
+ PanelBody,
+ ToggleControl,
+ __experimentalToolsPanel as ToolsPanel,
+ __experimentalToolsPanelItem as ToolsPanelItem,
+} from '@wordpress/components';
+import { store as coreStore } from '@wordpress/core-data';
+import { select, useSelect } from '@wordpress/data';
+import { renderToString } from '@wordpress/element';
+import { decodeEntities } from '@wordpress/html-entities';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import { registerBlockVariationForEmail } from '../../config-tools';
+import { updateBlockSettings } from '../../config-tools/block-config';
+import { storeName } from '../../store';
+
+type HeadingLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6;
+
+type SiteTitleAttributes = {
+ level: HeadingLevel;
+ levelOptions?: HeadingLevel[];
+ textAlign?: string;
+ isLink: boolean;
+ linkTarget: string;
+};
+
+type SiteTitleEditProps = BlockEditProps< SiteTitleAttributes >;
+
+type SelectFunction = typeof select;
+
+function getSite( selectFn: SelectFunction ) {
+ return selectFn( coreStore ).getEntityRecord( 'root', '__unstableBase' ) as
+ { name?: string; home?: string } | undefined;
+}
+
+function getSiteTitle( selectFn: SelectFunction ): string {
+ return decodeEntities( getSite( selectFn )?.name ?? '' );
+}
+
+function isReadOnly( selectFn: SelectFunction ): boolean {
+ return !! selectFn( storeName ).getInitialEditorSettings()
+ ?.readOnlySiteIdentityBlocks;
+}
+
+function ReadOnlySiteTitleEdit( {
+ attributes,
+ setAttributes,
+}: SiteTitleEditProps ) {
+ const { level, levelOptions, textAlign, isLink, linkTarget } = attributes;
+ const title = useSelect( getSiteTitle, [] );
+ const blockEditingMode = useBlockEditingMode();
+ // From WordPress 7.1 the block has no textAlign attribute; the typography block support adds its own control.
+ const hasTextAlignAttribute =
+ !! getBlockType( 'core/site-title' )?.attributes?.textAlign;
+ const TagName = ( level === 0 ? 'p' : `h${ level }` ) as
+ 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
+ const blockProps = useBlockProps( {
+ className: clsx( {
+ [ `has-text-align-${ textAlign }` ]: textAlign,
+ } ),
+ } );
+ const text = title || __( 'Site Title placeholder', __i18n_text_domain__ );
+
+ return (
+ <>
+ { blockEditingMode === 'default' && (
+ <BlockControls group="block">
+ <HeadingLevelDropdown
+ value={ level }
+ options={ levelOptions }
+ onChange={ ( newLevel ) =>
+ setAttributes( { level: newLevel } )
+ }
+ />
+ { hasTextAlignAttribute && (
+ <AlignmentControl
+ value={ textAlign }
+ onChange={ ( nextAlign?: string ) =>
+ setAttributes( { textAlign: nextAlign } )
+ }
+ />
+ ) }
+ </BlockControls>
+ ) }
+ <InspectorControls>
+ <PanelBody>
+ <p>
+ { __(
+ 'This shows your site title. To change it for the whole site, go to Settings > General. To use a different title in this email only, transform this block into a Heading block.',
+ __i18n_text_domain__
+ ) }
+ </p>
+ </PanelBody>
+ <ToolsPanel
+ label={ __( 'Settings', __i18n_text_domain__ ) }
+ resetAll={ () =>
+ setAttributes( { isLink: true, linkTarget: '_self' } )
+ }
+ >
+ <ToolsPanelItem
+ hasValue={ () => ! isLink }
+ label={ __(
+ 'Make title link to home',
+ __i18n_text_domain__
+ ) }
+ onDeselect={ () => setAttributes( { isLink: true } ) }
+ isShownByDefault
+ >
+ <ToggleControl
+ __nextHasNoMarginBottom
+ label={ __(
+ 'Make title link to home',
+ __i18n_text_domain__
+ ) }
+ onChange={ () =>
+ setAttributes( { isLink: ! isLink } )
+ }
+ checked={ isLink }
+ />
+ </ToolsPanelItem>
+ { isLink && (
+ <ToolsPanelItem
+ hasValue={ () => linkTarget !== '_self' }
+ label={ __(
+ 'Open in new tab',
+ __i18n_text_domain__
+ ) }
+ onDeselect={ () =>
+ setAttributes( { linkTarget: '_self' } )
+ }
+ isShownByDefault
+ >
+ <ToggleControl
+ __nextHasNoMarginBottom
+ label={ __(
+ 'Open in new tab',
+ __i18n_text_domain__
+ ) }
+ onChange={ ( value ) =>
+ setAttributes( {
+ linkTarget: value ? '_blank' : '_self',
+ } )
+ }
+ checked={ linkTarget === '_blank' }
+ />
+ </ToolsPanelItem>
+ ) }
+ </ToolsPanel>
+ </InspectorControls>
+ <TagName { ...blockProps }>
+ { isLink ? (
+ <a
+ href="#site-title-pseudo-link"
+ onClick={ ( event ) => event.preventDefault() }
+ >
+ { text }
+ </a>
+ ) : (
+ <span>{ text }</span>
+ ) }
+ </TagName>
+ </>
+ );
+}
+
+// Core's site title edit writes the site-wide title, which the email editor saves together with the email.
+function SiteTitleEdit(
+ OriginalEditComponent: React.ComponentType< SiteTitleEditProps >
+) {
+ return function Edit( props: SiteTitleEditProps ) {
+ const readOnly = useSelect( isReadOnly, [] );
+ if ( readOnly ) {
+ return <ReadOnlySiteTitleEdit { ...props } />;
+ }
+ return <OriginalEditComponent { ...props } />;
+ };
+}
+
+const headingTransform = {
+ type: 'block' as const,
+ blocks: [ 'core/heading' ],
+ isMatch: () => isReadOnly( select ),
+ transform: ( {
+ level,
+ levelOptions,
+ textAlign,
+ isLink,
+ linkTarget,
+ ...rest
+ }: SiteTitleAttributes & Record< string, unknown > ) => {
+ const title = getSiteTitle( select );
+ const homeUrl = getSite( select )?.home;
+ const opensInNewTab = linkTarget === '_blank';
+ return createBlock( 'core/heading', {
+ ...rest,
+ content: renderToString(
+ isLink && homeUrl ? (
+ <a
+ href={ homeUrl }
+ target={ opensInNewTab ? '_blank' : undefined }
+ rel={
+ opensInNewTab ? 'noreferrer noopener' : undefined
+ }
+ >
+ { title }
+ </a>
+ ) : (
+ title
+ )
+ ),
+ // Level 0 renders the site title as a paragraph; the heading falls back to its default level.
+ ...( level ? { level } : {} ),
+ textAlign,
+ } );
+ },
+};
+
+function enhanceSiteTitleBlock() {
+ updateBlockSettings( 'core/site-title', ( current ) => {
+ const settings = current as BlockConfiguration & {
+ transforms?: { to?: unknown[] };
+ };
+ return {
+ ...current,
+ edit: SiteTitleEdit(
+ current.edit as React.ComponentType< SiteTitleEditProps >
+ ),
+ transforms: {
+ ...settings.transforms,
+ to: [ ...( settings.transforms?.to ?? [] ), headingTransform ],
+ },
+ } as typeof current;
+ } );
+ // The inspector shows the description of the active variation instead of core's, which says that edits apply everywhere.
+ registerBlockVariationForEmail( 'core/site-title', {
+ name: 'read-only-site-title',
+ title: getBlockType( 'core/site-title' )?.title ?? '',
+ description: __(
+ 'Displays the name of this site.',
+ __i18n_text_domain__
+ ),
+ isActive: () => isReadOnly( select ),
+ // An empty scope keeps the variation out of the inserter and the block switcher.
+ scope: [],
+ } );
+}
+
+export { enhanceSiteTitleBlock };
diff --git a/packages/js/email-editor/src/blocks/core/test/site-identity.spec.tsx b/packages/js/email-editor/src/blocks/core/test/site-identity.spec.tsx
new file mode 100644
index 00000000000..9fc8e79d0a8
--- /dev/null
+++ b/packages/js/email-editor/src/blocks/core/test/site-identity.spec.tsx
@@ -0,0 +1,497 @@
+/**
+ * External dependencies
+ */
+import { render, screen, fireEvent } from '@testing-library/react';
+import {
+ registerBlockType,
+ unregisterBlockType,
+ getBlockType,
+ createBlock,
+ switchToBlockType,
+ getPossibleBlockTransformations,
+ store as blocksStore,
+} from '@wordpress/blocks';
+import type { BlockInstance } from '@wordpress/blocks';
+import { select } from '@wordpress/data';
+/**
+ * Internal dependencies
+ */
+import { enhanceSiteLogoBlock } from '../site-logo';
+import { enhanceSiteTitleBlock } from '../site-title';
+import { restoreAllModifiedBlockSettings } from '../../../config-tools/block-config';
+import { resetBlockVariations } from '../../../config-tools/block-variations';
+
+const mockState: {
+ editorSettings: { readOnlySiteIdentityBlocks?: boolean };
+ site: { name: string; home: string; site_logo?: number };
+} = {
+ editorSettings: {},
+ site: { name: '', home: '' },
+};
+
+const mockMedia = {
+ id: 42,
+ source_url: 'http://example.com/logo.png',
+ alt_text: 'Store logo',
+};
+
+jest.mock( '../../../store', () => ( {
+ storeName: 'email-editor/editor',
+} ) );
+
+jest.mock( '@wordpress/core-data', () => ( {
+ store: { name: 'core' },
+} ) );
+
+jest.mock( '@wordpress/block-editor', () => ( {
+ store: { name: 'core/block-editor' },
+ useBlockProps: ( props = {} ) => props,
+ useBlockEditingMode: () => 'default',
+ BlockControls: ( { children }: { children: React.ReactNode } ) => (
+ <>{ children }</>
+ ),
+ InspectorControls: ( { children }: { children: React.ReactNode } ) => (
+ <>{ children }</>
+ ),
+ AlignmentControl: () => <div>alignment control</div>,
+ HeadingLevelDropdown: () => null,
+} ) );
+
+jest.mock( '@wordpress/data', () => {
+ const actual = jest.requireActual( '@wordpress/data' );
+ const fakeSelectors: Record< string, Record< string, unknown > > = {
+ 'email-editor/editor': {
+ getInitialEditorSettings: () => mockState.editorSettings,
+ },
+ core: {
+ getEntityRecord: ( kind: string, name: string, id?: number ) => {
+ if ( kind === 'root' && name === '__unstableBase' ) {
+ return mockState.site;
+ }
+ if (
+ kind === 'postType' &&
+ name === 'attachment' &&
+ id === mockMedia.id
+ ) {
+ return mockMedia;
+ }
+ return undefined;
+ },
+ hasFinishedResolution: () => true,
+ },
+ 'core/block-editor': {
+ getSettings: () => ( { maxWidth: 580 } ),
+ },
+ };
+ const fakeSelect = ( store: string | { name: string } ) => {
+ const name = typeof store === 'string' ? store : store?.name;
+ return fakeSelectors[ name ] ?? actual.select( store );
+ };
+ return {
+ ...actual,
+ select: jest.fn( fakeSelect ),
+ useSelect: jest.fn( ( callback ) => callback( fakeSelect ) ),
+ };
+} );
+
+const OriginalEdit = () => <div>core edit</div>;
+
+function renderEdit( blockName: string, attributes: object ) {
+ const setAttributes = jest.fn();
+ const Edit = getBlockType( blockName )?.edit as React.ElementType;
+ render(
+ <Edit
+ name={ blockName }
+ clientId="block-1"
+ attributes={ attributes }
+ setAttributes={ setAttributes }
+ isSelected
+ />
+ );
+ return { setAttributes };
+}
+
+function possibleTransformNames( block: BlockInstance ) {
+ return getPossibleBlockTransformations( [ block ] ).map(
+ ( blockType ) => blockType.name
+ );
+}
+
+// The inspector shows the description of the active block variation, if there is one.
+function inspectorDescription( block: BlockInstance ) {
+ return select( blocksStore ).getActiveBlockVariation(
+ block.name,
+ block.attributes
+ )?.description;
+}
+
+function variationNamesIn( blockName: string, scope: string ) {
+ return (
+ select( blocksStore ).getBlockVariations( blockName, scope ) ?? []
+ ).map( ( variation: { name: string } ) => variation.name );
+}
+
+beforeEach( () => {
+ mockState.editorSettings = { readOnlySiteIdentityBlocks: true };
+ mockState.site = {
+ name: 'Ticket & Store',
+ home: 'http://example.com',
+ site_logo: mockMedia.id,
+ };
+} );
+
+describe( 'Site Title block', () => {
+ beforeEach( () => {
+ registerBlockType( 'core/site-title', {
+ apiVersion: 3,
+ title: 'Site Title',
+ category: 'theme',
+ attributes: {
+ level: { type: 'number', default: 1 },
+ levelOptions: { type: 'array' },
+ textAlign: { type: 'string' },
+ isLink: { type: 'boolean', default: true },
+ linkTarget: { type: 'string', default: '_self' },
+ style: { type: 'object' },
+ },
+ edit: OriginalEdit,
+ save: () => null,
+ } );
+ registerBlockType( 'core/heading', {
+ apiVersion: 3,
+ title: 'Heading',
+ category: 'text',
+ attributes: {
+ content: { type: 'string' },
+ level: { type: 'number', default: 2 },
+ textAlign: { type: 'string' },
+ style: { type: 'object' },
+ },
+ edit: () => null,
+ save: () => null,
+ } );
+ enhanceSiteTitleBlock();
+ } );
+
+ afterEach( () => {
+ restoreAllModifiedBlockSettings();
+ resetBlockVariations();
+ unregisterBlockType( 'core/site-title' );
+ unregisterBlockType( 'core/heading' );
+ } );
+
+ it( 'renders the original edit component when the setting is off', () => {
+ mockState.editorSettings = {};
+ renderEdit( 'core/site-title', { level: 2, isLink: true } );
+ expect( screen.getByText( 'core edit' ) ).toBeInTheDocument();
+ } );
+
+ it( 'shows the site title without letting the user edit it', () => {
+ renderEdit( 'core/site-title', { level: 2, isLink: true } );
+
+ const heading = screen.getByRole( 'heading', {
+ level: 2,
+ name: 'Ticket & Store',
+ } );
+ expect( screen.queryByText( 'core edit' ) ).not.toBeInTheDocument();
+ expect( heading.querySelector( '[contenteditable]' ) ).toBeNull();
+ } );
+
+ it( 'describes the block without saying that edits apply everywhere', () => {
+ const block = createBlock( 'core/site-title' );
+ expect( inspectorDescription( block ) ).toBe(
+ 'Displays the name of this site.'
+ );
+
+ mockState.editorSettings = {};
+ expect( inspectorDescription( block ) ).toBeUndefined();
+ } );
+
+ it.each( [ 'inserter', 'transform' ] )(
+ 'keeps the description variation out of the %s',
+ ( scope ) => {
+ expect(
+ variationNamesIn( 'core/site-title', scope )
+ ).not.toContain( 'read-only-site-title' );
+ }
+ );
+
+ it( 'explains how to change the title in the inspector', () => {
+ renderEdit( 'core/site-title', { level: 2 } );
+ expect(
+ screen.getByText( /This shows your site title\./ )
+ ).toBeInTheDocument();
+ } );
+
+ it( 'keeps the link setting editable', () => {
+ const { setAttributes } = renderEdit( 'core/site-title', {
+ level: 2,
+ isLink: true,
+ linkTarget: '_self',
+ } );
+ fireEvent.click(
+ screen.getByRole( 'checkbox', { name: 'Make title link to home' } )
+ );
+ expect( setAttributes ).toHaveBeenCalledWith( { isLink: false } );
+ } );
+
+ it( 'shows its own alignment control only when the block has a textAlign attribute', () => {
+ renderEdit( 'core/site-title', { level: 2 } );
+ expect( screen.getByText( 'alignment control' ) ).toBeInTheDocument();
+ } );
+
+ it( 'leaves text alignment to block supports when the block has no textAlign attribute', () => {
+ // From WordPress 7.1, Site Title aligns text through the typography block support.
+ restoreAllModifiedBlockSettings();
+ unregisterBlockType( 'core/site-title' );
+ registerBlockType( 'core/site-title', {
+ apiVersion: 3,
+ title: 'Site Title',
+ category: 'theme',
+ attributes: {
+ level: { type: 'number', default: 1 },
+ isLink: { type: 'boolean', default: true },
+ linkTarget: { type: 'string', default: '_self' },
+ },
+ edit: OriginalEdit,
+ save: () => null,
+ } );
+ enhanceSiteTitleBlock();
+
+ renderEdit( 'core/site-title', { level: 2 } );
+ expect(
+ screen.getByRole( 'heading', { name: 'Ticket & Store' } )
+ ).toBeInTheDocument();
+ expect(
+ screen.queryByText( 'alignment control' )
+ ).not.toBeInTheDocument();
+ } );
+
+ it( 'transforms to a heading with the site title linked to home', () => {
+ const block = createBlock( 'core/site-title', {
+ level: 3,
+ textAlign: 'center',
+ style: { spacing: { padding: { top: '10px' } } },
+ } );
+ expect( possibleTransformNames( block ) ).toContain( 'core/heading' );
+
+ const [ heading ] = switchToBlockType( block, 'core/heading' ) ?? [];
+ expect( heading.name ).toBe( 'core/heading' );
+ expect( heading.attributes ).toEqual( {
+ content: '<a href="http://example.com">Ticket & Store</a>',
+ level: 3,
+ textAlign: 'center',
+ style: { spacing: { padding: { top: '10px' } } },
+ } );
+ } );
+
+ it( 'opens the heading link in a new tab when the site title does', () => {
+ const block = createBlock( 'core/site-title', {
+ linkTarget: '_blank',
+ } );
+ const [ heading ] = switchToBlockType( block, 'core/heading' ) ?? [];
+ expect( heading.attributes.content ).toBe(
+ '<a href="http://example.com" target="_blank" rel="noreferrer noopener">Ticket & Store</a>'
+ );
+ } );
+
+ it( 'transforms to plain text when the site title is not a link', () => {
+ const block = createBlock( 'core/site-title', { isLink: false } );
+ const [ heading ] = switchToBlockType( block, 'core/heading' ) ?? [];
+ expect( heading.attributes.content ).toBe( 'Ticket & Store' );
+ } );
+
+ it( 'transforms to plain text when the site has no home URL', () => {
+ mockState.site = { name: 'Ticket & Store', home: '' };
+ const block = createBlock( 'core/site-title' );
+ const [ heading ] = switchToBlockType( block, 'core/heading' ) ?? [];
+ expect( heading.attributes.content ).toBe( 'Ticket & Store' );
+ } );
+
+ it( 'uses the default heading level for a paragraph site title', () => {
+ const block = createBlock( 'core/site-title', { level: 0 } );
+ const [ heading ] = switchToBlockType( block, 'core/heading' ) ?? [];
+ expect( heading.attributes.level ).toBe( 2 );
+ } );
+
+ it( 'does not offer the heading transform when the setting is off', () => {
+ mockState.editorSettings = {};
+ const block = createBlock( 'core/site-title', { level: 2 } );
+ expect( possibleTransformNames( block ) ).not.toContain(
+ 'core/heading'
+ );
+ } );
+} );
+
+describe( 'Site Logo block', () => {
+ const coreTransform = {
+ type: 'block' as const,
+ blocks: [ 'core/site-title' ],
+ transform: () => createBlock( 'core/site-title' ),
+ };
+
+ beforeEach( () => {
+ registerBlockType( 'core/site-logo', {
+ apiVersion: 3,
+ title: 'Site Logo',
+ category: 'theme',
+ attributes: {
+ width: { type: 'number' },
+ isLink: { type: 'boolean', default: true },
+ linkTarget: { type: 'string', default: '_self' },
+ shouldSyncIcon: { type: 'boolean' },
+ align: { type: 'string' },
+ style: { type: 'object' },
+ },
+ transforms: { to: [ coreTransform ] },
+ edit: OriginalEdit,
+ save: () => null,
+ } );
+ registerBlockType( 'core/site-title', {
+ apiVersion: 3,
+ title: 'Site Title',
+ category: 'theme',
+ edit: () => null,
+ save: () => null,
+ } );
+ registerBlockType( 'core/image', {
+ apiVersion: 3,
+ title: 'Image',
+ category: 'media',
+ attributes: {
+ url: { type: 'string' },
+ alt: { type: 'string' },
+ id: { type: 'number' },
+ width: { type: 'string' },
+ href: { type: 'string' },
+ linkTarget: { type: 'string' },
+ linkDestination: { type: 'string' },
+ align: { type: 'string' },
+ style: { type: 'object' },
+ },
+ edit: () => null,
+ save: () => null,
+ } );
+ enhanceSiteLogoBlock();
+ } );
+
+ afterEach( () => {
+ restoreAllModifiedBlockSettings();
+ resetBlockVariations();
+ unregisterBlockType( 'core/site-logo' );
+ unregisterBlockType( 'core/site-title' );
+ unregisterBlockType( 'core/image' );
+ } );
+
+ it( 'renders the original edit component when the setting is off', () => {
+ mockState.editorSettings = {};
+ renderEdit( 'core/site-logo', { width: 120 } );
+ expect( screen.getByText( 'core edit' ) ).toBeInTheDocument();
+ } );
+
+ it( 'shows the site logo without the controls that change site settings', () => {
+ renderEdit( 'core/site-logo', { width: 120, isLink: true } );
+
+ const image = screen.getByRole( 'img', { name: 'Store logo' } );
+ expect( image ).toHaveClass( 'custom-logo' );
+ expect( image ).toHaveAttribute( 'src', mockMedia.source_url );
+ expect( image.closest( 'a' ) ).toHaveAttribute(
+ 'href',
+ 'http://example.com'
+ );
+ expect( screen.queryByText( 'core edit' ) ).not.toBeInTheDocument();
+ expect( screen.queryByText( 'Replace' ) ).not.toBeInTheDocument();
+ expect(
+ screen.queryByText( 'Use as Site Icon' )
+ ).not.toBeInTheDocument();
+ } );
+
+ it( 'describes the block without saying that edits apply everywhere', () => {
+ const block = createBlock( 'core/site-logo' );
+ expect( inspectorDescription( block ) ).toBe(
+ 'Display an image to represent this site.'
+ );
+
+ mockState.editorSettings = {};
+ expect( inspectorDescription( block ) ).toBeUndefined();
+ } );
+
+ it.each( [ 'inserter', 'transform' ] )(
+ 'keeps the description variation out of the %s',
+ ( scope ) => {
+ expect( variationNamesIn( 'core/site-logo', scope ) ).not.toContain(
+ 'read-only-site-logo'
+ );
+ }
+ );
+
+ it( 'explains how to change the logo in the inspector', () => {
+ renderEdit( 'core/site-logo', { width: 120 } );
+ expect(
+ screen.getByText(
+ /go to Appearance > Editor, or Appearance > Customize > Site Identity in classic themes\./
+ )
+ ).toBeInTheDocument();
+ } );
+
+ it( 'keeps the image width editable', () => {
+ const { setAttributes } = renderEdit( 'core/site-logo', {
+ width: 120,
+ } );
+ fireEvent.change(
+ screen.getByRole( 'spinbutton', { name: 'Image width' } ),
+ { target: { value: '200' } }
+ );
+ expect( setAttributes ).toHaveBeenCalledWith( { width: 200 } );
+ } );
+
+ it( 'shows a placeholder when the site has no logo', () => {
+ mockState.site = { ...mockState.site, site_logo: undefined };
+ renderEdit( 'core/site-logo', { width: 120 } );
+ expect( screen.queryByRole( 'img' ) ).not.toBeInTheDocument();
+ } );
+
+ it( 'keeps the core transforms', () => {
+ const to = getBlockType( 'core/site-logo' )?.transforms?.to ?? [];
+ expect( to ).toContain( coreTransform );
+ } );
+
+ it( 'transforms to an image with the logo, width and link', () => {
+ const block = createBlock( 'core/site-logo', {
+ width: 200,
+ align: 'right',
+ isLink: true,
+ linkTarget: '_blank',
+ shouldSyncIcon: true,
+ style: { spacing: { padding: { top: '10px' } } },
+ } );
+ expect( possibleTransformNames( block ) ).toContain( 'core/image' );
+
+ const [ image ] = switchToBlockType( block, 'core/image' ) ?? [];
+ expect( image.name ).toBe( 'core/image' );
+ expect( image.attributes ).toEqual( {
+ url: mockMedia.source_url,
+ alt: 'Store logo',
+ id: mockMedia.id,
+ width: '200px',
+ align: 'right',
+ href: 'http://example.com',
+ linkTarget: '_blank',
+ linkDestination: 'custom',
+ style: { spacing: { padding: { top: '10px' } } },
+ } );
+ } );
+
+ it( 'uses the default width and no link when they are not set', () => {
+ const block = createBlock( 'core/site-logo', { isLink: false } );
+ const [ image ] = switchToBlockType( block, 'core/image' ) ?? [];
+ expect( image.attributes.width ).toBe( '120px' );
+ expect( image.attributes.href ).toBeUndefined();
+ } );
+
+ it( 'does not offer the image transform when the setting is off', () => {
+ mockState.editorSettings = {};
+ const block = createBlock( 'core/site-logo', { width: 120 } );
+ expect( possibleTransformNames( block ) ).not.toContain( 'core/image' );
+ } );
+} );
diff --git a/packages/js/email-editor/src/blocks/index.ts b/packages/js/email-editor/src/blocks/index.ts
index a51acdf64fb..ae49c1abaef 100644
--- a/packages/js/email-editor/src/blocks/index.ts
+++ b/packages/js/email-editor/src/blocks/index.ts
@@ -29,6 +29,7 @@ import { enhanceQuoteBlock } from './core/quote';
import { filterSetUrlAttribute } from './core/block-edit';
import { enhanceSocialLinksBlock } from './core/social-links';
import { enhanceSiteLogoBlock } from './core/site-logo';
+import { enhanceSiteTitleBlock } from './core/site-title';
import { enableFullWidthBlocks } from './core/full-width';
import { enableProductImageAlignment } from './woocommerce/product-image';
@@ -56,6 +57,7 @@ export function initBlocks() {
alterSupportConfiguration();
enhanceSocialLinksBlock();
enhanceSiteLogoBlock();
+ enhanceSiteTitleBlock();
enableFullWidthBlocks();
enableProductImageAlignment();
removeBlockStylesFromAllBlocks();
diff --git a/packages/js/email-editor/src/store/types.ts b/packages/js/email-editor/src/store/types.ts
index 602bf6e89b3..a8e59824b8b 100644
--- a/packages/js/email-editor/src/store/types.ts
+++ b/packages/js/email-editor/src/store/types.ts
@@ -41,6 +41,7 @@ export type EmailEditorSettings = EditorSettings &
isPreviewMode: boolean;
allowedIframeStyleHandles?: string[];
styles?: EmailBuiltStyles[];
+ readOnlySiteIdentityBlocks?: boolean;
};
export type EmailTheme = Omit< GlobalStylesConfig, 'styles' > & {
diff --git a/plugins/woocommerce/changelog/wooplug-7933-email-editor-site-logo-and-site-title-blocks b/plugins/woocommerce/changelog/wooplug-7933-email-editor-site-logo-and-site-title-blocks
new file mode 100644
index 00000000000..0888c0ddedf
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-7933-email-editor-site-logo-and-site-title-blocks
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Saving an email in the block email editor no longer changes the site's title, logo or icon.
diff --git a/plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php b/plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php
index efcc2b42502..959735dd0f6 100644
--- a/plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php
+++ b/plugins/woocommerce/src/Internal/EmailEditor/PageRenderer.php
@@ -99,8 +99,9 @@ class PageRenderer {
$localized_data['email_types'] = $email_types;
// Modify email editor settings.
- $localized_data['editor_settings']['isFullScreenForced'] = true;
- $localized_data['editor_settings']['displaySendEmailButton'] = false;
+ $localized_data['editor_settings']['isFullScreenForced'] = true;
+ $localized_data['editor_settings']['displaySendEmailButton'] = false;
+ $localized_data['editor_settings']['readOnlySiteIdentityBlocks'] = true;
return $localized_data;
}
diff --git a/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-site-identity.spec.ts b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-site-identity.spec.ts
new file mode 100644
index 00000000000..cf9aa7f5951
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/email-editor/email-editor-site-identity.spec.ts
@@ -0,0 +1,121 @@
+/**
+ * External dependencies
+ */
+import { createClient, WP_API_PATH } from '@woocommerce/e2e-utils-playwright';
+
+/**
+ * Internal dependencies
+ */
+import { expect, request, test, locks } from '../../fixtures/fixtures';
+import { ADMIN_STATE_PATH } from '../../playwright.config';
+import {
+ deleteEmailPost,
+ disableEmailEditor,
+ enableEmailEditor,
+} from './helpers/enable-email-editor-feature';
+import { accessTheEmailEditor } from '../../utils/email';
+import { setOption } from '../../utils/options';
+import { admin } from '../../test-data/data';
+
+const SITE_TITLE = 'Site Identity E2E Store';
+
+const getSiteTitle = async ( baseURL: string ): Promise< string > => {
+ const apiClient = createClient( baseURL, {
+ type: 'basic',
+ username: admin.username,
+ password: admin.password,
+ } );
+ const response = await apiClient.get( `${ WP_API_PATH }/settings` );
+ return response.data.title;
+};
+
+test.describe(
+ 'WooCommerce Email Editor site identity blocks',
+ { lock: locks.EMAIL_FEATURE_FLAGS },
+ () => {
+ test.use( { storageState: ADMIN_STATE_PATH } );
+
+ let originalSiteTitle: string | undefined;
+ let emailPostId: string | null = null;
+
+ test.beforeAll( async ( { baseURL } ) => {
+ originalSiteTitle = await getSiteTitle( baseURL );
+ await setOption( request, baseURL, 'blogname', SITE_TITLE );
+ await enableEmailEditor( baseURL );
+ } );
+
+ test.afterAll( async ( { baseURL } ) => {
+ try {
+ if ( emailPostId ) {
+ await deleteEmailPost( baseURL, emailPostId );
+ }
+ } finally {
+ try {
+ if ( originalSiteTitle !== undefined ) {
+ await setOption(
+ request,
+ baseURL,
+ 'blogname',
+ originalSiteTitle
+ );
+ }
+ } finally {
+ await disableEmailEditor( baseURL );
+ }
+ }
+ } );
+
+ test( 'Saving an email with a Site Title block does not change the site title', async ( {
+ page,
+ baseURL,
+ } ) => {
+ await accessTheEmailEditor( page, 'New order' );
+ emailPostId = new URL( page.url() ).searchParams.get( 'post' );
+ const canvas = page
+ .locator( 'iframe[name="editor-canvas"]' )
+ .contentFrame();
+
+ // Set the insertion point inside the email content.
+ await canvas.getByLabel( 'Block: Heading' ).click();
+ await page
+ .getByRole( 'button', { name: 'Block Inserter' } )
+ .click();
+ await page
+ .getByRole( 'searchbox', { name: 'Search' } )
+ .fill( 'Site Title' );
+ await page
+ .getByRole( 'option', { name: 'Site Title', exact: true } )
+ .click();
+
+ // The template header can contain a Site Title too, but it is locked in the email mode.
+ const siteTitle = canvas.locator(
+ '[data-type="core/site-title"]:not([inert])'
+ );
+ await expect( siteTitle ).toHaveText( SITE_TITLE );
+ await expect(
+ siteTitle.locator( '[contenteditable="true"]' )
+ ).toHaveCount( 0 );
+
+ await siteTitle.click();
+ await page.keyboard.type( ' changed' );
+ await expect( siteTitle ).toHaveText( SITE_TITLE );
+
+ await page
+ .getByRole( 'button', { name: 'Save', exact: true } )
+ .click();
+ // Edited records stay dirty until saved, the site settings included.
+ await expect
+ .poll( () =>
+ page.evaluate(
+ () =>
+ window.wp.data
+ .select( 'core' )
+ .__experimentalGetDirtyEntityRecords().length
+ )
+ )
+ .toBe( 0 );
+
+ expect( await getSiteTitle( baseURL ) ).toBe( SITE_TITLE );
+ } );
+ }
+);