feat(06-03): add job publish hook to schedule mentor notifications

Add notify_mentors_on_job_publish() method to trigger async batch
notifications when jobs transition to publish status. Only triggers on
initial publish (not updates). Queries opted-in mentors via User
Preferences class and schedules batches via Scheduler class. Logs
notification scheduling with mentor count and batch count.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-14 21:08:23 +09:00
parent b87ac203fe
commit e24b4fa7f0

View File

@@ -23,6 +23,9 @@ class DDHH_JM_Notifications {
// Hook into post status transitions to detect job deactivations
add_action( 'transition_post_status', array( __CLASS__, 'send_admin_job_deactivation_notification' ), 10, 3 );
// Hook into post status transitions to notify mentors on job publish
add_action( 'transition_post_status', array( __CLASS__, 'notify_mentors_on_job_publish' ), 10, 3 );
// Hook into Formidable form submissions to send application notifications
add_action( 'frm_after_create_entry', array( __CLASS__, 'send_provider_application_notification' ), 30, 2 );
}
@@ -335,4 +338,52 @@ class DDHH_JM_Notifications {
);
}
}
/**
* Notify opted-in mentors when a job is published
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Post object.
*/
public static function notify_mentors_on_job_publish( $new_status, $old_status, $post ) {
// Only trigger on job_offer posts
if ( 'job_offer' !== $post->post_type ) {
return;
}
// Only send notification on initial publish (not updates to already published posts)
if ( 'publish' !== $new_status || 'publish' === $old_status ) {
return;
}
// Get opted-in mentors
$mentor_ids = DDHH_JM_User_Preferences::get_opted_in_mentors();
// Check if any mentors opted in
if ( empty( $mentor_ids ) ) {
error_log(
sprintf(
'DDHH Job Manager: No opted-in mentors to notify for job #%d "%s"',
$post->ID,
$post->post_title
)
);
return;
}
// Schedule async batch notifications
$batch_count = DDHH_JM_Scheduler::schedule_mentor_notification_batch( $mentor_ids, $post->ID );
// Log success
error_log(
sprintf(
'DDHH Job Manager: Scheduled %d notification batches for job #%d "%s" to %d mentors',
$batch_count,
$post->ID,
$post->post_title,
count( $mentor_ids )
)
);
}
}