Skip to content

Add the usage of the render_email_callback to the email rendering. #59070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lysyjan
Copy link
Contributor

@lysyjan lysyjan commented Jun 23, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes WOOPLUG-4676

  • This PR changes the logic for rendering blocks.
  • It also returns the list of supported blocks back to the PHP package.
  • It removes the class Blocks_Registry.

Screenshots or screen recordings:

N/A

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Enable the email editor feature in WooCommerce > Settings > Advanced> Features
  2. Go to WooCommerce > Settings > Emails and open an email in the editor
  3. Verify allowed blocks in the email editor and its functionality
  4. Check that the email preview and sent email are rendered correctly

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

📝 Walkthrough

Walkthrough

This change removes the custom Blocks_Registry system and migrates block registration and rendering in the email editor to use WordPress’s native WP_Block_Type_Registry and the render_email_callback mechanism. Related JavaScript logic is deleted, and block support configuration is consolidated in PHP. Tests and documentation are updated accordingly.

Changes

File(s) / Path(s) Change Summary
packages/js/email-editor/src/blocks/core/supported-blocks.ts, packages/js/email-editor/src/blocks/index.ts Removed JS logic for allowed blocks and email block support, deleted setEmailBlockSupport export and usage.
packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-blocks-registry.php, packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Blocks_Registry_Test.php Removed Blocks_Registry class and its integration tests.
packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php Refactored to use WP_Block_Type_Registry and render_email_callback; removed dependency on Blocks_Registry.
packages/php/email-editor/src/Integrations/Core/class-initializer.php Added ALLOWED_BLOCK_TYPES constant; introduced update_block_settings to set supports.email and render_email_callback.
packages/php/email-editor/src/class-bootstrap.php Added filter to update block settings using update_block_settings.
packages/php/email-editor/src/class-email-editor-container.php, packages/php/email-editor/tests/integration/Email_Editor_Integration_Test_Case.php Removed Blocks_Registry from DI container and related imports; updated Content_Renderer instantiation to inject Email_Editor_Logger.
packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php Updated tests to use WP_Block_Type_Registry and fallback renderer directly; removed registry mocks.
packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php Added USED_CORE_BLOCKS constant; updated setup to re-register blocks with new settings.
packages/php/email-editor/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to, packages/php/email-editor/src/Engine/Renderer/readme.md Updated docs and changelogs to reflect migration to render_email_callback and PHP-based block support configuration.
plugins/woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php Removed Blocks_Registry usage and block renderer registration method.
plugins/woocommerce/src/Internal/EmailEditor/Integration.php Added register_blocks method to register WooContent block during initialization.
plugins/woocommerce/src/Internal/EmailEditor/Renderer/Blocks/WooContent.php Refactored WooContent to register itself using render_email_callback; removed inheritance from Abstract_Block_Renderer.
plugins/woocommerce/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to Updated changelog to note WooContent block migration to render_email_callback.

Sequence Diagram(s)

sequenceDiagram
    participant WP as WordPress Core
    participant Initializer as Initializer (PHP)
    participant Block as Block Renderer (e.g., WooContent)
    participant Renderer as Content_Renderer

    WP->>Initializer: Apply 'block_type_metadata_settings' filter
    Initializer->>WP: For allowed blocks, set supports.email & render_email_callback

    WP->>Renderer: Request to render a block
    Renderer->>WP: Get block type from WP_Block_Type_Registry
    alt Block has render_email_callback
        Renderer->>Block: Call render_email_callback
        Block-->>Renderer: Return rendered content
    else No callback
        Renderer->>Renderer: Use fallback renderer
    end
    Renderer-->>WP: Return rendered content
Loading

Possibly related PRs

  • woocommerce/woocommerce#58966: Introduced the now-removed JS function for email block support; this PR reverses and replaces that logic in favor of PHP-based configuration.
  • woocommerce/woocommerce#58796: Refactored block rendering to use a new Rendering_Context and improved callback structure; related due to changes in core rendering architecture and callback usage.

Poem

A registry’s gone, the code is anew,
PHP now decides which blocks make it through.
With callbacks for email, the rendering is tight,
No more JS lists hidden out of sight.
The Woo rabbit hops with a jubilant cheer—
“Block rendering’s simpler, the future is here!”
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c1b5e7 and 45cb5f6.

