PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.3
YayMail – WooCommerce Email Customizer v4.3.3
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 +49 -163 4.4.6 → 4.3.3 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,41 +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_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 : '';
82 - }
83 -}
84 -
85 -if ( ! function_exists( 'yaymail_version' ) ) {
86 - function yaymail_version() {
87 - if ( defined( 'YAYMAIL_VERSION' ) ) {
88 - return YAYMAIL_VERSION;
89 - }
90 - return false;
91 - }
92 -}
93 -
94 -
95 -
96 68 if ( ! function_exists( 'yaymail_settings' ) ) {
97 69 function yaymail_settings() {
98 70 global $yaymail_unsaved_settings;
99 71 if ( ! empty( $yaymail_unsaved_settings ) ) {
@@ -125,11 +97,9 @@
125 97 }
126 98
127 99 // TODO: do later
128 100 ob_start();
129 - // nosemgrep: audit.php.lang.security.file.inclusion-arg
130 - include $path;
131 - // nosemgrep
101 + include $path; // nosemgrep
132 102 $html = ob_get_contents();
133 103 ob_end_clean();
134 104 return yaymail_kses_post( $html );
135 105 }
@@ -215,8 +185,28 @@
215 185 return ElementsLoader::get_instance()->get_all();
216 186 }
217 187 }
218 188
189 +if ( ! function_exists( 'yaymail_get_email_available_elements' ) ) {
190 +
191 + /**
192 + * Get all available elements of given email
193 + *
194 + * @param string $email_id
195 + *
196 + * @return BaseElement[]
197 + */
198 + function yaymail_get_email_available_elements( $email_id ) {
199 + $find_email = yaymail_get_email( $email_id );
200 +
201 + if ( ! $find_email ) {
202 + return [];
203 + }
204 +
205 + return $find_email->get_elements();
206 + }
207 +}
208 +
219 209 if ( ! function_exists( 'yaymail_get_email_elements_data' ) ) {
220 210
221 211 /**
222 212 * Get all elements data of given email
@@ -231,14 +221,8 @@
231 221 if ( ! $find_email ) {
232 222 return [];
233 223 }
234 224
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 -
241 225 $all_elements = yaymail_get_all_elements();
242 226 $result = [];
243 227
244 228 foreach ( $all_elements as $element ) {
@@ -289,60 +273,8 @@
289 273 return $element;
290 274 }
291 275 }//end if
292 276
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 -
345 277 if ( ! function_exists( 'yaymail_get_element' ) ) {
346 278
347 279 /**
348 280 * Get element by given type
@@ -398,31 +330,8 @@
398 330 $logger->log_exception_message( new \Exception( $message ), $log_type, $additional_data );
399 331 }
400 332 }
401 333
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
424 -
425 334 if ( ! function_exists( 'yaymail_get_wc_email_settings' ) ) {
426 335 /**
427 336 * Get WooCommerce email settings
428 337 *
@@ -463,57 +372,34 @@
463 372 * @since 4.0.3
464 373 *
465 374 * @return string
466 375 */
467 -if ( ! function_exists( 'yaymail_get_email_recipient_zone' ) ) {
468 - function yaymail_get_email_recipient_zone( $email ) {
469 - $is_customer_email = $email instanceof \WC_Email && method_exists( $email, 'is_customer_email' ) ? $email->is_customer_email() : true;
470 - if ( $is_customer_email ) {
471 - return __( 'Customer', 'woocommerce' );
472 - }
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 + }
473 381
474 - $recipient = '';
475 - if ( $email instanceof \WC_Email ) {
476 - $recipient = ! empty( $email->recipient ) ? $email->recipient : $email->get_recipient();
477 - if ( empty( $recipient ) ) {
478 - $recipient = __( 'Recipient', 'yaymail' );
479 - }
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' );
480 387 }
481 -
482 - $recipients = array_map(
483 - function( $email_recipient ) {
484 - $recipient_user = get_user_by( 'email', $email_recipient );
485 - if ( $recipient_user && user_can( $recipient_user, 'manage_options' ) ) {
486 - return __( 'Admin', 'woocommerce' );
487 - }
488 - if ( empty( $email_recipient ) ) {
489 - return __( 'Recipient', 'yaymail' );
490 - }
491 - return $email_recipient;
492 - },
493 - explode( ',', $recipient )
494 - );
495 - $recipients = array_unique( $recipients );
496 - return implode( ', ', $recipients );
497 388 }
498 -}//end if
499 389
500 -if ( ! function_exists( 'yaymail_get_template' ) ) {
501 - function yaymail_get_template( $template_name, $template_path = '', $default_path = '' ) {
502 - if ( ! $template_path ) {
503 - $template_path = 'yaymail';
504 - }
505 -
506 - $template = locate_template(
507 - [
508 - trailingslashit( $template_path ) . $template_name,
509 - $template_name,
510 - ]
511 - );
512 -
513 - if ( ! $template ) {
514 - $template = $default_path . $template_name;
515 - }
516 -
517 - return $template;
518 - }
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 );
519 405 }