Enable mentors to opt-in to email notifications for new published jobs via user profile toggle.
Purpose: Allow mentors (subscribers) to control whether they receive notifications when new jobs are published, respecting user preferences and avoiding unwanted emails.
Output: User meta field for notification preference with profile UI toggle for opt-in/opt-out.
PROJECT.md line 42: "Existing users: Mentors already exist as subscribers"
PROJECT.md line 27: "Mentor opt-in notification system for new published jobs"
Tech stack available: User meta functions (get_user_meta, update_user_meta), profile hooks (show_user_profile, edit_user_profile, personal_options_update, edit_user_profile_update)
Established patterns:
Singleton pattern for classes (Phase 01-02)
Static setup_hooks() method for initialization (all phases)
German labels for UI (Phase 01-02, 02-01, 03-01)
Class file loading in main plugin file (all phases)
Constraining decisions:
PROJECT.md: Mentors are WordPress subscribers (existing role)
PROJECT.md: Opt-in system (not opt-out) - users must explicitly enable notifications
Phase 03-03: Email notifications use wp_mail with error logging
Task 1: Create user preferences class with notification opt-in meta
includes/class-user-preferences.php, includes/class-ddhh-job-manager.php, ddhh-job-manager.php
Create new file includes/class-user-preferences.php with class DDHH_JM_User_Preferences. Add static method setup_hooks() that registers hooks for user profile display and saving. User meta key: 'ddhh_jm_notify_new_jobs' (boolean, default false = opt-out by default). Add method show_notification_toggle() that hooks to show_user_profile and edit_user_profile (both hooks needed - one for viewing own profile, one for admin editing). Display only for users with 'subscriber' role (mentors). Use checkbox input with label "Benachrichtigungen über neue Stellenangebote erhalten" (German: "Receive notifications about new job offers"). Add method save_notification_preference() that hooks to personal_options_update and edit_user_profile_update. Sanitize input with checkbox pattern: isset($_POST['ddhh_jm_notify_new_jobs']) ? '1' : '0'. Use update_user_meta() to save. Add nonce verification for security. Initialize class in includes/class-ddhh-job-manager.php by calling DDHH_JM_User_Preferences::setup_hooks() in init_hooks(). Add require_once in main plugin file ddhh-job-manager.php following established pattern.
Check includes/class-user-preferences.php exists with DDHH_JM_User_Preferences class. Verify setup_hooks() registered for profile display and save hooks. Confirm checkbox appears on subscriber user profiles. Verify user meta saves correctly when checkbox toggled.
User preferences class created, notification opt-in checkbox appears on mentor profiles, preference saves to user meta 'ddhh_jm_notify_new_jobs', class initialized in main plugin
Task 2: Add helper method to query opted-in mentors
includes/class-user-preferences.php
Add static method get_opted_in_mentors() to DDHH_JM_User_Preferences class. Method returns array of user IDs who have opted in. Use WP_User_Query with arguments: role='subscriber' (mentors), meta_query for ddhh_jm_notify_new_jobs='1', fields='ID' (return only IDs for efficiency). Return empty array if no results. This provides clean API for Phase 06-03 to get notification recipients. Add error_log if query fails for debugging. Example usage: $mentor_ids = DDHH_JM_User_Preferences::get_opted_in_mentors(); foreach ($mentor_ids as $user_id) { /* send email */ }
Check get_opted_in_mentors() method exists. Verify it returns array of user IDs. Confirm WP_User_Query filters by subscriber role and meta value. Verify returns empty array when no opt-ins exist.
Helper method get_opted_in_mentors() exists, returns filtered list of opted-in mentor user IDs, ready for use in email batch processing
Before declaring plan complete:
- [ ] User preferences class exists in includes/class-user-preferences.php
- [ ] Checkbox appears on subscriber user profiles (both own profile and admin edit)
- [ ] Preference saves correctly to user meta ddhh_jm_notify_new_jobs
- [ ] Helper method get_opted_in_mentors() returns correct user IDs
- [ ] Class properly initialized in main plugin
- [ ] German labels used for UI elements
<success_criteria>
User preferences class created following singleton pattern
Notification opt-in checkbox displayed on mentor (subscriber) profiles
User meta field 'ddhh_jm_notify_new_jobs' saves preference (default: false/opt-out)
Helper method available to query opted-in mentors by user ID
UI uses German labels for consistency
Nonce verification for security
</success_criteria>
After completion, create `.planning/phases/06-email-notifications/06-01-SUMMARY.md`:
Phase 6 Plan 1: Mentor Notification Opt-In Summary
[Substantive one-liner - what shipped, not "phase complete"]
Accomplishments
[Key outcome 1]
[Key outcome 2]
Files Created/Modified
includes/class-user-preferences.php - Description
includes/class-ddhh-job-manager.php - Description
ddhh-job-manager.php - Description
Decisions Made
[Key decisions and rationale, or "None"]
Issues Encountered
[Problems and resolutions, or "None"]
Next Step
Ready for parallel execution with 06-02 (Action Scheduler integration). Both 06-01 and 06-02 are independent and can run concurrently.