Jake Vanderwerf
2026-02-17 a24a06002081ad71a78ffeff9072725ba39cf121
inc/managers/EmailManager.php
@@ -45,23 +45,23 @@
        add_filter('wp_mail_content_type', [$this, 'setHtmlContentType']);
        // User registration emails
        add_filter('wp_new_user_notification_email', [$this, 'customizeNewUserEmail'], 10, 3);
        add_filter('wp_new_user_notification_email_admin', [$this, 'customizeNewUserEmailAdmin'], 10, 3);
        add_filter('wp_new_user_notification_email', [$this, 'customizeNewUserEmail'], 999, 3);
        add_filter('wp_new_user_notification_email_admin', [$this, 'customizeNewUserEmailAdmin'], 999, 3);
        // Password reset emails
        add_filter('retrieve_password_message', [$this, 'customizePasswordResetEmail'], 10, 4);
        add_filter('retrieve_password_title', [$this, 'customizePasswordResetTitle'], 10, 3);
        add_filter('retrieve_password_message', [$this, 'customizePasswordResetEmail'], 999, 4);
        add_filter('retrieve_password_title', [$this, 'customizePasswordResetTitle'], 999, 3);
        // User email change emails
        add_filter('email_change_email', [$this, 'customizeEmailChangeEmail'], 10, 3);
        add_filter('new_user_email_content', [$this, 'customizeNewUserEmailContent'], 10, 2);
        add_filter('email_change_email', [$this, 'customizeEmailChangeEmail'], 999, 3);
        add_filter('new_user_email_content', [$this, 'customizeNewUserEmailContent'], 999, 2);
        // Password change notification
        add_filter('password_change_email', [$this, 'customizePasswordChangeEmail'], 10, 3);
        add_filter('password_change_email', [$this, 'customizePasswordChangeEmail'], 999, 3);
        // User request/export data emails
        add_filter('user_request_action_email_content', [$this, 'customizeUserRequestEmail'], 10, 2);
        add_filter('wp_privacy_personal_data_email_content', [$this, 'customizePersonalDataEmail'], 10, 3);
        add_filter('user_request_action_email_content', [$this, 'customizeUserRequestEmail'], 999, 2);
        add_filter('wp_privacy_personal_data_email_content', [$this, 'customizePersonalDataEmail'], 999, 3);
    }
    /**
@@ -82,13 +82,13 @@
     * @param string $header Optional header text for the template
     * @return bool Whether the email was sent successfully
     */
    public function sendEmail(string $to, string $subject, string $message, string $header = '', array $headers = [], array $attachments = []):bool
    public function sendEmail(string $to, string $subject, string $message, string $header = '', string $preheader = '', array $headers = [], array $attachments = []):bool
    {
        // Make sure the content type is set to HTML
        add_filter('wp_mail_content_type', [$this, 'setHtmlContentType']);
        // Format the message with our template
        $formatted_message = $this->getEmailTemplate($message, $header);
        $formatted_message = $this->getEmailTemplate($message, $header, $preheader);
        // Send the email
        $result = wp_mail($to, $subject, $formatted_message, $headers, $attachments);
@@ -105,7 +105,7 @@
     *
     * @return string
     */
    private function getEmailTemplate(string $content, string $headerText = ''):string
    private function getEmailTemplate(string $content, string $headerText = '', string $preheader = ''):string
    {
      $custom_logo_id = get_theme_mod( 'custom_logo' );
      $logo_thumbnail = wp_get_attachment_image_src( $custom_logo_id, 'custom-logo-thumbnail' );
@@ -118,6 +118,14 @@
         $headerText = $this->title;
        }
      $preheaderHtml = '';
      if (!empty($preheader)) {
         $preheaderHtml = '
        <div style="display:none;font-size:1px;color:#fefefe;line-height:1px;font-family:Helvetica,Arial,sans-serif;max-height:0px;max-width:0px;opacity:0;overflow:hidden;">
            ' . esc_html($preheader) . '
        </div>';
      }
        return '<!DOCTYPE html>
        <html>
        <head>
@@ -395,7 +403,11 @@
     */
    public function customizePasswordResetEmail(string $message, string $key, string $user_login, WP_User $user):string
    {
      $reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
      return $this->passwordResetEmail($user, $key);
    }
   public function passwordResetEmail(WP_User $user, string $key):string {
      $reset_url = network_site_url("login/?action=resetpass&key=$key&login=" . rawurlencode($user->user_login), 'login');
      $content = sprintf(
         '<p>Hi %s!</p>
         <p>We received a request to reset the password for an account associated with this email:</p>
@@ -408,14 +420,18 @@
         %s
         <p>This password reset link is only valid for 24 hours.</p>',
         $user->display_name,
         $user_login,
         $user->user_login,
         $this->button($reset_url,'Reset Password'),
         $this->link($reset_url),
         $this->divider()
      );
      $content = apply_filters('jvbPasswordResetEmail', $content, $user_login, $user, $reset_url);
        return $this->getEmailTemplate($content, 'Password Reset');
    }
      return apply_filters('jvbPasswordResetEmail', $content, $user->user_login, $user, $reset_url);
   }
   public function sendPasswordResetEmail(WP_User $user, string $key):bool
   {
      return $this->sendEmail($user->user_email, $this->passwordResetTitle(), $this->passwordResetEmail($user, $key), '', 'Reset your Password');
   }
    /**
     * Customize the password reset email title
@@ -426,10 +442,14 @@
     */
    public function customizePasswordResetTitle(string $title, string $user_login, WP_User $user_data):string
    {
      return $this->passwordResetTitle();
   }
   public function passwordResetTitle():string
   {
      $prefix = JVB_EMAIL['types']['resetPass']['showPrefix']??true;
      $prefix = ($prefix) ? $this->prefix : '';
      return $prefix.JVB_EMAIL['types']['resetPass']['subject']?:'Password Reset';
   }
    /**
@@ -671,15 +691,15 @@
         }
         $content .= sprintf(
            '<div style="padding:10px 0;border-bottom:1px solid %s;background-color:%s;">
               <span style="display:inline-block;vertical-align:top;font-weight:600;color:%s;width:%s;">%s</span>
               <div style="display:inline-block;vertical-align:top;width:%s;">%s</div>
            </div>',
        <span style="display:inline-block;vertical-align:top;font-weight:600;color:%s;width:%s;">%s</span>
        <div style="display:inline-block;vertical-align:top;width:%s;">%s</div>
    </div>',
            $this->colours['dark-200'],
            ($index%2 === 0) ? $this->colours['light-100'] : $this->colours['light-50'],
            $this->colours['dark-200'],
            '19%',
            '30%',  // Changed from 19% to 30%
            $item['label'],
            '80%',
            '68%',  // Changed from 80% to 68% (30% + 68% = 98%, leaving 2% for spacing)
            $item['value']
         );
      }