Commit 9990a5aca64 for woocommerce

commit 9990a5aca64c2af69b94291bc011388aeafcdf3a
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date:   Fri Aug 21 11:52:06 2026 +0300

    Add filter for the recent emails query in the email editor (#67859)

    * Add filter for the recent emails query in the email editor

    * Create new query object for the recent emails quer filter

    * Remove orderby and order params from default query

    * Make per_page and status optional in RecentEmailsQuery type

diff --git a/packages/js/email-editor/README.md b/packages/js/email-editor/README.md
index 0eb06009ab7..c848349e283 100644
--- a/packages/js/email-editor/README.md
+++ b/packages/js/email-editor/README.md
@@ -356,3 +356,4 @@ We may add, update and delete any of them.
 | `woocommerce_email_editor_close_action_callback`                   | `function` backAction                                 | `function` backAction                      | Action to perform when the close (back) button is clicked                                                                      |
 | `woocommerce_email_editor_close_content`                           | `React.ComponentType` DefaultBackButtonContent        | `React.ComponentType` Back button content  | Custom component for the back button content in the editor header                                                              |
 | `woocommerce_email_editor_create_coupon_handler`                   | `() => void` handler                                  | `() => void` handler                       | Handler function called when user clicks "Create new coupon". Should open the coupon creation UI.                              |
+| `woocommerce_email_editor_recent_emails_query`                     | `RecentEmailsQuery` query, `string` postType          | `RecentEmailsQuery` query                  | Query used to load the emails listed in the `Recent` category of the template selection modal. Statuses must be registered.    |
diff --git a/packages/js/email-editor/changelog/add-recent-emails-query-filter b/packages/js/email-editor/changelog/add-recent-emails-query-filter
new file mode 100644
index 00000000000..fdf68e579fc
--- /dev/null
+++ b/packages/js/email-editor/changelog/add-recent-emails-query-filter
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add the `woocommerce_email_editor_recent_emails_query` filter so integrations can change which emails the "Recent" category of the template selection modal lists.
diff --git a/packages/js/email-editor/src/index.ts b/packages/js/email-editor/src/index.ts
index fb4797e4738..02d81fceff0 100644
--- a/packages/js/email-editor/src/index.ts
+++ b/packages/js/email-editor/src/index.ts
@@ -31,6 +31,7 @@ export {
 	createStore,
 	type TemplatePreview,
 	type EmailBuiltStyles,
+	type RecentEmailsQuery,
 } from './store';

 /**
diff --git a/packages/js/email-editor/src/store/selectors.ts b/packages/js/email-editor/src/store/selectors.ts
index 86a79b0adb5..c5d50d0af7d 100644
--- a/packages/js/email-editor/src/store/selectors.ts
+++ b/packages/js/email-editor/src/store/selectors.ts
@@ -6,6 +6,7 @@ import { store as coreDataStore } from '@wordpress/core-data';
 import { store as editorStore } from '@wordpress/editor';
 import { store as preferencesStore } from '@wordpress/preferences';
 import { serialize, parse, BlockInstance } from '@wordpress/blocks';
+import { applyFilters } from '@wordpress/hooks';

 /**
  * Internal dependencies
@@ -19,6 +20,7 @@ import {
 	Feature,
 	PersonalizationTag,
 	GlobalEmailStylesPost,
+	RecentEmailsQuery,
 } from './types';

 function getContentFromEntity( entity ): string {
@@ -183,15 +185,38 @@ export const getEditedEmailContent = createRegistrySelector(
 	}
 );

+const DEFAULT_RECENT_EMAILS_QUERY: RecentEmailsQuery = {
+	per_page: 30, // show a maximum of 30 for now
+	status: 'publish,sent',
+};
+
+function isRecentEmailsQuery( value: unknown ): value is RecentEmailsQuery {
+	return !! value && typeof value === 'object' && ! Array.isArray( value );
+}
+
+/**
+ * Returns the emails listed in the "Recent" category of the template selection
+ * modal. The query can be changed with a filter, so integrations can list their
+ * own post statuses. A status has to be registered on the site, otherwise the
+ * REST API rejects the request and the list stays empty.
+ */
 export const getSentEmailEditorPosts = createRegistrySelector(
 	( select ) => () => {
 		const postType = select( storeName ).getEmailPostType();
+
+		const filteredQuery = applyFilters(
+			'woocommerce_email_editor_recent_emails_query',
+			{ ...DEFAULT_RECENT_EMAILS_QUERY },
+			postType
+		);
+
+		const query = isRecentEmailsQuery( filteredQuery )
+			? filteredQuery
+			: DEFAULT_RECENT_EMAILS_QUERY;
+
 		return (
 			select( coreDataStore )
-				.getEntityRecords( 'postType', postType, {
-					per_page: 30, // show a maximum of 30 for now
-					status: 'publish,sent', // show only sent emails
-				} )
+				.getEntityRecords( 'postType', postType, query )
 				?.filter(
 					( post: EmailEditorPostType ) => post?.content?.raw !== '' // filter out empty content
 				) || []
diff --git a/packages/js/email-editor/src/store/types.ts b/packages/js/email-editor/src/store/types.ts
index 0f33a36c136..e77e85e315f 100644
--- a/packages/js/email-editor/src/store/types.ts
+++ b/packages/js/email-editor/src/store/types.ts
@@ -170,6 +170,20 @@ export type TemplatePreview = {

 export type TemplateCategory = string;

+/**
+ * Query used to fetch the emails shown in the "Recent" category of the
+ * template selection modal. Accepts any parameter supported by the posts
+ * REST collection endpoint.
+ */
+export type RecentEmailsQuery = {
+	per_page?: number;
+	status?: string;
+	orderby?: string;
+	order?: string;
+	exclude?: Array< number | string >;
+	[ key: string ]: unknown;
+};
+
 export type Feature =
 	| 'fullscreenMode'
 	| 'showIconLabels'