Automattic\WooCommerce\EmailEditor\Engine\Templates
Templates::add_theme_templates
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
Метод класса: Templates{}
Хуков нет.
Возвращает
Массив
.
Использование
$Templates = new Templates(); $Templates->add_theme_templates( $templates, $theme, $post, $post_type );
- $templates(массив) (обязательный)
- The templates.
- $theme(строка) (обязательный)
- The theme.
- $post(WP_Post) (обязательный)
- The post.
- $post_type(строка) (обязательный)
- The post type.
Код Templates::add_theme_templates() Templates::add theme templates WC 10.0.2
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(); $email_templates_slugs = array_map( function ( Template $template ) { return $template->get_slug(); }, $this->templates_registry->get_all() ); foreach ( $block_templates as $block_template ) { if ( ! in_array( $block_template->slug, $email_templates_slugs, true ) ) { continue; } if ( isset( $templates[ $block_template->slug ] ) ) { continue; } $templates[ $block_template->slug ] = $block_template->title; // Requires only the template title, not the full template object. } return $templates; }