[ 'title' => 'Account', 'icon' => 'settings', ], 'notifications' => [ 'title' => 'Notifications', 'icon' => 'email' ], 'newsletter' => [ 'title' => 'Newsletter', 'icon' => 'logo' ], 'invitations' => [ 'title' => 'Invite Artists', 'icon' => 'new-user', ] ]; protected array $frequency = [ 'never' => 'Never', 'daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly', ]; public function initType():void { $this->object_type = 'user'; $this->userFields(); } public function getFields():array { return $this->fields; } public function getSections():array { return $this->sections; } public function userFields():void { $this->fields = [ 'display_name' => [ 'type' => 'text', 'label' => 'Name', 'description' => 'Optional. Only used if you allow artists to see your info when you favourite them.', 'default' => '', 'section' => 'account', 'role' => ['ei_enthusiast'] ], 'user_email' => [ 'type' => 'email', 'label' => 'Email', 'description' => 'Required for any notifications you subscribe to.', 'default' => '', 'section' => 'account', 'role' => ['ei_enthusiast'] ], 'city' => [ 'type' => 'text', 'label' => 'City', 'description' => 'Optional. Just helps us know where people who use this site are located.', 'default' => '', 'section' => 'account', 'role' => ['ei_enthusiast'] ], 'notify' => [ 'type' => 'true_false', 'label' => 'Notify artists when you favourite their work', 'description' => 'If you select this, artists will see your name when you favourite their work, else they will just get an anonymous notification.', 'default' => false, 'section' => 'account', ], 'dark_mode' => [ 'type' => 'true_false', 'label' => 'Dark Mode', 'default' => false, ], 'email_digest' => [ 'type' => 'radio', 'label' => 'Email Summary Frequency', 'options' => $this->frequency, 'default' => 'never', 'section' => 'notifications' ], 'digest_override' => [ 'type' => 'true_false', 'label' => 'Apply to all notifications', 'description' => 'Override individual notification settings and apply this frequency to all your notifications', 'default' => false, 'section' => 'notifications' ], 'notifications' => [ 'type' => 'callback', 'callback' => 'renderNotifications', 'label' => 'Notifications', 'section' => 'notifications', 'default' => '', ], 'site_updates' => [ 'type' => 'true_false', 'label' => 'Site Updates', 'description' => 'Get notified when new features are added to edmonton.ink', 'default' => false, 'section' => 'account', ], 'newsletter' => [ 'type' => 'true_false', 'label' => 'Newsletter', 'description' => 'Sign up for our monthly-ish newsletter, featuring upcoming events, featured artists, new artists, and their work.', 'default' => false, 'section' => 'newsletter', ], 'owner_of' => [ 'type' => 'taxonomy', 'label' => __('Owner of', 'jvb'), 'taxonomy_type' => 'reference', 'taxonomy' => BASE. 'shop', 'quickEdit' => true, 'default' => '', ], 'manager_of' => [ 'type' => 'taxonomy', 'label' => __('Manager of', 'jvb'), 'taxonomy_type' => 'reference', 'taxonomy' => BASE. 'shop', 'hidden' => true, 'default' => '', ], 'invitations' => [ 'type' => 'callback', 'callback' => 'handleInvitationsManagement', 'section' => 'invitations', 'label' => __('Invite Artists', 'jvb'), 'role' => ['ei_artist'] ], ]; } /** * Render custom notification preferences UI * @param int $user_id * * @return string */ public function renderNotifications(int $user_id):string { $favourites = $this->getUserFavourites($user_id); $preferences = $this->getUserNotificationPreferences($user_id); global $notify; ob_start(); ?>
$items) : ?>
'fill'])?> ( )
Name Frequency
" value="" >
Set all s to:

No favourites yet

prefix . BASE.'favourites'; global $notify; global $types; $favourites = []; foreach (array_keys($notify) as $type) { $favourites[$type] = []; } // Fetch favourites from database $results = $wpdb->get_results($wpdb->prepare( "SELECT * FROM $table WHERE user_id = %d", $user_id )); foreach ($results as $result) { $type = str_replace(BASE, '', $result->type); if (!array_key_exists($type, $favourites)) { continue; } // Get proper name based on type switch ($types[BASE.$type]['table']) { case 'post': $name = get_the_title($result->target_id); break; case 'term': $term = get_term($result->target_id, BASE.$type); $name = $term ? $term->name : ''; break; default: $name = ''; } if ($name) { $favourites[$type][] = [ 'id' => $result->target_id, 'name' => $name ]; } } return $favourites; } /** * Get current notification preferences */ protected function getNotificationPreferences(int $user_id):array { return get_user_meta($user_id, 'notification_preferences', true) ?: []; } protected function getUserNotificationPreferences(int $user_id):array { global $wpdb; $table = $wpdb->prefix . BASE.'notification_preferences'; // error_log('Getting notification preferences for user: ' . $user_id); // Get user's preferences from the table $raw_preferences = $wpdb->get_results($wpdb->prepare( "SELECT notification_type, item_id, frequency FROM {$table} WHERE user_id = %d", $user_id ), ARRAY_A); // error_log('Raw preferences from database: ' . print_r($raw_preferences, true)); // Structure the preferences $preferences = []; if (!empty($raw_preferences)) { foreach ($raw_preferences as $pref) { $type = $pref['notification_type']; $item_id = intval($pref['item_id']); $frequency = $pref['frequency']; if (!isset($preferences[$type])) { $preferences[$type] = []; } $preferences[$type][$item_id] = $frequency; } } // Get default frequency $default_frequency = get_user_meta($user_id, BASE.'email_digest', true) ?: 'never'; // error_log('Structured preferences: ' . print_r($preferences, true)); // error_log('Default frequency: ' . $default_frequency); return [ 'preferences' => $preferences, 'default_frequency' => $default_frequency ]; } public function handleInvitationsManagement(int $userID):void { $name = 'artist_invite'; ?>
routes('invites')->getUserInvitations($userID); ?> invitations)) { foreach ($invites->invitations as $invite) { ?>
Name Email Status Expires Actions
No invites yet