site_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $this->site_url = get_site_url(); $this->signature = jvbSignature(); 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); // Password reset emails add_filter('retrieve_password_message', [$this, 'customizePasswordResetEmail'], 10, 4); add_filter('retrieve_password_title', [$this, 'customizePasswordResetTitle'], 10, 3); // User email change emails add_filter('email_change_email', [$this, 'customizeEmailChangeEmail'], 10, 3); add_filter('new_user_email_content', [$this, 'customizeNewUserEmailContent'], 10, 2); // Password change notification add_filter('password_change_email', [$this, 'customizePasswordChangeEmail'], 10, 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); } /** * Helper to set content type to HTML * @return string */ public function setHtmlContentType():string { return 'text/html'; } /** * Send a styled email using the common template * * @param string $to Recipient email address * @param string $subject Email subject line * @param string $message Email body content (can contain HTML) * @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 = ''):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); // Send the email $result = wp_mail($to, $subject, $formatted_message); // Reset content type filter to avoid affecting other emails remove_filter('wp_mail_content_type', [$this, 'setHtmlContentType']); return $result; } /** * Common email wrapper template * @param string $content * @param string $header * * @return string */ private function getEmailTemplate(string $content, string $header = ''):string { // Get logo URL (replace with your actual logo path) $logo_url = esc_url(wp_get_attachment_image_url(get_theme_mod('custom_logo'), 'medium')); // Default header if none provided if (empty($header)) { $header = 'edmonton.ink'; } return ' ' . $this->site_name . '
Edmonton Ink

' . $header . '

' . $content . '
'; } /** * New user registration email to user */ public function customizeNewUserEmail($wp_new_user_notification_email, $user, $blogname) { $user_login = $user->user_login; // Only create the password key if the user can change their password $key = get_password_reset_key($user); if (!is_wp_error($key)) { $reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login'); $message = sprintf('

Hey %s!

', $user->first_name); $message .= '

Thanks for joining Edmonton\'s tattoo scene. Here\'s your login information:

'; $message .= sprintf('

Username: %s

', $user_login); $message .= '

To set your password and access your account, click the button below:

'; $message .= sprintf('

Set Your Password

', $reset_url); $message .= '

Or copy and paste this link into your browser:

'; $message .= sprintf('

%s

', $reset_url); $message .= '

This link will expire in 24 hours, for security reasons.

'; if (in_array('jvb_artist', array_values($user->roles))) { $message .= '
'; $message .= '

NOTE:

Once you set your password, you\'ll have access to your custom dashboard where you can:

Nothing will be published until you\'ve been approved by 3 already approved artists, or the admin.

Admins check every day or three, but, if you are in a rush, you can contact us directly by replying to this email, or texting us at 825-925-9916.

'; } elseif (in_array('jvb_partner', array_values($user->roles))) { $message .= '
'; $message .= '

NOTE:

Once you set your password, you\'ll have access to your custom dashboard where you can:

Nothing will be published until you\'ve been approved by the admin.

Admins check every day or three, but, if you are in a rush, you can contact us directly by replying to this email, or texting us at 825-925-9916.

Note:Even after approval by admin, your ability to publish depends on your karmic standing by artists. Artists each have a vote they can cast (UP or DOWN) - if your karmic score dips too far in the negative, you account is subject to reconsideration or even a ban.

'; } $message .= '
'; $message = apply_filters(BASE.'new_user_email_content', $message, $user); $message .= '

If you didn\'t create this account, please ignore this email and the link will expire.

'; $message .= sprintf('

Ink on, %s

', $user->first_name); $message .= $this->signature; $wp_new_user_notification_email['message'] = $this->getEmailTemplate($message, 'Welcome to edmonton.ink'); } // Change the subject line $wp_new_user_notification_email['subject'] = sprintf('Welcome to %s! Confirm your account', $this->site_name); return $wp_new_user_notification_email; } /** * New user registration email to admin * @param array $emailData * @param WP_User $user * @param string $blogname * * @return array */ public function customizeNewUserEmailAdmin(array $emailData, WP_User $user, string $blogname):array { $message = '

A new user has registered on ' . $this->site_name . ':

'; $message .= '

Username: ' . $user->user_login . '
'; $message .= 'Email: ' . $user->user_email . '
'; $message .= 'Role: ' . str_replace(BASE, '', array_values($user->roles)[0]).'

'; $message .= $this->signature; $emailData['message'] = $this->getEmailTemplate($message, 'New User Registration'); $emailData['subject'] = '[' . $this->site_name . '] New ' . str_replace(BASE, '', array_values($user->roles)[0]).': '.$user->display_name; return $emailData; } /** * Password reset email * @param string $message * @param string $key * @param string $user_login * @param WP_User $user_data * * @return string */ public function customizePasswordResetEmail(string $message, string $key, string $user_login, WP_User $user_data):string { $reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login'); $content = '

Hey bud,

'; $content = '

We received a request to reset the password for an account associated with this email:

'; $content .= '

Username: ' . $user_login . '

'; $content .= '

If you didn\'t make this request, you can safely ignore this email and nothing will happen to your account.

'; $content .= '

To reset your password, click the button below:

