PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.3
YayMail – WooCommerce Email Customizer v4.3.3
4.4.7 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 All 58 releases
← All changes | src/Utils/TemplateHelpers.php +0 -235 4.4.6 → 4.3.3 View file →
@@ -3,10 +3,8 @@
3 3 namespace YayMail\Utils;
4 4
5 5 use YayMail\Constants\AttributesData;
6 6 use YayMail\Constants\TemplatesData;
7 -use YayMail\Shortcodes\ShortcodesExecutor;
8 -use YayMail\YayMailTemplate;
9 7
10 8 defined( 'ABSPATH' ) || exit;
11 9
12 10 /**
@@ -69,61 +67,8 @@
69 67 $unit
70 68 );
71 69 }
72 70
73 - /**
74 - * Inner border radius for column_layout children: only the four outer corners of the row
75 - * (first column left, last column right; single column gets all four).
76 - *
77 - * @param array $inner_border_radius Keys top_left, top_right, bottom_left, bottom_right.
78 - * @param int $total_columns amount_of_columns from parent column_layout.
79 - * @param int $column_index Zero-based column index.
80 - * @return array{top_left:int,top_right:int,bottom_right:int,bottom_left:int}
81 - */
82 - public static function get_inner_column_border_radius( $inner_border_radius, $total_columns, $column_index ) {
83 - $tl = isset( $inner_border_radius['top_left'] ) ? (int) $inner_border_radius['top_left'] : 0;
84 - $tr = isset( $inner_border_radius['top_right'] ) ? (int) $inner_border_radius['top_right'] : 0;
85 - $br = isset( $inner_border_radius['bottom_right'] ) ? (int) $inner_border_radius['bottom_right'] : 0;
86 - $bl = isset( $inner_border_radius['bottom_left'] ) ? (int) $inner_border_radius['bottom_left'] : 0;
87 -
88 - $total_columns = max( 1, (int) $total_columns );
89 - $column_index = max( 0, (int) $column_index );
90 -
91 - if ( 1 === $total_columns ) {
92 - return [
93 - 'top_left' => $tl,
94 - 'top_right' => $tr,
95 - 'bottom_right' => $br,
96 - 'bottom_left' => $bl,
97 - ];
98 - }
99 -
100 - if ( 0 === $column_index ) {
101 - return [
102 - 'top_left' => $tl,
103 - 'top_right' => 0,
104 - 'bottom_right' => 0,
105 - 'bottom_left' => $bl,
106 - ];
107 - }
108 -
109 - if ( $column_index === $total_columns - 1 ) {
110 - return [
111 - 'top_left' => 0,
112 - 'top_right' => $tr,
113 - 'bottom_right' => $br,
114 - 'bottom_left' => 0,
115 - ];
116 - }
117 -
118 - return [
119 - 'top_left' => 0,
120 - 'top_right' => 0,
121 - 'bottom_right' => 0,
122 - 'bottom_left' => 0,
123 - ];
124 - }
125 -
126 71 public static function get_dimension_value( $dimension, $unit = 'px' ) {
127 72 $unit = esc_attr( $unit );
128 73 $dimension = floatval( $dimension );
129 74 return "$dimension$unit";
@@ -415,186 +360,6 @@
415 360 }
416 361 }
417 362
418 363 return $elements;
419 - }
420 -
421 - public static function replace_color_paths( $value ) {
422 - return $value;
423 - }
424 -
425 - /**
426 - * Ensure each nested element has parentId pointing to its direct parent.
427 - * Root-level elements have no parentId (customizer "Select parent" relies on this).
428 - *
429 - * @param array $elements Template elements tree.
430 - * @param string|null $parent_id Parent element id for direct children.
431 - * @return array
432 - */
433 - public static function normalize_elements_parent_ids( $elements, $parent_id = null ) {
434 - if ( ! is_array( $elements ) ) {
435 - return [];
436 - }
437 -
438 - $normalized = [];
439 -
440 - foreach ( $elements as $element ) {
441 - if ( ! is_array( $element ) ) {
442 - continue;
443 - }
444 -
445 - if ( null !== $parent_id && '' !== $parent_id ) {
446 - $element['parentId'] = $parent_id;
447 - } else {
448 - unset( $element['parentId'] );
449 - }
450 -
451 - if ( ! empty( $element['children'] ) && is_array( $element['children'] ) ) {
452 - $child_parent_id = isset( $element['id'] ) ? $element['id'] : null;
453 - $element['children'] = self::normalize_elements_parent_ids( $element['children'], $child_parent_id );
454 - }
455 -
456 - $normalized[] = $element;
457 - }
458 -
459 - return $normalized;
460 - }
461 -
462 - /**
463 - * Append invisible characters so inbox clients do not pull body text into the preview line.
464 - *
465 - * @param string $preheader Visible preheader text.
466 - * @param int $target_length Approximate preview window (Gmail ~90–140, Outlook ~130).
467 - * @return string
468 - */
469 - public static function pad_preheader( $preheader, $target_length = 150 ) {
470 - $preheader = trim( (string) $preheader );
471 -
472 - if ( '' === $preheader ) {
473 - return '';
474 - }
475 -
476 - /**
477 - * Filter the target length for invisible preheader padding.
478 - *
479 - * @param int $target_length Default padding target length.
480 - * @param string $preheader Visible preheader text.
481 - */
482 - $target_length = (int) apply_filters( 'yaymail_email_preheader_pad_length', $target_length, $preheader );
483 -
484 - if ( $target_length <= 0 ) {
485 - return $preheader;
486 - }
487 -
488 - $visible_length = mb_strlen( $preheader );
489 -
490 - if ( $visible_length >= $target_length ) {
491 - return $preheader;
492 - }
493 -
494 - // Litmus preview-text hack: zero-width non-joiner + non-breaking space.
495 - $pad_unit = "\u{200C}\u{00A0}";
496 -
497 - return $preheader . str_repeat( $pad_unit, $target_length - $visible_length );
498 - }
499 -
500 - /**
501 - * Process preheader text (YayMail shortcodes).
502 - *
503 - * @param string $preheader Raw preheader from template meta.
504 - * @param YayMailTemplate $template Email template.
505 - * @param array $render_data Render context.
506 - * @return string Plain-text preheader for inbox preview.
507 - */
508 - public static function process_email_preheader( $preheader, $template, $args = [] ) {
509 - $preheader = trim( (string) $preheader );
510 -
511 - if ( '' === $preheader || ! $template instanceof YayMailTemplate ) {
512 - return '';
513 - }
514 -
515 - $template_name = $template->get_name();
516 -
517 - if ( false !== strpos( $preheader, '[' ) && $template_name ) {
518 -
519 - $shortcodes = yaymail_get_email_shortcodes( $template_name );
520 - new ShortcodesExecutor( $shortcodes, $args );
521 - $preheader = do_shortcode( $preheader );
522 - }//end if
523 -
524 - $preheader = self::pad_preheader( wp_strip_all_tags( $preheader ) );
525 -
526 - return $preheader;
527 - }
528 -
529 - /**
530 - * Render YayMail shortcodes inside an email subject at send time.
531 - *
532 - * Twin of process_email_preheader: registers the template shortcodes with the
533 - * given render context, then resolves them. Output is forced to a single
534 - * plain-text line because subjects must not contain HTML/markup that some
535 - * shortcodes (e.g. order details) emit.
536 - *
537 - * @param string $subject Raw subject after WooCommerce format_string().
538 - * @param YayMailTemplate $template Email template.
539 - * @param array $args Shortcode executor data (template, render_data, settings, ...).
540 - * @return string Subject with YayMail shortcodes resolved.
541 - */
542 - public static function process_email_subject( $subject, $template, $args = [] ) {
543 - $subject = (string) $subject;
544 -
545 - // Cheap guard: nothing to resolve when there is no shortcode marker.
546 - if ( '' === $subject || false === strpos( $subject, '[' ) || ! $template instanceof YayMailTemplate ) {
547 - return $subject;
548 - }
549 -
550 - $template_name = $template->get_name();
551 - if ( ! $template_name ) {
552 - return $subject;
553 - }
554 -
555 - $shortcodes = yaymail_get_email_shortcodes( $template_name );
556 - new ShortcodesExecutor( $shortcodes, $args );
557 -
558 - // $remove_breaks = true collapses newlines so multi-line shortcode output stays a single subject line.
559 - $subject = trim( wp_strip_all_tags( do_shortcode( $subject ), true ) );
560 -
561 - // Extension point: no shortcode restriction by default; lets integrators trim length,
562 - // blank structural shortcodes, etc. $args carries template + render_data (incl. order).
563 - return apply_filters( 'yaymail_email_subject', $subject, $template, $args );
564 - }
565 -
566 - /**
567 - * Output hidden preheader row at the top of the email body (Woo block-editor style).
568 - *
569 - * @param YayMailTemplate $template Email template.
570 - * @param array $args Render context.
571 - */
572 - public static function render_email_preheader( $template, $args = [] ) {
573 - if ( ! $template instanceof YayMailTemplate ) {
574 - return;
575 - }
576 -
577 - $template_name = $template->get_name();
578 -
579 - if ( str_starts_with( $template_name, 'pattern_' ) || in_array( $template_name, TemplatesData::GLOBAL_HEADER_FOOTER_TEMPLATE_IDS, true ) ) {
580 - return;
581 - }
582 -
583 - $preheader = self::process_email_preheader( $template->get_preheader(), $template, $args );
584 -
585 - if ( '' === $preheader ) {
586 - return;
587 - }
588 -
589 - $preheader_html = yaymail_get_content(
590 - 'templates/emails/email-preheader.php',
591 - [
592 - 'preheader' => $preheader,
593 - ]
594 - );
595 -
596 - if ( '' !== $preheader_html ) {
597 - yaymail_kses_post_e( $preheader_html );
598 - }
599 364 }
600 365 }