MailPoet\EmailEditor\Engine\Templates

Templates::add_theme_templates()publicWC 1.0

This is need to enable saving post – template association. When a theme doesn't support block_templates feature the association is not saved, because templates registered via register_block_template are not added to the list of available templates. https://github.com/WordPress/wordpress-develop/blob/cdc2f255acce57372b849d6278c4156e1056c749/src/wp-includes/class-wp-theme.php#L1355

This function ensures that the email templates are in the list which is used for checking if the template can be saved in the association. See https://github.com/WordPress/wordpress-develop/blob/cdc2f255acce57372b849d6278c4156e1056c749/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1595-L1599

Method of the class: Templates{}

No Hooks.

Return

Array.

Usage

$Templates = new Templates();
$Templates->add_theme_templates( $templates, $theme, $post, $post_type );
$templates(array) (required)
The templates.
$theme(string) (required)
The theme.
$post(\WP_Post) (required)
The post.
$post_type(string) (required)
The post type.

Templates::add_theme_templates() code WC 9.8.1

public function add_theme_templates( $templates, $theme, $post, $post_type ) {
	if ( $post_type && ! in_array( $post_type, $this->post_types, true ) ) {
		return $templates;
	}
	$block_templates = get_block_templates();
	foreach ( $block_templates as $block_template ) {
		// Ideally we could check for supported post_types but there seems to be a bug and once a template has some edits and is stored in DB
		// the core returns null for post_types.
		if ( $block_template->plugin !== $this->template_prefix ) {
			continue;
		}
		$templates[ $block_template->slug ] = $block_template;
	}
	return $templates;
}