From 474109a5df0a06f5343ab184838fe2d80e3872a8 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 11 Jan 2026 19:23:20 +0000
Subject: [PATCH] =Fixed timeline CRUD.js issue where this.activeItem was set null when we still needed it
---
inc/managers/NotificationManager.php | 149 ++++++++++++++++++++++++-------------------------
1 files changed, 74 insertions(+), 75 deletions(-)
diff --git a/inc/managers/NotificationManager.php b/inc/managers/NotificationManager.php
index 146d2a0..5656303 100644
--- a/inc/managers/NotificationManager.php
+++ b/inc/managers/NotificationManager.php
@@ -139,7 +139,7 @@
*/
public function __construct()
{
- $this->cache = new CacheManager('notifications', WEEK_IN_SECONDS); // 1 week cache
+ $this->cache = CacheManager::for('notifications', WEEK_IN_SECONDS);
// Add filter for bulk operation handling
add_filter(BASE . 'handle_bulk_operation', [ $this, 'processOperation' ], 10, 3);
@@ -435,6 +435,10 @@
*/
public function trackContentCreation(int $post_id, WP_POST $post, bool $update):void
{
+ // SAFETY: Skip attachments and other non-content post types
+ if (in_array($post->post_type, jvbIgnoredPostTypes())) {
+ return;
+ }
// Skip if not a published post
if ($post->post_status !== 'publish') {
return;
@@ -1026,7 +1030,7 @@
};
// Send the email
- return jvbMail($user->user_email, $subject, $content, $header);
+ return JVB()->email()->sendEmail($user->user_email, $subject, $content, $header);
}
/**
@@ -1039,46 +1043,47 @@
*
* @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
@@ -1095,7 +1100,7 @@
}
$content = '';
- $cache = new CacheManager('digest_content', HOUR_IN_SECONDS * 6); // Cache for 6 hours
+ $cache = CacheManager::for('digest_content', HOUR_IN_SECONDS * 6); // Cache for 6 hours
// Group updates by artist
$updates_by_artist = [];
@@ -1230,46 +1235,39 @@
*
* @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
@@ -1630,8 +1628,9 @@
*/
protected function clearNotificationCache(int $user_id):void
{
- $this->cache->invalidate("user_{$user_id}_notifications_", 'notifications_' . $user_id);
- $this->cache->invalidate("user_{$user_id}_content_notifications_", 'notifications_' . $user_id);
+
+ $this->cache->delete("user_{$user_id}_notifications_", 'notifications_' . $user_id);
+ $this->cache->delete("user_{$user_id}_content_notifications_", 'notifications_' . $user_id);
}
/**
--
Gitblit v1.10.0