Commit a98cf8b5d55 for woocommerce
commit a98cf8b5d555a88d8ce5e612a98ce3d9e89be56b
Author: Rostislav Wolný <1082140+costasovo@users.noreply.github.com>
Date: Tue Nov 24 17:05:38 2026 +0100
[Email Editor] Remove unused theme meta reads and filter hook (#71319)
* Remove unused theme meta reads from the email editor
Nothing writes the `woocommerce_email_theme` meta and nothing fires the
`woocommerce_email_editor_rendering_theme_styles` filter. Email styles are
stored in `User_Theme`, so this code does nothing. The public method and
constant are deprecated instead of removed, because the package is public.
The caption test now sets the colour through the theme JSON filter, which
is the path real emails take.
diff --git a/packages/php/email-editor/changelog/remove-email-editor-dead-theme-meta b/packages/php/email-editor/changelog/remove-email-editor-dead-theme-meta
new file mode 100644
index 00000000000..18e35fe85f8
--- /dev/null
+++ b/packages/php/email-editor/changelog/remove-email-editor-dead-theme-meta
@@ -0,0 +1,4 @@
+Significance: minor
+Type: update
+
+Stop applying element styles from the legacy `woocommerce_email_theme` post meta, and deprecate `Email_Editor::extend_email_theme_styles()` and `Email_Editor::WOOCOMMERCE_EMAIL_META_THEME_TYPE`.
diff --git a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php
index 1283b54fe8e..6d333e733bf 100644
--- a/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php
+++ b/packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php
@@ -285,7 +285,7 @@ class Content_Renderer {
return array(
'html' => $rendered_html,
- 'styles' => $this->collect_styles( $post, $template ),
+ 'styles' => $this->collect_styles( $post ),
);
}
@@ -661,11 +661,10 @@ class Content_Renderer {
/**
* Collects CSS for the rendered content without inlining it.
*
- * @param WP_Post $post Post object.
- * @param WP_Block_Template|null $template Block template.
+ * @param WP_Post $post Post object.
* @return string The collected CSS string (without <style> wrapper).
*/
- private function collect_styles( WP_Post $post, $template = null ): string {
+ private function collect_styles( WP_Post $post ): string {
$styles = (string) file_get_contents( __DIR__ . '/' . self::CONTENT_STYLES_FILE );
$styles .= (string) file_get_contents( __DIR__ . '/../../content-shared.css' );
@@ -689,7 +688,7 @@ class Content_Renderer {
);
// Get styles from theme.
- $styles .= $this->theme_controller->get_stylesheet_for_rendering( $post, $template );
+ $styles .= $this->theme_controller->get_stylesheet_for_rendering();
$block_support_styles = $this->theme_controller->get_stylesheet_from_context( 'block-supports', array() );
// Get styles from block-supports stylesheet. This includes rules such as layout (contentWidth) that some blocks use.
// @see https://github.com/WordPress/WordPress/blob/3c5da9c74344aaf5bf8097f2e2c6a1a781600e03/wp-includes/script-loader.php#L3134
diff --git a/packages/php/email-editor/src/Engine/class-email-editor.php b/packages/php/email-editor/src/Engine/class-email-editor.php
index 6d1545e92b5..b79e7f8f94a 100644
--- a/packages/php/email-editor/src/Engine/class-email-editor.php
+++ b/packages/php/email-editor/src/Engine/class-email-editor.php
@@ -23,6 +23,11 @@ use WP_Theme_JSON;
* See register_post_type for details about EmailPostType args.
*/
class Email_Editor {
+ /**
+ * Post meta key for per-email theme styles. Nothing writes this meta; email styles live in User_Theme.
+ *
+ * @deprecated 2.21.0
+ */
public const WOOCOMMERCE_EMAIL_META_THEME_TYPE = 'woocommerce_email_theme';
/**
@@ -112,7 +117,6 @@ class Email_Editor {
public function initialize(): void {
$this->logger->info( 'Initializing email editor' );
do_action( 'woocommerce_email_editor_initialized' );
- add_filter( 'woocommerce_email_editor_rendering_theme_styles', array( $this, 'extend_email_theme_styles' ), 10, 2 );
$this->register_block_patterns();
$this->register_email_post_types();
@@ -402,11 +406,14 @@ class Email_Editor {
/**
* Extends the email theme styles with the email specific styles.
*
+ * @deprecated 2.21.0 Email styles live in User_Theme, so there is nothing to merge.
+ *
* @param WP_Theme_JSON $theme Email theme styles.
* @param WP_Post $post Email post object.
* @return WP_Theme_JSON
*/
public function extend_email_theme_styles( WP_Theme_JSON $theme, WP_Post $post ): WP_Theme_JSON {
+ _deprecated_function( __METHOD__, '2.21.0' );
$email_theme = get_post_meta( $post->ID, self::WOOCOMMERCE_EMAIL_META_THEME_TYPE, true );
if ( $email_theme && is_array( $email_theme ) ) {
$theme->merge( new WP_Theme_JSON( $email_theme ) );
diff --git a/packages/php/email-editor/src/Engine/class-theme-controller.php b/packages/php/email-editor/src/Engine/class-theme-controller.php
index e4400c63ed5..aaf523fce8d 100644
--- a/packages/php/email-editor/src/Engine/class-theme-controller.php
+++ b/packages/php/email-editor/src/Engine/class-theme-controller.php
@@ -197,11 +197,11 @@ class Theme_Controller {
/**
* Get stylesheet for rendering.
*
- * @param WP_Post|null $post Post object.
- * @param WP_Block_Template|null $template Template object.
+ * @param WP_Post|null $post Unused. Kept for backward compatibility.
+ * @param WP_Block_Template|null $template Unused. Kept for backward compatibility.
* @return string
*/
- public function get_stylesheet_for_rendering( ?WP_Post $post = null, $template = null ): string {
+ public function get_stylesheet_for_rendering( ?WP_Post $post = null, $template = null ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Unused parameters kept for backward compatibility.
$email_theme_settings = $this->get_settings();
$css_presets = '';
@@ -232,21 +232,6 @@ class Theme_Controller {
// Element specific styles.
$elements_styles = $this->get_theme()->get_raw_data()['styles']['elements'] ?? array();
- // Because the section styles is not a part of the output the `get_styles_block_nodes` method, we need to get it separately.
- if ( $template && $template->wp_id ) {
- $template_theme = (array) get_post_meta( $template->wp_id, Email_Editor::WOOCOMMERCE_EMAIL_META_THEME_TYPE, true );
- $template_styles = (array) ( $template_theme['styles'] ?? array() );
- $template_elements = $template_styles['elements'] ?? array();
- $elements_styles = array_replace_recursive( (array) $elements_styles, (array) $template_elements );
- }
-
- if ( $post ) {
- $post_theme = (array) get_post_meta( $post->ID, 'woocommerce_email_theme', true );
- $post_styles = (array) ( $post_theme['styles'] ?? array() );
- $post_elements = $post_styles['elements'] ?? array();
- $elements_styles = array_replace_recursive( (array) $elements_styles, (array) $post_elements );
- }
-
$css_elements = '';
foreach ( $elements_styles as $key => $elements_style ) {
$selector = $key;
diff --git a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php
index aea36b59823..bfd7cb727a3 100644
--- a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php
+++ b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php
@@ -9,6 +9,7 @@ declare(strict_types = 1);
namespace Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer;
use Automattic\WooCommerce\EmailEditor\Engine\Email_Editor;
+use Automattic\WooCommerce\EmailEditor\Engine\User_Theme;
use Automattic\WooCommerce\EmailEditor\Integrations\Core\Initializer as Core_Initializer;
use Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks\Fallback;
@@ -79,16 +80,22 @@ class Content_Renderer_Test extends \Email_Editor_Integration_Test_Case {
)
);
$this->assertIsInt( $email_post_id );
- update_post_meta(
- $email_post_id,
- 'woocommerce_email_theme',
+ $user_theme_post = $this->di_container->get( User_Theme::class )->get_user_theme_post();
+ wp_update_post(
array(
- 'styles' => array(
- 'elements' => array(
- 'caption' => array(
- 'color' => array( 'text' => '#f78da7' ),
+ 'ID' => $user_theme_post->ID,
+ 'post_content' => (string) wp_json_encode(
+ array(
+ 'version' => 3,
+ 'isGlobalStylesUserThemeJSON' => true,
+ 'styles' => array(
+ 'elements' => array(
+ 'caption' => array(
+ 'color' => array( 'text' => '#f78da7' ),
+ ),
+ ),
),
- ),
+ )
),
)
);