📒 Files selected for processing (2)
  • packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php (4 hunks)
  • packages/php/email-editor/src/Integrations/Core/class-initializer.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php
🧰 Additional context used
🧠 Learnings (1)
packages/php/email-editor/src/Integrations/Core/class-initializer.php (1)
Learnt from: lysyjan
PR: woocommerce/woocommerce#59070
File: packages/php/email-editor/src/Integrations/Core/class-initializer.php:103-141
Timestamp: 2025-06-23T16:55:58.220Z
Learning: The core/spacer block in the WooCommerce email editor intentionally does not have a dedicated renderer class and is handled by the fallback renderer instead of having an explicit render_email_callback assigned in the switch statement.
⏰ Context from checks skipped due to timeout of 90000ms (23)
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: JavaScript - @woocommerce/email-editor [unit]
  • GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: JavaScript - @woocommerce/admin-library [unit]
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHPStan: PHP 8.4 - @woocommerce/email-editor-php-config [unit]
  • GitHub Check: PHPStan: PHP 7.4 - @woocommerce/email-editor-php-config [unit]
  • GitHub Check: Lint - @woocommerce/email-editor
  • GitHub Check: PHP: 8.1 WP: latest [WP latest] - @woocommerce/email-editor-php-config [unit:php]
  • GitHub Check: Lint - @woocommerce/email-editor-php-config
  • GitHub Check: Lint - @woocommerce/plugin-woocommerce
  • GitHub Check: Validate markdown
  • GitHub Check: Check Asset Sizes
  • GitHub Check: build
🔇 Additional comments (7)
packages/php/email-editor/src/Integrations/Core/class-initializer.php (7)

12-26: LGTM: Import statements properly reflect the new architecture.

The imports correctly include all the specific renderer classes that are now directly instantiated in the switch statement, replacing the previous centralized registry approach.


35-50: LGTM: Well-organized constant for supported block types.

The ALLOWED_BLOCK_TYPES constant effectively consolidates the list of supported blocks in PHP, replacing the JavaScript definition that was removed. This centralization improves maintainability and ensures consistency between the allowed blocks and their renderers.


53-57: LGTM: Efficient caching mechanism for renderer instances.

The $renderers array provides proper caching to avoid repeatedly instantiating renderer objects, which is good for performance.


62-65: LGTM: Simplified initialization aligns with new architecture.

The initialize method has been correctly streamlined to focus only on filters, as block renderer registration is now handled through the render_email_callback mechanism via the update_block_settings method.


107-114: LGTM: Proper implementation of the new block settings approach.

The update_block_settings method correctly:

  • Checks if the block is in the allowed list
  • Sets supports.email to true for email editor compatibility
  • Assigns the render_email_callback to the render_block method

This effectively replaces the previous registry-based approach with WordPress core's block type system.


124-131: LGTM: Robust block rendering with proper error handling.

The render_block method includes appropriate guard clauses for missing blockName and delegates to the appropriate renderer. The fallback to returning the original $block_content ensures graceful handling of edge cases.


139-189: LGTM: Comprehensive renderer factory with proper caching.

The get_block_renderer method effectively:

  • Implements caching to avoid duplicate instantiation
  • Covers all blocks in ALLOWED_BLOCK_TYPES through explicit cases or fallback
  • Uses appropriate renderer classes for each block type
  • Handles the core/spacer block through the fallback renderer as intended (per previous learnings)

The switch statement properly maps blocks to their respective renderers, with core/heading and core/paragraph both correctly using the Text renderer.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jun 23, 2025
@lysyjan lysyjan force-pushed the wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to branch from 8f68dbf to 522f3ad Compare June 23, 2025 12:00
lysyjan added 2 commits June 23, 2025 14:26
This change allows defining a rendering callback that is used for rendering in emails.
The class Blocks_Registry is not needed anymore when we use the block custom callback.
@lysyjan lysyjan force-pushed the wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to branch 2 times, most recently from f98d61a to c52fb84 Compare June 23, 2025 12:40
@lysyjan lysyjan added Ballade Issues related to block-based email editor package: @woocommerce/email-editor issues related to the @woocommerce/email-editor package labels Jun 23, 2025
lysyjan added 4 commits June 23, 2025 16:47
- I didn't move placeholder const to avoid changes in the email templates.
We decided to keep rendering callbacks and block configuration at one place. This place should be PHP package.
@lysyjan lysyjan force-pushed the wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to branch from c52fb84 to 07a4f8d Compare June 23, 2025 14:48
@lysyjan lysyjan marked this pull request as ready for review June 23, 2025 15:20
@lysyjan lysyjan self-assigned this Jun 23, 2025
Copy link
Contributor

