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/Functions.php +96 -24 4.4.1 → 4.4.5 View file →
@@ -68,17 +68,27 @@
68 68 return $plugin_work['yaymail'];
69 69 }
70 70 }
71 71
72 -if ( ! function_exists( 'yaymail_is_wp_mail_installed' ) ) {
73 - function yaymail_is_wp_mail_installed() {
74 - return defined( 'YAYMAIL_WP_VERSION' );
72 +if ( ! function_exists( 'yaymail_sanitize_template_variant' ) ) {
73 + /**
74 + * Variant slugs are stored as post meta and used as lookup keys, so only [a-z0-9_-] survives.
75 + * Anything else (including null) means the default design.
76 + */
77 + function yaymail_sanitize_template_variant( $variant ) {
78 + if ( ! is_string( $variant ) ) {
79 + return '';
80 + }
81 + return preg_match( '/^[a-z0-9_-]{1,40}$/', $variant ) ? $variant : '';
75 82 }
76 83 }
77 84
78 85 if ( ! function_exists( 'yaymail_version' ) ) {
79 86 function yaymail_version() {
80 - return yaymail_is_wp_mail_installed() ? YAYMAIL_WP_VERSION : YAYMAIL_VERSION;
87 + if ( defined( 'YAYMAIL_VERSION' ) ) {
88 + return YAYMAIL_VERSION;
89 + }
90 + return false;
81 91 }
82 92 }
83 93
84 94
@@ -115,8 +125,9 @@
115 125 }
116 126
117 127 // TODO: do later
118 128 ob_start();
129 + // nosemgrep: audit.php.lang.security.file.inclusion-arg
119 130 include $path;
120 131 // nosemgrep
121 132 $html = ob_get_contents();
122 133 ob_end_clean();
@@ -204,28 +215,8 @@
204 215 return ElementsLoader::get_instance()->get_all();
205 216 }
206 217 }
207 218
208 -if ( ! function_exists( 'yaymail_get_email_available_elements' ) ) {
209 -
210 - /**
211 - * Get all available elements of given email
212 - *
213 - * @param string $email_id
214 - *
215 - * @return BaseElement[]
216 - */
217 - function yaymail_get_email_available_elements( $email_id ) {
218 - $find_email = yaymail_get_email( $email_id );
219 -
220 - if ( ! $find_email ) {
221 - return [];
222 - }
223 -
224 - return $find_email->get_elements();
225 - }
226 -}
227 -
228 219 if ( ! function_exists( 'yaymail_get_email_elements_data' ) ) {
229 220
230 221 /**
231 222 * Get all elements data of given email
@@ -240,8 +231,14 @@
240 231 if ( ! $find_email ) {
241 232 return [];
242 233 }
243 234
235 + // Not passed as a get_data() argument: ColumnLayout::get_data( $amount, $attributes )
236 + // uses that same first/second position for its own params, so any element's
237 + // default color must read this out-of-band instead. Scoped to this one request.
238 + global $yaymail_current_email_id;
239 + $yaymail_current_email_id = $email_id;
240 +
244 241 $all_elements = yaymail_get_all_elements();
245 242 $result = [];
246 243
247 244 foreach ( $all_elements as $element ) {
@@ -292,8 +289,60 @@
292 289 return $element;
293 290 }
294 291 }//end if
295 292
293 +if ( ! function_exists( 'yaymail_get_default_brand_color' ) ) {
294 +
295 + /**
296 + * Default accent color for newly dragged elements (Heading background, Button
297 + * background, etc.), matching the frontend's brand color per platform
298 + * (constants/theme.ts WP_COLORS vs YAYMAIL_TOKENS.color.wcPurple).
299 + *
300 + * Element get_data() methods share BaseElement's abstract contract, but
301 + * ColumnLayout::get_data( $amount, $attributes ) repurposes that same
302 + * position for a non-attributes param -- so the email/template id can't be
303 + * threaded through as a get_data() argument without breaking it. Falls back
304 + * to the id yaymail_get_email_elements_data() stashed for the current request.
305 + *
306 + * @param string|null $email_id Email/template id to check; defaults to the
307 + * current request's when omitted.
308 + * @return string Hex color.
309 + */
310 + function yaymail_get_default_brand_color( $email_id = null ) {
311 + if ( null === $email_id ) {
312 + global $yaymail_current_email_id;
313 + $email_id = $yaymail_current_email_id;
314 + }
315 + $email_id = (string) $email_id;
316 +
317 + $is_wp_template = 0 === strpos( $email_id, 'wp-core-' ) || 'wp_global_header_footer' === $email_id;
318 +
319 + return $is_wp_template ? YAYMAIL_COLOR_WP_DEFAULT : YAYMAIL_COLOR_WC_DEFAULT;
320 + }
321 +}
322 +
323 +if ( ! function_exists( 'yaymail_get_ghf_disallowed_element_types' ) ) {
324 +
325 + /**
326 + * Element types that cannot be used in global header/footer.
327 + * Derived from the same availability rules as the GHF customizer sidebar.
328 + *
329 + * @return string[]
330 + */
331 + function yaymail_get_ghf_disallowed_element_types() {
332 + $elements = yaymail_get_email_elements_data( 'yaymail_global_header_footer' );
333 +
334 + $disallowed = [];
335 + foreach ( $elements as $element ) {
336 + if ( empty( $element['available'] ) && ! empty( $element['type'] ) ) {
337 + $disallowed[] = $element['type'];
338 + }
339 + }
340 +
341 + return array_values( array_unique( $disallowed ) );
342 + }
343 +}//end if
344 +
296 345 if ( ! function_exists( 'yaymail_get_element' ) ) {
297 346
298 347 /**
299 348 * Get element by given type
@@ -348,8 +397,31 @@
348 397 $logger = new Logger();
349 398 $logger->log_exception_message( new \Exception( $message ), $log_type, $additional_data );
350 399 }
351 400 }
401 +
402 +if ( ! function_exists( 'yaymail_get_attachment_image_url' ) ) {
403 +
404 + /**
405 + * Safely resolve an attachment image URL.
406 + *
407 + * Returns '' for an empty id or a dangling/deleted attachment (where
408 + * wp_get_attachment_image_src() returns false). Never throws, so a missing
409 + * image degrades gracefully instead of breaking the request that triggered
410 + * rendering (e.g. WooCommerce checkout).
411 + *
412 + * @param int|string $image_id Attachment ID.
413 + * @param string $size Registered image size.
414 + * @return string Image URL or '' when unavailable.
415 + */
416 + function yaymail_get_attachment_image_url( $image_id, $size = 'full' ) {
417 + if ( empty( $image_id ) ) {
418 + return '';
419 + }
420 + $image = wp_get_attachment_image_src( $image_id, $size );
421 + return ( is_array( $image ) && ! empty( $image[0] ) ) ? $image[0] : '';
422 + }
423 +}//end if
352 424
353 425 if ( ! function_exists( 'yaymail_get_wc_email_settings' ) ) {
354 426 /**
355 427 * Get WooCommerce email settings