'; $content .= '

Reset Password

'; $content .= '

Or copy and paste this link into your browser:

'; $content .= '

' . $reset_url . '

'; $content .= '
'; $content .= '

This password reset link is only valid for 24 hours.

'; $content .= $this->signature; return $this->getEmailTemplate($content, 'Password Reset'); } /** * Customize the password reset email title * @param string $title * @param string $user_login * @param WP_User $user_data * @return string */ public function customizePasswordResetTitle(string $title, string $user_login, WP_User $user_data):string { return '[' . $this->site_name . '] Password Reset Request'; } /** * Email change notification to admin * @param array $email_change_email * @param array $user * @param array $userdata * * @return array */ public function customizeEmailChangeEmail(array $email_change_email, array $user, array $userdata):array { $content = sprintf('

Hi %s,

', $user['first_name']); $content .= '

Ideally you already know this: you asked to change your email, and here we are.

'; $content .= '

Old Email: ' . $email_change_email['to'] . '
'; $content .= 'New Email: ' . $user['user_email'] . '

'; $content .= '

If this is news, or you did not change your email, please contact us immediately. You can text us or reply to this email.">

'; $content .= '

Log In to Your Account

'; $content .= $this->signature; $email_change_email['message'] = $this->getEmailTemplate($content, 'Email Address Changed'); $email_change_email['subject'] = '[' . $this->site_name . '] Email Address Changed'; return $email_change_email; } /** * New email address confirmation * @param string $email_text * @param array $user * * @return string */ public function customizeNewUserEmailContent(string $email_text, array $user):string { // Extract the confirmation link from the default message $pattern = '/###CONFIRM_URL### (.*?)(?=\n|\r|$)/'; preg_match($pattern, $email_text, $matches); $confirm_url = isset($matches[1]) ? $matches[1] : admin_url('profile.php?newuseremail=' . $user['hash']); $content = '

Hey human,

'; $content .= '

Seems you want to change the email associated with your account.

'; $content .= '

You\'d like to change your email to: ' . $user['newemail'] . '

'; $content .= '

Please confirm this change by clicking the button below:

'; $content .= '

Confirm Email Change

'; $content .= '

Or copy and paste this link into your browser:

'; $content .= '

' . $confirm_url . '

'; $content .= '
'; $content .= '

If you did not request this change, you can safely ignore this email and nothing will change.

'; $content .= $this->signature; return $this->getEmailTemplate($content, 'Confirm Email Change'); } /** * Password change notification * @param array $pass_change_email * @param array $user * @param array $userdata * * @return array */ public function customizePasswordChangeEmail(array $pass_change_email, array $user, array $userdata):array { $content = '

Hey bud,

'; $content .= '

Ideally, you\'re expecting this email. You wanted to change your password, and this is to let you know that it\'s definitely updated.

'; $content .= '

If you did not change your password, please contact us immediately.

'; $content .= '

You can text us, or reply to this email.

'; $content .= '

Log In to Your Account

'; $content .= $this->signature; $pass_change_email['message'] = $this->getEmailTemplate($content, 'Password Changed'); $pass_change_email['subject'] = '[' . $this->site_name . '] Password Changed'; return $pass_change_email; } /** * User data request confirmation email * @param string $content * @param array $request_data * * @return string */ public function customizeUserRequestEmail(string $content, array $request_data):string { // Extract the confirmation URL from the content $pattern = '/]*>/'; preg_match($pattern, $content, $matches); $confirm_url = isset($matches[1]) ? $matches[1] : ''; $request_type = $request_data['action_name']; $request_name = ''; switch ($request_type) { case 'export_personal_data': $request_name = 'Export Personal Data'; break; case 'remove_personal_data': $request_name = 'Erase Personal Data'; break; default: $request_name = 'Data Request'; } $message = '

Hi privacy enthusiast,

'; $message .= '

A request has been made to perform the following action on your account:

'; $message .= '

' . $request_name . '

'; $message .= '

If you made this request, you can confirm it by clicking the button below:

'; $message .= '

Confirm Request

'; $message .= '

Or copy and paste this link into your browser:

'; $message .= '

' . $confirm_url . '

'; $message .= '
'; $message .= '

If you did not make this request, you can safely ignore this email.

'; $message .= $this->signature; return $this->getEmailTemplate($message, 'Action Confirmation'); } /** * Personal data export email * @param string $content * @param int $request_id * @param array $email_data * * @return string */ public function customizePersonalDataEmail(string $content, int $request_id, array $email_data):string { // Extract the download link $pattern = '/]*>/'; preg_match($pattern, $content, $matches); $download_url = isset($matches[1]) ? $matches[1] : ''; $message = '

Your request for an export of personal data has been completed.

'; $message .= '

You can download your personal data by clicking the button below.

'; $message .= '

Download Personal Data

'; $message .= '

Or copy and paste this link into your browser:

'; $message .= '

' . $download_url . '

'; $message .= '
'; $message .= '

Important: For privacy reasons, this link will expire in ' . $email_data['expiration'] . '.

'; $message .= $this->signature; return $this->getEmailTemplate($message, 'Your Personal Data Export'); } } new EmailManager();