| | |
| | | }; |
| | | |
| | | // Send the email |
| | | return jvbMail($user->user_email, $subject, $content, $header); |
| | | return JVB()->email()->sendEmail($user->user_email, $subject, $content, $header); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return string HTML email content |
| | | */ |
| | | protected function generateDigestContent(WP_User $user, string $frequency, array $notifications, array $content_updates):string |
| | | { |
| | | $content = sprintf('<p>Hey %s,</p>', $user->first_name ?: $user->display_name); |
| | | protected function generateDigestContent(WP_User $user, string $frequency, array $notifications, array $content_updates):string |
| | | { |
| | | $content = sprintf('<p>Hey %s,</p>', $user->first_name ?: $user->display_name); |
| | | |
| | | // Intro text based on frequency |
| | | switch ($frequency) { |
| | | case 'daily': |
| | | $content .= '<p>Here\'s what happened in Edmonton\'s tattoo scene today:</p>'; |
| | | break; |
| | | case 'weekly': |
| | | $content .= '<p>Here\'s what you missed in Edmonton\'s tattoo scene this week:</p>'; |
| | | break; |
| | | case 'monthly': |
| | | $content .= sprintf('<p>Here\'s your monthly roundup of what happened in %s in Edmonton\'s tattoo scene:</p>', date('F')); |
| | | break; |
| | | } |
| | | // Intro text based on frequency |
| | | switch ($frequency) { |
| | | case 'daily': |
| | | $content .= '<p>Here\'s what happened in Edmonton\'s tattoo scene today:</p>'; |
| | | break; |
| | | case 'weekly': |
| | | $content .= '<p>Here\'s what you missed in Edmonton\'s tattoo scene this week:</p>'; |
| | | break; |
| | | case 'monthly': |
| | | $content .= sprintf('<p>Here\'s your monthly roundup of what happened in %s in Edmonton\'s tattoo scene:</p>', date('F')); |
| | | break; |
| | | } |
| | | |
| | | // Process artist content updates - the most visually interesting part |
| | | $content .= $this->generateContentUpdatesSection($content_updates); |
| | | // Process artist content updates - the most visually interesting part |
| | | $content .= $this->generateContentUpdatesSection($content_updates); |
| | | |
| | | // Process regular notifications |
| | | if (!empty($notifications)) { |
| | | $content .= $this->generateNotificationsSection($notifications); |
| | | } |
| | | // Process regular notifications |
| | | if (!empty($notifications)) { |
| | | $content .= $this->generateNotificationsSection($notifications); |
| | | } |
| | | |
| | | // Add footer content |
| | | $content .= '<div class="divider"></div>'; |
| | | $content .= sprintf( |
| | | '<p>You\'re receiving this %s digest because you follow artists on edmonton.ink. ' . |
| | | 'You can <a href="%s" class="text-link">adjust your notification settings</a> at any time.</p>', |
| | | $frequency, |
| | | esc_url(add_query_arg([ |
| | | 'utm_source' => 'email', |
| | | 'utm_medium' => 'digest', |
| | | 'utm_campaign' => $this->campaign |
| | | ], site_url('/dash/settings/'))) |
| | | ); |
| | | // Add footer content |
| | | $content .= JVB()->email()->divider(); |
| | | $settings_url = add_query_arg([ |
| | | 'utm_source' => 'email', |
| | | 'utm_medium' => 'digest', |
| | | 'utm_campaign' => $this->campaign |
| | | ], site_url('/dash/settings/')); |
| | | |
| | | return $content; |
| | | } |
| | | $content .= sprintf( |
| | | '<p>You\'re receiving this %s digest because you follow artists on edmonton.ink. You can %s at any time.</p>', |
| | | $frequency, |
| | | '<a href="' . esc_url($settings_url) . '">adjust your notification settings</a>' |
| | | ); |
| | | |
| | | return $content; |
| | | } |
| | | |
| | | /** |
| | | * Generate HTML section for content updates |
| | |
| | | * |
| | | * @return string HTML content |
| | | */ |
| | | protected function generateNotificationsSection(array $notifications):string |
| | | { |
| | | if (empty($notifications)) { |
| | | return ''; |
| | | } |
| | | protected function generateNotificationsSection(array $notifications):string |
| | | { |
| | | if (empty($notifications)) { |
| | | return ''; |
| | | } |
| | | |
| | | $content = '<h3>Other Updates</h3>'; |
| | | $content .= '<ul style="padding-left: 20px;">'; |
| | | $items = []; |
| | | |
| | | // Group notifications by type |
| | | $by_type = []; |
| | | foreach ($notifications as $notification) { |
| | | if (!isset($by_type[$notification->type])) { |
| | | $by_type[ $notification->type ] = []; |
| | | } |
| | | $by_type[ $notification->type ][] = $notification; |
| | | } |
| | | // Group notifications by type |
| | | $by_type = []; |
| | | foreach ($notifications as $notification) { |
| | | if (!isset($by_type[$notification->type])) { |
| | | $by_type[$notification->type] = []; |
| | | } |
| | | $by_type[$notification->type][] = $notification; |
| | | } |
| | | |
| | | // Process each type |
| | | foreach ($by_type as $type => $type_notifications) { |
| | | $config = $this->notification_types[ $type ] ?? []; |
| | | $icon = $config['icon'] ?? 'info'; |
| | | // Process each type |
| | | foreach ($by_type as $type => $type_notifications) { |
| | | foreach ($type_notifications as $notification) { |
| | | $message = $notification->message; |
| | | if (empty($message)) { |
| | | $message = $this->generateNotificationMessage($notification); |
| | | } |
| | | |
| | | foreach ($type_notifications as $notification) { |
| | | $message = $notification->message; |
| | | if (empty($message)) { |
| | | $message = $this->generateNotificationMessage($notification); |
| | | } |
| | | if (!empty($message)) { |
| | | $items[] = ['label' => '', 'value' => $message]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!empty($message)) { |
| | | $content .= sprintf('<li>%s</li>', $message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | $content .= '</ul>'; |
| | | $content .= '<div class="divider"></div>'; |
| | | |
| | | return $content; |
| | | } |
| | | return JVB()->email()->table($items, 'Other Updates'); |
| | | } |
| | | |
| | | /** |
| | | * Generate a message for a notification when none is provided |