mailpoet
/
vendor
/
woocommerce
/
email-editor
/
src
/
Engine
/
Templates
/
class-templates-registry.php
class-template.php
1 year ago
class-templates-registry.php
1 year ago
class-templates.php
4 months ago
email-general.html
7 months ago
index.php
1 year ago
single-email-post-template.php
1 year ago
class-templates-registry.php
40 lines
| 1 | <?php |
| 2 | declare(strict_types = 1); |
| 3 | namespace Automattic\WooCommerce\EmailEditor\Engine\Templates; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | class Templates_Registry { |
| 6 | private $templates = array(); |
| 7 | public function initialize(): void { |
| 8 | apply_filters( 'woocommerce_email_editor_register_templates', $this ); |
| 9 | } |
| 10 | public function register( Template $template ): void { |
| 11 | if ( ! \WP_Block_Templates_Registry::get_instance()->is_registered( $template->get_name() ) ) { |
| 12 | // skip registration if the template was already registered. |
| 13 | $result = register_block_template( |
| 14 | $template->get_name(), |
| 15 | array( |
| 16 | 'title' => $template->get_title(), |
| 17 | 'description' => $template->get_description(), |
| 18 | 'content' => $template->get_content(), |
| 19 | 'post_types' => $template->get_post_types(), |
| 20 | ) |
| 21 | ); |
| 22 | $this->templates[ $template->get_name() ] = $template; |
| 23 | } |
| 24 | } |
| 25 | public function get_by_name( string $name ): ?Template { |
| 26 | return $this->templates[ $name ] ?? null; |
| 27 | } |
| 28 | public function get_by_slug( string $slug ): ?Template { |
| 29 | foreach ( $this->templates as $template ) { |
| 30 | if ( $template->get_slug() === $slug ) { |
| 31 | return $template; |
| 32 | } |
| 33 | } |
| 34 | return null; |
| 35 | } |
| 36 | public function get_all() { |
| 37 | return $this->templates; |
| 38 | } |
| 39 | } |
| 40 |