PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Abstracts / BaseEmail.php

BaseEmail.php in YayMail – WooCommerce Email Customizer trunk, at src/Abstracts/BaseEmail.php

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