github-actions bot commented Jun 23, 2025

Size Change: -1.06 kB (-0.02%)

Total Size: 5.84 MB

Filename Size Change
./packages/js/data/build/payment-settings/actions.js 1.21 kB +238 B (+24.56%) 🚨
./packages/js/data/build/payment-settings/resolvers.js 765 B +189 B (+32.81%) 🚨
./packages/js/email-editor/build/blocks/core/supported-blocks.js 0 B -493 B (removed) 🏆
./plugins/woocommerce/client/admin/build/chunks/4910.js 14.3 kB +304 B (+2.17%)
./plugins/woocommerce/client/admin/build/chunks/launch-store.js 13.7 kB +312 B (+2.34%)
./plugins/woocommerce/client/admin/build/chunks/settings-payments-main.js 13.3 kB +285 B (+2.19%)
./plugins/woocommerce/client/admin/build/wp-admin-scripts/settings-embed.js 375 kB +501 B (+0.13%)
./plugins/woocommerce/client/blocks/build/all-products-rtl.css 3.4 kB -385 B (-10.16%) 👏
./plugins/woocommerce/client/blocks/build/all-products.css 3.4 kB -385 B (-10.17%) 👏
./plugins/woocommerce/client/blocks/build/all-products.js 36 kB -901 B (-2.44%)
./plugins/woocommerce/client/blocks/build/blockified-product-details.js 0 B -2.35 kB (removed) 🏆
./plugins/woocommerce/client/blocks/build/blockified-product-reviews.js 0 B -2.67 kB (removed) 🏆
./plugins/woocommerce/client/blocks/build/product-reviews-rtl.css 0 B -343 B (removed) 🏆
./plugins/woocommerce/client/blocks/build/product-reviews.css 0 B -343 B (removed) 🏆
./plugins/woocommerce/client/blocks/build/wc-blocks-editor-style-rtl.css 7.25 kB -104 B (-1.41%)
./plugins/woocommerce/client/blocks/build/wc-blocks-editor-style.css 7.25 kB -103 B (-1.4%)
./plugins/woocommerce/client/blocks/build/woocommerce/blockified-product-reviews.js 0 B -581 B (removed) 🏆
./plugins/woocommerce/client/blocks/build/product-details.js 2.46 kB +2.46 kB (new file) 🆕
./plugins/woocommerce/client/blocks/build/product-reviews.js 2.65 kB +2.65 kB (new file) 🆕
./plugins/woocommerce/client/blocks/build/woocommerce/product-reviews.js 578 B +578 B (new file) 🆕

compressed-size-action

Copy link
Contributor

github-actions bot commented Jun 23, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php (1)

44-62: Consider simplifying the block re-registration logic.

While the current approach works, the manual unregistering and re-registering of blocks in setUp is complex and potentially fragile. Consider these alternatives:

  1. Mock the block registry: Use dependency injection to provide a test-specific block registry
  2. Separate test helper method: Extract the re-registration logic into a reusable helper method
  3. Integration test approach: Consider if this level of block manipulation is necessary or if the functionality could be tested differently

The current implementation modifies global state which could interfere with other tests.

+ /**
+  * Helper method to register blocks with email callbacks for testing
+  *
+  * @param array $blocks Array of block names to register
+  */
+ private function registerBlocksWithEmailCallbacks(array $blocks): void {
+     $initializer = $this->di_container->get(Initializer::class);
+     
+     foreach ($blocks as $block) {
+         $block_type = \WP_Block_Type_Registry::get_instance()->get_registered($block);
+         $this->assertInstanceOf(\WP_Block_Type::class, $block_type);
+         // ... rest of the registration logic
+     }
+ }

