1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
<?php namespace YayMail\Abstracts;
use YayMail\Models\TemplateModel; use YayMail\YayMailTemplate;
/** * Base Email Class */ abstract class BaseEmail {
/** * Contains id of the email * Id also means template name in some case * * @var string */ protected $id;
/** * Email name * * @var string */ protected $title;
/** * Contains recipient * * @var string */ protected $recipient;
/** * Which plugin email created by */ protected $source = [ 'plugin_id' => 'woocommerce', 'plugin_name' => 'WooCommerce', ];
protected $elements = [];
protected $shortcodes = [];
protected $root_email = null;
protected $is_existed = true;
/** * Example values: non_order, order, global_header_footer, ... */ public $email_types = [ YAYMAIL_WITH_ORDER_EMAILS ];
/** * Indicate which template that process is working on */ public $template = null;
/** * Render priority * * @var int */ protected $render_priority = YAYMAIL_EMAIL_RENDER_PRIORITY;
/** * Callback for yaymail_emails hook * Return this email data */ public function get_email_data() { return [ 'id' => $this->id, 'title' => $this->title, 'recipient' => $this->recipient, 'source' => $this->source, ]; }
abstract public function get_template_path();
abstract public function get_default_elements();
/** * Function check current template is WooCommerce email * Return boolean */ protected function is_template_email( \WC_Email $email ) { return ! empty( $email->id ) && $email->id === $this->id; }
public function get_language( $order ) { return ''; }
public function get_id() { return $this->id; }
public function get_template_file( $located, $template_name, $args ) { if ( ! isset( $args['email'] ) ) { return $located; } if ( ! $args['email'] instanceof \WC_Email || ! $this->is_template_email( $args['email'] ) ) { return $located; } $template_path = $this->get_template_path(); if ( ! file_exists( $template_path ) ) { return $located; }
$this->template = new YayMailTemplate( $this->id );
if ( ! $this->template->is_enabled() ) { return $located; }
return $template_path; }
public function get_title() { return $this->title ?? ''; }
public function get_recipient() { return $this->recipient ?? ''; }
public function get_source() { return $this->source; }
public function register_element( $element ) { if ( ! ( $element instanceof BaseElement ) ) { return; } $this->elements[] = $element; }
public function get_elements() { return $this->elements; }
public function register_shortcodes( $shortcodes ) { $this->shortcodes = array_merge( $this->shortcodes, $shortcodes ); }
public function get_shortcodes() { return $this->shortcodes; }
public function get_root_email() { return $this->root_email; }
public function is_existed() { return ! empty( $this->id ); }
public function maybe_disable_block_email_editor() { if ( ! \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'block_email_editor' ) ) { return; } if ( ! $this->root_email || ! $this->root_email instanceof \WC_Email ) { return; } $find_yaymail_template = TemplateModel::get_short_data_by_name( $this->id ); if ( ! empty( $find_yaymail_template ) && $find_yaymail_template['status'] === 'active' ) { $this->root_email->block_email_editor_enabled = false; } } }
|