From 3dd9e63881344e08ccf78cf0e314990d13bb3b20 Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Mon, 4 Aug 2025 10:34:25 +0100 Subject: [PATCH 01/25] New: init version of plugin feature with template parts --- includes/classes/BrandedEmails.php | 49 +++++++++++++++++++ includes/classes/Templates.php | 48 ++++++++++++++++++ orbit.php | 1 + .../branded-emails/email-template.php | 45 +++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 includes/classes/BrandedEmails.php create mode 100644 includes/classes/Templates.php create mode 100644 template-parts/branded-emails/email-template.php diff --git a/includes/classes/BrandedEmails.php b/includes/classes/BrandedEmails.php new file mode 100644 index 0000000..c307937 --- /dev/null +++ b/includes/classes/BrandedEmails.php @@ -0,0 +1,49 @@ + $args['message'], + ] + ); + + $styled_message = ob_get_clean(); + + $args['message'] = $styled_message; + + return $args; + } +} diff --git a/includes/classes/Templates.php b/includes/classes/Templates.php new file mode 100644 index 0000000..7cc2322 --- /dev/null +++ b/includes/classes/Templates.php @@ -0,0 +1,48 @@ +setup(); Security\HideVersion::instance()->setup(); Security\RemoveHeadLinks::instance()->setup(); + BrandedEmails::instance()->setup(); OtherFilters::instance()->setup(); HealthCheck::instance()->setup(); RemoteFiles::instance()->setup(); diff --git a/template-parts/branded-emails/email-template.php b/template-parts/branded-emails/email-template.php new file mode 100644 index 0000000..7ce78b4 --- /dev/null +++ b/template-parts/branded-emails/email-template.php @@ -0,0 +1,45 @@ + + + + + + + + +
+ + +
+ + From 4362651f5abd78d1deddfd0c41524a394a9a909e Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Mon, 4 Aug 2025 10:39:30 +0100 Subject: [PATCH 02/25] Fix: tried to use class as a trait --- includes/classes/BrandedEmails.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/classes/BrandedEmails.php b/includes/classes/BrandedEmails.php index c307937..bcde4b9 100644 --- a/includes/classes/BrandedEmails.php +++ b/includes/classes/BrandedEmails.php @@ -15,7 +15,6 @@ class BrandedEmails { use Environment; use Singleton; - use Templates; /** * Primary constructor From f8dab27a67f00222d47eb295212ee4697bbd47e8 Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Mon, 4 Aug 2025 11:09:26 +0100 Subject: [PATCH 03/25] New: add styles as separate file --- includes/classes/BrandedEmails.php | 6 +++ .../branded-emails/email-styles.php | 41 +++++++++++++++++++ .../branded-emails/email-template.php | 35 +++++----------- 3 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 template-parts/branded-emails/email-styles.php diff --git a/includes/classes/BrandedEmails.php b/includes/classes/BrandedEmails.php index bcde4b9..16a0ceb 100644 --- a/includes/classes/BrandedEmails.php +++ b/includes/classes/BrandedEmails.php @@ -29,6 +29,12 @@ public function setup() { add_filter( 'wp_mail', [ $this, 'apply_branded_email_template' ] ); } + /** + * Wraps the original email message in a branded HTML email template. + * + * @param array $args Array of arguments passed to wp_mail(). + * @return array Modified $args array with the email message wrapped in branded HTML. + */ public function apply_branded_email_template( $args ) { ob_start(); diff --git a/template-parts/branded-emails/email-styles.php b/template-parts/branded-emails/email-styles.php new file mode 100644 index 0000000..b1aa8ad --- /dev/null +++ b/template-parts/branded-emails/email-styles.php @@ -0,0 +1,41 @@ + + + diff --git a/template-parts/branded-emails/email-template.php b/template-parts/branded-emails/email-template.php index 7ce78b4..035e0fb 100644 --- a/template-parts/branded-emails/email-template.php +++ b/template-parts/branded-emails/email-template.php @@ -1,44 +1,31 @@ - + From 558fbc5ee14c4202b180dce00c69d7970bff41dc Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Mon, 4 Aug 2025 12:36:40 +0100 Subject: [PATCH 04/25] New: only apply template to non html emails, specific gf scenario --- includes/classes/BrandedEmails.php | 53 +++++++++++++++++++ .../branded-emails/email-template.php | 25 ++++----- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/includes/classes/BrandedEmails.php b/includes/classes/BrandedEmails.php index 16a0ceb..1f54da2 100644 --- a/includes/classes/BrandedEmails.php +++ b/includes/classes/BrandedEmails.php @@ -27,6 +27,7 @@ public function setup() { } add_filter( 'wp_mail', [ $this, 'apply_branded_email_template' ] ); + add_filter( 'gform_html_message_template_pre_send_email', [ $this, 'apply_branded_email_template_to_gf_notifications' ] ); } /** @@ -36,19 +37,71 @@ public function setup() { * @return array Modified $args array with the email message wrapped in branded HTML. */ public function apply_branded_email_template( $args ) { + $headers = []; + + // Convert headers to an array if they aren't already + if ( empty( $args['headers'] ) ) { + $headers = []; + } elseif ( is_string( $args['headers'] ) ) { + $headers = explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ); + } elseif ( is_array( $args['headers'] ) ) { + $headers = $args['headers']; + } + + // Check if Content-Type is already set to HTML + $content_type_is_html = false; + foreach ( $headers as $header ) { + if ( stripos( $header, 'Content-Type:' ) !== false && stripos( $header, 'text/html' ) !== false ) { + $content_type_is_html = true; + break; + } + } + + // If email is already HTML return original $args + if ( $content_type_is_html ) { + return $args; + } + ob_start(); Templates::include_template_part( 'branded-emails/email-template.php', [ 'email_content' => $args['message'], + 'email_subject' => isset( $args['subject'] ) ? $args['subject'] : '', ] ); $styled_message = ob_get_clean(); + // Remove existing Content-Type headers (at this point we've already established it's not HTML) + $headers = array_filter( $headers, function ( $header ) { + return stripos( $header, 'Content-Type:' ) === false; + } ); + + // Add HTML Content-Type + $headers[] = 'Content-Type: text/html; charset=UTF-8'; + + // Set updated headers and message + $args['headers'] = $headers; $args['message'] = $styled_message; return $args; } + + public function apply_branded_email_template_to_gf_notifications( $template ) { + ob_start(); + + Templates::include_template_part( + 'branded-emails/email-template.php', + [ + 'email_content' => '{message}', + 'email_subject' => '{subject}', + ] + ); + + $template = ob_get_clean(); + + return $template; + } } diff --git a/template-parts/branded-emails/email-template.php b/template-parts/branded-emails/email-template.php index 035e0fb..74f4c62 100644 --- a/template-parts/branded-emails/email-template.php +++ b/template-parts/branded-emails/email-template.php @@ -16,17 +16,18 @@ ?> - - - - - - + From 082551a5ae8ad935510655eff7989cefdfec2b88 Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Mon, 4 Aug 2025 12:50:56 +0100 Subject: [PATCH 05/25] New: add logo to template --- includes/classes/BrandedEmails.php | 2 +- template-parts/branded-emails/email-styles.php | 11 +++++++++++ .../branded-emails/email-template.php | 18 ++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/includes/classes/BrandedEmails.php b/includes/classes/BrandedEmails.php index 1f54da2..874a339 100644 --- a/includes/classes/BrandedEmails.php +++ b/includes/classes/BrandedEmails.php @@ -22,7 +22,7 @@ class BrandedEmails { * @return void */ public function setup() { - if ( apply_filters( 'orbit_disable_branded_emails', false ) ) { + if ( apply_filters( 'orbit_branded_emails_disable', false ) ) { return; } diff --git a/template-parts/branded-emails/email-styles.php b/template-parts/branded-emails/email-styles.php index b1aa8ad..1f30f7f 100644 --- a/template-parts/branded-emails/email-styles.php +++ b/template-parts/branded-emails/email-styles.php @@ -19,6 +19,7 @@ diff --git a/template-parts/branded-emails/email-template.php b/template-parts/branded-emails/email-template.php index c08731c..d930b2c 100644 --- a/template-parts/branded-emails/email-template.php +++ b/template-parts/branded-emails/email-template.php @@ -3,7 +3,8 @@ * Branded Email Template * This file can be overridden in your theme. * - * Available variables: + * @package Orbit + * * @var string $email_content */ @@ -14,7 +15,10 @@ } $header_logo = apply_filters( 'orbit_branded_emails_header_logo', '' ); +$email_content = $args['email_content'] ?? ''; +$email_subject = $args['email_subject'] ?? get_bloginfo( 'name', 'display' ); ?> + @@ -36,11 +40,11 @@ From 2407755c0312de2ae3fa902ab6add0f2bcbe46aa Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Mon, 4 Aug 2025 16:50:42 +0100 Subject: [PATCH 07/25] New: rename template functions and where they go in the theme --- includes/classes/BrandedEmails.php | 4 ++-- includes/classes/Templates.php | 11 +++++------ .../branded-emails/email-styles.php | 0 .../branded-emails/email-template.php | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) rename {template-parts => templates}/branded-emails/email-styles.php (100%) rename {template-parts => templates}/branded-emails/email-template.php (93%) diff --git a/includes/classes/BrandedEmails.php b/includes/classes/BrandedEmails.php index cf04405..0c3380e 100644 --- a/includes/classes/BrandedEmails.php +++ b/includes/classes/BrandedEmails.php @@ -64,7 +64,7 @@ public function apply_branded_email_template( $args ) { ob_start(); - Templates::include_template_part( + Templates::include_template( 'branded-emails/email-template.php', [ 'email_content' => $args['message'], @@ -104,7 +104,7 @@ function ( $header ) { public function apply_branded_email_template_to_gf_notifications( $template ) { ob_start(); - Templates::include_template_part( + Templates::include_template( 'branded-emails/email-template.php', [ 'email_content' => '{message}', diff --git a/includes/classes/Templates.php b/includes/classes/Templates.php index 6db2d52..6db3870 100644 --- a/includes/classes/Templates.php +++ b/includes/classes/Templates.php @@ -22,14 +22,14 @@ class Templates { * @param string $template_name The name of the template file. * @return string The path to the template file. */ - private static function get_template_part( $template_name ) { - $theme_template = get_stylesheet_directory() . '/template-parts/' . $template_name; + private static function get_template( $template_name ) { + $theme_template = get_theme_file_path( '//orbit//' . $template_name ); if ( file_exists( $theme_template ) ) : return $theme_template; endif; - return ORBIT_PATH . 'template-parts/' . $template_name; + return ORBIT_PATH . 'templates/' . $template_name; } /** @@ -38,9 +38,8 @@ private static function get_template_part( $template_name ) { * @param string $template_name The name of the template file. * @param array $args Optional. Associative array of variables to make available in the template. */ - public static function include_template_part( string $template_name, array $args = [] ) { - - $template_path = self::get_template_part( $template_name ); + public static function include_template( string $template_name, array $args = [] ) { + $template_path = self::get_template( $template_name ); if ( file_exists( $template_path ) ) { include $template_path; diff --git a/template-parts/branded-emails/email-styles.php b/templates/branded-emails/email-styles.php similarity index 100% rename from template-parts/branded-emails/email-styles.php rename to templates/branded-emails/email-styles.php diff --git a/template-parts/branded-emails/email-template.php b/templates/branded-emails/email-template.php similarity index 93% rename from template-parts/branded-emails/email-template.php rename to templates/branded-emails/email-template.php index d930b2c..860bb52 100644 --- a/template-parts/branded-emails/email-template.php +++ b/templates/branded-emails/email-template.php @@ -24,7 +24,7 @@ <?php echo esc_attr( $email_subject ); ?> - + From c658d3fdbdc371049ec8ede74b5e40f50bd64f65 Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Tue, 5 Aug 2025 11:46:36 +0100 Subject: [PATCH 08/25] New: bring template inline with WooCommerce base --- templates/branded-emails/email-styles.php | 215 ++++++++++++++++++-- templates/branded-emails/email-template.php | 114 ++++++++--- 2 files changed, 285 insertions(+), 44 deletions(-) diff --git a/templates/branded-emails/email-styles.php b/templates/branded-emails/email-styles.php index bf7c4ae..6e631e1 100644 --- a/templates/branded-emails/email-styles.php +++ b/templates/branded-emails/email-styles.php @@ -10,45 +10,218 @@ exit; // Exit if accessed directly. } -$background_color = apply_filters( 'orbit_branded_emails_background_color', '#f4f4f4' ); +$global_settings = wp_get_global_settings(); +$background_color = apply_filters( 'orbit_branded_emails_background_color', '#ffffff' ); $body_background_color = apply_filters( 'orbit_branded_emails_body_background_color', '#ffffff' ); -$body_border_color = apply_filters( 'orbit_branded_emails_body_border_color', '#ddd' ); -$body_max_width = apply_filters( 'orbit_branded_emails_body_max_width', '800px' ); -$body_text_color = apply_filters( 'orbit_branded_emails_body_text_color', '#000' ); -$footer_text_color = apply_filters( 'orbit_branded_emails_footer_text_color', '#999' ); +$body_border_color = apply_filters( 'orbit_branded_emails_body_border_color', $global_settings['custom']['color']['border'] ?? '#EDEFF1' ); +$body_text_color = apply_filters( 'orbit_branded_emails_body_text_color', $global_settings['color']['contrast'] ?? '#3F474D' ); +$link_color = apply_filters( 'orbit_branded_emails_link_color', $global_settings['custom']['color']['link'] ?? '#8549FF' ); +$footer_text_color = apply_filters( 'orbit_branded_emails_footer_text_color', $global_settings['color']['contrast'] ?? '#3F474D' ); +$font_family = '"Helvetica Neue", Helvetica, Roboto, Arial, sans-serif'; ?> diff --git a/templates/branded-emails/email-template.php b/templates/branded-emails/email-template.php index 860bb52..b5daeb2 100644 --- a/templates/branded-emails/email-template.php +++ b/templates/branded-emails/email-template.php @@ -15,37 +15,105 @@ } $header_logo = apply_filters( 'orbit_branded_emails_header_logo', '' ); +$site_name = get_bloginfo( 'name', 'display' ); $email_content = $args['email_content'] ?? ''; $email_subject = $args['email_subject'] ?? get_bloginfo( 'name', 'display' ); ?> - +> - + + <?php echo esc_attr( $email_subject ); ?> - - - + + + + + + + +
+
+ + + + + + + +
+ + + + +
+ ' . esc_attr( $site_name ) . '

'; + } else { + echo ''; + } + ?> +
+ + + + + + + +
+ + + + + +
+

+
+ +
+ + + + + +
+ + + + + +
+
+ +
+
+ +
+ +
+
+ + + + + + + +
+
+
From 4efc8a3d32184a22c3c17b8189cc5cb08ee1dd87 Mon Sep 17 00:00:00 2001 From: Dan Hudson Date: Thu, 7 Aug 2025 12:30:11 +0100 Subject: [PATCH 09/25] New: inline all the styles from within