PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.5
YayMail – WooCommerce Email Customizer v4.4.5
4.4.6 4.4.5 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 All 57 releases
← All changes | src/Abstracts/BaseEmail.php +25 -18 4.4.3 → 4.4.5 View file →
@@ -38,10 +38,8 @@
38 38 'plugin_id' => 'woocommerce',
39 39 'plugin_name' => 'WooCommerce',
40 40 ];
41 41
42 - protected $elements = [];
43 -
44 42 protected $shortcodes = [];
45 43
46 44 protected $root_email = null;
47 45
@@ -108,15 +106,35 @@
108 106 if ( ! file_exists( $template_path ) ) {
109 107 return $located;
110 108 }
111 109
112 - $this->template = new YayMailTemplate( $this->id );
110 + return $this->load_template( $args ) ? $template_path : $located;
111 + }
113 112
113 + /**
114 + * Resolve the variant and load the YayMail template into $this->template.
115 + * The default design decides whether YayMail renders this email at all;
116 + * a variant only swaps the design when an addon returns one via `yaymail_email_get_variant`.
117 + *
118 + * @param array $args wc_get_template args.
119 + * @param string|null $template_name Template to load; defaults to this email's id.
120 + * @return bool True when a YayMail template should render.
121 + */
122 + protected function load_template( $args, $template_name = null ) {
123 + $template_name = $template_name ?? $this->id;
124 + $order = isset( $args['order'] ) ? $args['order'] : null;
125 +
126 + $this->template = new YayMailTemplate( $template_name );
114 127 if ( ! $this->template->is_enabled() ) {
115 - return $located;
128 + return false;
116 129 }
117 130
118 - return $template_path;
131 + $variant = yaymail_sanitize_template_variant( apply_filters( 'yaymail_email_get_variant', '', $order, $args, $this, $template_name ) );
132 + if ( '' !== $variant ) {
133 + $this->template = new YayMailTemplate( $template_name, '', $variant );
134 + }
135 +
136 + return true;
119 137 }
120 138
121 139 public function get_title() {
122 140 return $this->title ?? '';
@@ -129,19 +147,8 @@
129 147 public function get_source() {
130 148 return $this->source;
131 149 }
132 150
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 151 public function register_shortcodes( $shortcodes ) {
145 152 $this->shortcodes = array_merge( $this->shortcodes, $shortcodes );
146 153 }
147 154
@@ -163,10 +170,10 @@
163 170 }
164 171 if ( ! $this->root_email || ! $this->root_email instanceof \WC_Email ) {
165 172 return;
166 173 }
167 - $find_yaymail_template = TemplateModel::get_short_data_by_name( $this->id );
168 - if ( ! empty( $find_yaymail_template ) && $find_yaymail_template['status'] === 'active' ) {
174 + // One batched lookup shared by all emails instead of a per-email query at init.
175 + if ( in_array( $this->id, TemplateModel::get_active_default_template_names(), true ) ) {
169 176 $this->root_email->block_email_editor_enabled = false;
170 177 }
171 178 }
172 179 }