PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.2
YayMail – WooCommerce Email Customizer v4.3.2
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
← All changes | src/Functions.php +29 -150 trunk4.3.2 View file →
@@ -4,11 +4,12 @@
4 4 use YayMail\Utils\TemplateHelpers;
5 5 use YayMail\Constants\TemplatesData;
6 6 use YayMail\Elements\ColumnLayout;
7 7 use YayMail\Elements\ElementsLoader;
8 +use YayMail\Integrations\TranslationModule;
8 9 use YayMail\YayMailEmails;
9 10 use YayMail\Utils\Logger;
10 -
11 +use YayMail\Utils\StyleInline;
11 12 if ( ! function_exists( 'yaymail_get_emails' ) ) {
12 13
13 14 /**
14 15 * Get all supported Emails
@@ -59,28 +60,12 @@
59 60 }//end if
60 61
61 62 if ( ! function_exists( 'yaymail_is_wc_installed' ) ) {
62 63 function yaymail_is_wc_installed() {
63 - if ( ! function_exists( 'WC' ) ) {
64 - return false;
65 - }
66 -
67 - $plugin_work = \YayMail\Utils\Helpers::get_plugin_work_info();
68 - return $plugin_work['yaymail'];
64 + return function_exists( 'WC' );
69 65 }
70 66 }
71 67
72 -if ( ! function_exists( 'yaymail_version' ) ) {
73 - function yaymail_version() {
74 - if ( defined( 'YAYMAIL_VERSION' ) ) {
75 - return YAYMAIL_VERSION;
76 - }
77 - return false;
78 - }
79 -}
80 -
81 -
82 -
83 68 if ( ! function_exists( 'yaymail_settings' ) ) {
84 69 function yaymail_settings() {
85 70 global $yaymail_unsaved_settings;
86 71 if ( ! empty( $yaymail_unsaved_settings ) ) {
@@ -112,11 +97,9 @@
112 97 }
113 98
114 99 // TODO: do later
115 100 ob_start();
116 - // nosemgrep: audit.php.lang.security.file.inclusion-arg
117 - include $path;
118 - // nosemgrep
101 + include $path; // nosemgrep
119 102 $html = ob_get_contents();
120 103 ob_end_clean();
121 104 return yaymail_kses_post( $html );
122 105 }
@@ -238,14 +221,8 @@
238 221 if ( ! $find_email ) {
239 222 return [];
240 223 }
241 224
242 - // Not passed as a get_data() argument: ColumnLayout::get_data( $amount, $attributes )
243 - // uses that same first/second position for its own params, so any element's
244 - // default color must read this out-of-band instead. Scoped to this one request.
245 - global $yaymail_current_email_id;
246 - $yaymail_current_email_id = $email_id;
247 -
248 225 $all_elements = yaymail_get_all_elements();
249 226 $result = [];
250 227
251 228 foreach ( $all_elements as $element ) {
@@ -296,60 +273,8 @@
296 273 return $element;
297 274 }
298 275 }//end if
299 276
300 -if ( ! function_exists( 'yaymail_get_default_brand_color' ) ) {
301 -
302 - /**
303 - * Default accent color for newly dragged elements (Heading background, Button
304 - * background, etc.), matching the frontend's brand color per platform
305 - * (constants/theme.ts WP_COLORS vs YAYMAIL_TOKENS.color.wcPurple).
306 - *
307 - * Element get_data() methods share BaseElement's abstract contract, but
308 - * ColumnLayout::get_data( $amount, $attributes ) repurposes that same
309 - * position for a non-attributes param -- so the email/template id can't be
310 - * threaded through as a get_data() argument without breaking it. Falls back
311 - * to the id yaymail_get_email_elements_data() stashed for the current request.
312 - *
313 - * @param string|null $email_id Email/template id to check; defaults to the
314 - * current request's when omitted.
315 - * @return string Hex color.
316 - */
317 - function yaymail_get_default_brand_color( $email_id = null ) {
318 - if ( null === $email_id ) {
319 - global $yaymail_current_email_id;
320 - $email_id = $yaymail_current_email_id;
321 - }
322 - $email_id = (string) $email_id;
323 -
324 - $is_wp_template = 0 === strpos( $email_id, 'wp-core-' ) || 'wp_global_header_footer' === $email_id;
325 -
326 - return $is_wp_template ? YAYMAIL_COLOR_WP_DEFAULT : YAYMAIL_COLOR_WC_DEFAULT;
327 - }
328 -}
329 -
330 -if ( ! function_exists( 'yaymail_get_ghf_disallowed_element_types' ) ) {
331 -
332 - /**
333 - * Element types that cannot be used in global header/footer.
334 - * Derived from the same availability rules as the GHF customizer sidebar.
335 - *
336 - * @return string[]
337 - */
338 - function yaymail_get_ghf_disallowed_element_types() {
339 - $elements = yaymail_get_email_elements_data( 'yaymail_global_header_footer' );
340 -
341 - $disallowed = [];
342 - foreach ( $elements as $element ) {
343 - if ( empty( $element['available'] ) && ! empty( $element['type'] ) ) {
344 - $disallowed[] = $element['type'];
345 - }
346 - }
347 -
348 - return array_values( array_unique( $disallowed ) );
349 - }
350 -}//end if
351 -
352 277 if ( ! function_exists( 'yaymail_get_element' ) ) {
353 278
354 279 /**
355 280 * Get element by given type
@@ -405,31 +330,8 @@
405 330 $logger->log_exception_message( new \Exception( $message ), $log_type, $additional_data );
406 331 }
407 332 }
408 333
409 -if ( ! function_exists( 'yaymail_get_attachment_image_url' ) ) {
410 -
411 - /**
412 - * Safely resolve an attachment image URL.
413 - *
414 - * Returns '' for an empty id or a dangling/deleted attachment (where
415 - * wp_get_attachment_image_src() returns false). Never throws, so a missing
416 - * image degrades gracefully instead of breaking the request that triggered
417 - * rendering (e.g. WooCommerce checkout).
418 - *
419 - * @param int|string $image_id Attachment ID.
420 - * @param string $size Registered image size.
421 - * @return string Image URL or '' when unavailable.
422 - */
423 - function yaymail_get_attachment_image_url( $image_id, $size = 'full' ) {
424 - if ( empty( $image_id ) ) {
425 - return '';
426 - }
427 - $image = wp_get_attachment_image_src( $image_id, $size );
428 - return ( is_array( $image ) && ! empty( $image[0] ) ) ? $image[0] : '';
429 - }
430 -}//end if
431 -
432 334 if ( ! function_exists( 'yaymail_get_wc_email_settings' ) ) {
433 335 /**
434 336 * Get WooCommerce email settings
435 337 *
@@ -470,57 +372,34 @@
470 372 * @since 4.0.3
471 373 *
472 374 * @return string
473 375 */
474 -if ( ! function_exists( 'yaymail_get_email_recipient_zone' ) ) {
475 - function yaymail_get_email_recipient_zone( $email ) {
476 - $is_customer_email = $email instanceof \WC_Email && method_exists( $email, 'is_customer_email' ) ? $email->is_customer_email() : true;
477 - if ( $is_customer_email ) {
478 - return __( 'Customer', 'woocommerce' );
479 - }
376 +function yaymail_get_email_recipient_zone( $email ) {
377 + $is_customer_email = $email instanceof \WC_Email && method_exists( $email, 'is_customer_email' ) ? $email->is_customer_email() : true;
378 + if ( $is_customer_email ) {
379 + return __( 'Customer', 'woocommerce' );
380 + }
480 381
481 - $recipient = '';
482 - if ( $email instanceof \WC_Email ) {
483 - $recipient = ! empty( $email->recipient ) ? $email->recipient : $email->get_recipient();
484 - if ( empty( $recipient ) ) {
485 - $recipient = __( 'Recipient', 'yaymail' );
486 - }
382 + $recipient = '';
383 + if ( $email instanceof \WC_Email ) {
384 + $recipient = ! empty( $email->recipient ) ? $email->recipient : $email->get_recipient();
385 + if ( empty( $recipient ) ) {
386 + $recipient = __( 'Recipient', 'yaymail' );
487 387 }
488 -
489 - $recipients = array_map(
490 - function( $email_recipient ) {
491 - $recipient_user = get_user_by( 'email', $email_recipient );
492 - if ( $recipient_user && user_can( $recipient_user, 'manage_options' ) ) {
493 - return __( 'Admin', 'woocommerce' );
494 - }
495 - if ( empty( $email_recipient ) ) {
496 - return __( 'Recipient', 'yaymail' );
497 - }
498 - return $email_recipient;
499 - },
500 - explode( ',', $recipient )
501 - );
502 - $recipients = array_unique( $recipients );
503 - return implode( ', ', $recipients );
504 388 }
505 -}//end if
506 389
507 -if ( ! function_exists( 'yaymail_get_template' ) ) {
508 - function yaymail_get_template( $template_name, $template_path = '', $default_path = '' ) {
509 - if ( ! $template_path ) {
510 - $template_path = 'yaymail';
511 - }
512 -
513 - $template = locate_template(
514 - [
515 - trailingslashit( $template_path ) . $template_name,
516 - $template_name,
517 - ]
518 - );
519 -
520 - if ( ! $template ) {
521 - $template = $default_path . $template_name;
522 - }
523 -
524 - return $template;
525 - }
390 + $recipients = array_map(
391 + function( $email_recipient ) {
392 + $recipient_user = get_user_by( 'email', $email_recipient );
393 + if ( $recipient_user && user_can( $recipient_user, 'manage_options' ) ) {
394 + return __( 'Admin', 'woocommerce' );
395 + }
396 + if ( empty( $email_recipient ) ) {
397 + return __( 'Recipient', 'yaymail' );
398 + }
399 + return $email_recipient;
400 + },
401 + explode( ',', $recipient )
402 + );
403 + $recipients = array_unique( $recipients );
404 + return implode( ', ', $recipients );
526 405 }