Do you want me to help refactor this test setup to be more maintainable?

packages/php/email-editor/src/Integrations/Core/class-initializer.php (1)

98-144: Consider caching renderer instances for better performance.

Creating new renderer instances on every call to update_block_settings could be inefficient if this filter is applied frequently during block registration. Consider implementing a singleton pattern or caching these instances.

Example approach using static caching:

+    /**
+     * Cached renderer instances.
+     */
+    private static $renderer_cache = array();
+
+    /**
+     * Get or create a renderer instance.
+     */
+    private static function get_renderer( string $renderer_class, ...$args ) {
+        $cache_key = $renderer_class . serialize( $args );
+        if ( ! isset( self::$renderer_cache[ $cache_key ] ) ) {
+            self::$renderer_cache[ $cache_key ] = new $renderer_class( ...$args );
+        }
+        return self::$renderer_cache[ $cache_key ];
+    }

     public function update_block_settings( array $settings ): array {
         // ... existing code ...
         switch ( $settings['name'] ) {
             case 'core/heading':
             case 'core/paragraph':
-                $settings['render_email_callback'] = array( new Text(), 'render' );
+                $settings['render_email_callback'] = array( self::get_renderer( Text::class ), 'render' );
                 break;
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ecf69e and 6fb5dad.

📒 Files selected for processing (19)
  • packages/js/email-editor/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to (1 hunks)
  • packages/js/email-editor/src/blocks/core/supported-blocks.ts (0 hunks)
  • packages/js/email-editor/src/blocks/index.ts (0 hunks)
  • packages/php/email-editor/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to (1 hunks)
  • packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-blocks-registry.php (0 hunks)
  • packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php (4 hunks)
  • packages/php/email-editor/src/Engine/Renderer/class-renderer.php (0 hunks)
  • packages/php/email-editor/src/Engine/Renderer/readme.md (1 hunks)
  • packages/php/email-editor/src/Integrations/Core/class-initializer.php (2 hunks)
  • packages/php/email-editor/src/class-bootstrap.php (1 hunks)
  • packages/php/email-editor/src/class-email-editor-container.php (0 hunks)
  • packages/php/email-editor/tests/integration/Email_Editor_Integration_Test_Case.php (0 hunks)
  • packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Blocks_Registry_Test.php (0 hunks)
  • packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php (2 hunks)
  • packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php (2 hunks)
  • plugins/woocommerce/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to (1 hunks)
  • plugins/woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php (1 hunks)
  • plugins/woocommerce/src/Internal/EmailEditor/Integration.php (3 hunks)
  • plugins/woocommerce/src/Internal/EmailEditor/Renderer/Blocks/WooContent.php (1 hunks)
💤 Files with no reviewable changes (7)
  • packages/php/email-editor/src/Engine/Renderer/class-renderer.php
  • packages/js/email-editor/src/blocks/index.ts
  • packages/php/email-editor/tests/integration/Email_Editor_Integration_Test_Case.php
  • packages/js/email-editor/src/blocks/core/supported-blocks.ts
  • packages/php/email-editor/src/class-email-editor-container.php
  • packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Blocks_Registry_Test.php
  • packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-blocks-registry.php
🔇 Additional comments (18)
plugins/woocommerce/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to (1)

1-4: LGTM! Well-structured changelog entry.

The changelog entry appropriately describes the migration to render_email_callback with correct significance level and type classification.

plugins/woocommerce/src/Internal/EmailEditor/Integration.php (3)

12-12: LGTM! Proper import added.

The import for WooContent is correctly added to support the new block registration functionality.


83-83: LGTM! Proper initialization sequence.

The call to register_blocks() is appropriately placed in the initialization sequence.


128-134: LGTM! Clean block registration implementation.

The register_blocks() method properly instantiates and registers the WooContent block. The implementation follows good practices by delegating the registration logic to the block class itself.

plugins/woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php (2)

15-15: LGTM! Constant simplified appropriately.

The WOO_EMAIL_CONTENT_PLACEHOLDER constant has been properly simplified while maintaining its functionality.


64-64: ```shell
#!/bin/bash

Search for the register_block_renderers method definition

rg -n "function register_block_renderers" -C2

Search for any references to register_block_renderers

rg -n "register_block_renderers"

Search for the action hook usage

rg -n "woocommerce_email_blocks_renderer_initialized"

Locate the Integration class and its register_blocks method

rg -n "class Integration" -C2
rg -n "function register_blocks" -C2


</details>
<details>
<summary>plugins/woocommerce/src/Internal/EmailEditor/Renderer/Blocks/WooContent.php (3)</summary>

`12-18`: **LGTM! Clean class structure.**

The class has been properly refactored to remove the inheritance from `Abstract_Block_Renderer` and includes a well-defined block name property.

---

`20-36`: **LGTM! Proper WordPress block registration.**

The `register()` method correctly implements the new pattern by:
- Using WordPress's native `register_block_type` function
- Setting appropriate block supports (inserter disabled, email enabled)
- Properly configuring the `render_email_callback` to use the class's render method

This aligns well with the migration from the custom Blocks_Registry system to WordPress's native block type registry.

---

`43-45`: **LGTM! Simplified render method.**

The render method has been correctly refactored to be public and parameterless, following the new `render_email_callback` pattern while maintaining its core functionality of returning the placeholder constant.

</details>
<details>
<summary>packages/js/email-editor/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to (1)</summary>

`1-5`: **LGTM - Clear changelog entry.**

The changelog entry appropriately documents the migration of the allowed blocks constant from JavaScript to PHP, with correct significance and type classifications.

</details>
<details>
<summary>packages/php/email-editor/changelog/wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to (1)</summary>

`1-5`: **LGTM - Comprehensive changelog entry.**

The changelog entry accurately documents the introduction of `render_email_callback` support and removal of the `Blocks_Registry` class, representing significant architectural improvements.

</details>
<details>
<summary>packages/php/email-editor/src/class-bootstrap.php (1)</summary>

`66-71`: Let’s search the entire repo for the method and its class to confirm the signature.


```shell
#!/bin/bash
# 1) Find every occurrence of update_block_settings
rg -n 'update_block_settings' .

# 2) Locate the CoreEmailEditorIntegration class and inspect its methods
rg -n 'class CoreEmailEditorIntegration' -A20 .
packages/php/email-editor/src/Engine/Renderer/readme.md (1)

7-7: LGTM - Documentation correctly updated.

The documentation update properly reflects the architectural change, directing developers to the new PHP location for adding allowed core blocks instead of the removed JavaScript location.

packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Renderer_Test.php (1)

21-29: LGTM - Well-defined test constants.

The USED_CORE_BLOCKS constant clearly defines which blocks are tested and provides good documentation for the test scope.

packages/php/email-editor/src/Integrations/Core/class-initializer.php (2)

12-23: LGTM!

The imports are properly organized and follow PSR-4 namespace conventions.


29-48: LGTM!

Good approach to centralize the list of supported blocks in PHP, replacing the JavaScript-based configuration.

packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php (1)

12-12: LGTM!

The test changes correctly reflect the architectural shift from the custom Blocks_Registry to WordPress's native block type registry with render_email_callback support.

Also applies to: 83-111

packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php (1)

13-15: LGTM!

The refactoring properly implements the render_email_callback pattern using WordPress's native WP_Block_Type_Registry, with appropriate fallback handling for blocks without email-specific rendering.

Also applies to: 38-43, 80-85, 99-103, 163-168

@lysyjan lysyjan assigned costasovo and unassigned lysyjan Jun 23, 2025
@lysyjan lysyjan requested a review from costasovo June 23, 2025 16:52
Copy link
Contributor

Testing Guidelines

Hi @costasovo ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@lysyjan lysyjan assigned lysyjan and unassigned costasovo Jun 24, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb5dad and 7c1b5e7.

📒 Files selected for processing (4)
  • packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php (4 hunks)
  • packages/php/email-editor/src/Integrations/Core/class-initializer.php (2 hunks)
  • packages/php/email-editor/src/class-email-editor-container.php (1 hunks)
  • packages/php/email-editor/tests/integration/Email_Editor_Integration_Test_Case.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/php/email-editor/tests/integration/Email_Editor_Integration_Test_Case.php
  • packages/php/email-editor/src/class-email-editor-container.php
  • packages/php/email-editor/src/Integrations/Core/class-initializer.php
⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHPStan: PHP 7.4 - @woocommerce/email-editor-php-config [unit]
  • GitHub Check: JavaScript - @woocommerce/admin-library [unit]
  • GitHub Check: JavaScript - @woocommerce/email-editor [unit]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHP: 8.1 WP: latest [WP latest] - @woocommerce/email-editor-php-config [unit:php]
  • GitHub Check: PHPStan: PHP 8.4 - @woocommerce/email-editor-php-config [unit]
  • GitHub Check: Lint - @woocommerce/plugin-woocommerce
  • GitHub Check: Validate markdown
  • GitHub Check: Check Asset Sizes
  • GitHub Check: build
🔇 Additional comments (3)
packages/php/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php (3)

11-11: LGTM: Clean import additions for the refactor.

The new imports properly support the transition from custom Blocks_Registry to WordPress core WP_Block_Type_Registry, along with the new logging and fallback capabilities.

Also applies to: 14-14, 16-16


39-94: LGTM: Well-structured property additions.

The new properties properly encapsulate the dependencies for the refactored architecture:

  • WP_Block_Type_Registry for WordPress core block management
  • Fallback renderer for graceful degradation
  • Email_Editor_Logger for error tracking

The documentation is clear and follows consistent patterns.


96-115: Constructor refactor looks good with proper dependency management.

The constructor properly initializes the WordPress core registry singleton and creates the fallback renderer instance. The parameter change from Blocks_Registry to Email_Editor_Logger aligns with the architectural refactor.

Verify that all instantiations of this class have been updated to match the new constructor signature:

#!/bin/bash
# Description: Check for instantiations of Content_Renderer to ensure they match new constructor signature

# Search for Content_Renderer instantiations
rg -A 10 "new Content_Renderer|Content_Renderer\(" --type php

@lysyjan lysyjan assigned costasovo and unassigned lysyjan Jun 24, 2025
@lysyjan
Copy link
Contributor Author

lysyjan commented Jun 24, 2025

@costasovo The PR is updated.

Copy link
Contributor

@costasovo costasovo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates! Great job!

Testing performed

  1. I created an email with various blocks and checked that all blocks are available in inserter. This PR refactors how they are registered to the editor.
Screenshot 2025-06-24 at 15 04 24
  1. Checked blocks are rendered in the preview
Screenshot 2025-06-24 at 15 04 51
  1. Sent a test email to Mailpit and verified all blocks were rendered
Screenshot 2025-06-24 at 15 06 02

@costasovo costasovo assigned lysyjan and unassigned costasovo Jun 24, 2025
@costasovo costasovo merged commit 02f20c4 into trunk Jun 24, 2025
34 checks passed
@costasovo costasovo deleted the wooplug-4676-block-registration-api-add-usage-of-render_email_callback-to branch June 24, 2025 13:11
@github-actions github-actions bot added this to the 10.1.0 milestone Jun 24, 2025
Kallyan01 pushed a commit to Kallyan01/woocommerce that referenced this pull request Jun 26, 2025
…oocommerce#59070)

* Use the custom block property render_email_callback for rendering

This change allows defining a rendering callback that is used for rendering in emails.

* Remove the class Blocks_Registry and its test

The class Blocks_Registry is not needed anymore when we use the block custom callback.

* Replace using Blocks_Registry with register_block_type function

- I didn't move placeholder const to avoid changes in the email templates.

* Add changelogs

* Remove the list of allowed blocks from email-editor JS package

We decided to keep rendering callbacks and block configuration at one place. This place should be PHP package.

* Add settings supports.email to true for allowed core blocks

* Add changelog and update readme.md

* Refactor setting render_email_callback to one method

This refactoring should prevent the creation of class instances earlier than necessary.

* Add internal property for caching renderer instances

* Add try-catch statement around calling the custom callback

* Fix the incorrect exit and change method to private
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ballade Issues related to block-based email editor package: @woocommerce/email-editor issues related to the @woocommerce/email-editor package plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants