Commit 304c33de5c2 for woocommerce
commit 304c33de5c20ac9af4bdfa6bbd355be02e145d7e
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date: Mon Aug 24 12:52:10 2026 +0300
Fix preloading of recent emails in email editor template modal (#67911)
diff --git a/packages/php/email-editor/README.md b/packages/php/email-editor/README.md
index ab6f9ad546d..40b87b8ec7b 100644
--- a/packages/php/email-editor/README.md
+++ b/packages/php/email-editor/README.md
@@ -111,6 +111,7 @@ We may add, update and delete any of them.
| `woocommerce_email_editor_allowed_iframe_style_handles` | `Array` $allowed_iframe_style_handles | `Array` $allowed_iframe_style_handles | Filter the list of allowed stylesheet handles in the editor iframe. |
| `woocommerce_email_editor_script_localization_data` | `Array` $localization_data | `Array` $localization_data | Use to modify inlined JavaScript variables used by Email Editor client. |
| `woocommerce_email_editor_styles_unsupported_props` | `Array` $unsupported_props | `Array` $unsupported_props | Filter the list of unsupported style properties (as nested key paths) that will be removed before block styles are converted to CSS. |
+| `woocommerce_email_editor_preload_rest_api_routes` | `Array` $routes, `string` $post_type, `int\|string` $post_id | `Array` $routes | REST API routes preloaded for the email editor. A preloaded route is only used when it matches the request made by the editor. |
## Logging
diff --git a/packages/php/email-editor/changelog/fix-recent-emails-preload b/packages/php/email-editor/changelog/fix-recent-emails-preload
new file mode 100644
index 00000000000..929f8024ca0
--- /dev/null
+++ b/packages/php/email-editor/changelog/fix-recent-emails-preload
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Preload the recent emails used by the template selection modal, and add the woocommerce_email_editor_preload_rest_api_routes filter.
diff --git a/packages/php/email-editor/src/Engine/class-assets-manager.php b/packages/php/email-editor/src/Engine/class-assets-manager.php
index 4202040aa4a..7e3a7de0198 100644
--- a/packages/php/email-editor/src/Engine/class-assets-manager.php
+++ b/packages/php/email-editor/src/Engine/class-assets-manager.php
@@ -217,6 +217,7 @@ class Assets_Manager {
private function preload_rest_api_data( $post_id, string $post_type ): void {
$email_post_type = $post_type;
$user_theme_post_id = $this->user_theme->get_user_theme_post()->ID;
+ $post = is_numeric( $post_id ) ? get_post( (int) $post_id ) : null;
$template_slug = get_post_meta( (int) $post_id, '_wp_page_template', true );
$routes = array(
"/wp/v2/{$email_post_type}/" . intval( $post_id ) . '?context=edit',
@@ -230,13 +231,26 @@ class Assets_Manager {
'/wp/v2/taxonomies?context=view',
);
- if ( is_string( $template_slug ) ) {
+ if ( is_string( $template_slug ) && '' !== $template_slug ) {
$routes[] = '/wp/v2/templates/lookup?slug=' . $template_slug;
- } else {
+ }
+
+ // Recent emails listed by the template selection modal, which opens on emails with no content.
+ if ( $post instanceof \WP_Post && '' === $post->post_content ) {
$routes[] = "/wp/v2/{$email_post_type}?context=edit&per_page=30&status=publish,sent";
}
- // Preload the data for the specified routes.
+ /**
+ * Filters the REST API routes preloaded for the email editor.
+ *
+ * @param string[] $routes The routes to preload.
+ * @param string $post_type The edited post type.
+ * @param int|string $post_id The edited post ID.
+ *
+ * @since 11.2.0
+ */
+ $routes = apply_filters( 'woocommerce_email_editor_preload_rest_api_routes', $routes, $post_type, $post_id );
+
$preload_data = array_reduce(
$routes,
'rest_preload_api_request',