Add post_types field to the template REST API response

We want to use post_type for filtering email templates.
There is a PR that adds this property https://github.com/WordPress/wordpress-develop/pull/7530
but it is not merged.
This commit added the property and also future compatibility check
so that we don't attempt to add it after the PR is merged.
[MAILPOET-6356]
This commit is contained in:
Rostislav Wolny
2024-12-13 17:29:59 +01:00
committed by Rostislav Wolný
parent ddd2108109
commit a5db2564c8
2 changed files with 42 additions and 4 deletions

View File

@@ -248,10 +248,9 @@ export const getEmailTemplates = createRegistrySelector(
} )
// We still need to filter the templates because, in some cases, the API also returns custom templates
// ignoring the post_type filter in the query
?.filter(
( template ) =>
// @ts-expect-error Missing property in type
template.plugin === 'mailpoet'
?.filter( ( template ) =>
// @ts-expect-error Missing property in type
template.post_types.includes( 'mailpoet_email' )
)
);