diff --git a/includes/class-notifications.php b/includes/class-notifications.php
index 93bd726..16b7989 100644
--- a/includes/class-notifications.php
+++ b/includes/class-notifications.php
@@ -23,8 +23,8 @@ class DDHH_JM_Notifications {
// Hook into job edit to send admin notification (after metadata is saved)
add_action( 'ddhh_job_edited', array( __CLASS__, 'send_admin_job_edit_notification_after_submit' ), 10, 2 );
- // 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 job deactivation to send admin notification (after metadata is saved)
+ add_action( 'ddhh_job_deactivated', array( __CLASS__, 'send_admin_job_deactivation_notification' ), 10, 2 );
// 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 );
@@ -67,6 +67,13 @@ class DDHH_JM_Notifications {
$job_deadline = get_post_meta( $post->ID, 'job_deadline', true );
$job_contact_email = get_post_meta( $post->ID, 'job_contact_email', true );
+ // Get job description (truncate if too long)
+ $job_description = $post->post_content;
+ $description_text = wp_strip_all_tags( $job_description );
+ if ( strlen( $description_text ) > 500 ) {
+ $description_text = substr( $description_text, 0, 500 ) . '...';
+ }
+
// Format deadline if present
$deadline_formatted = 'Nicht angegeben';
if ( ! empty( $job_deadline ) ) {
@@ -82,36 +89,23 @@ class DDHH_JM_Notifications {
// Build email subject
$subject = sprintf( 'Neues Stellenangebot zur Prüfung: %s', $job_title );
- // Build email body
- $body = sprintf(
- "Ein neues Stellenangebot wurde eingereicht und wartet auf Ihre Prüfung.\n\n" .
- "Titel: %s\n" .
- "Anbieter: %s (%s)\n" .
- "Standort: %s\n" .
- "Art: %s\n" .
- "Bewerbungsfrist: %s\n" .
- "Kontakt-E-Mail: %s\n" .
- "Eingereicht am: %s\n\n" .
- "Prüfen Sie das Stellenangebot hier:\n%s\n\n" .
- "---\n" .
- "Diese E-Mail wurde automatisch gesendet.",
- $job_title,
- $author_name,
- $author_org,
- $job_location ? $job_location : 'Nicht angegeben',
- $job_type ? $job_type : 'Nicht angegeben',
- $deadline_formatted,
- $job_contact_email ? $job_contact_email : 'Nicht angegeben',
- $submission_date,
- $edit_link
- );
+ // Build email body as HTML
+ $html_body = 'Ein neues Stellenangebot wurde eingereicht und wartet auf Ihre Prüfung.
';
+ $html_body .= 'Titel: ' . esc_html( $job_title ) . '
';
+ $html_body .= 'Anbieter: ' . esc_html( $author_name ) . ' (' . esc_html( $author_org ) . ')
';
+ $html_body .= 'Standort: ' . esc_html( $job_location ? $job_location : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Art: ' . esc_html( $job_type ? $job_type : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Bewerbungsfrist: ' . esc_html( $deadline_formatted ) . '
';
+ $html_body .= 'Kontakt-E-Mail: ' . esc_html( $job_contact_email ? $job_contact_email : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Beschreibung:
' . esc_html( $description_text ) . '
';
+ $html_body .= 'Eingereicht am: ' . esc_html( $submission_date ) . '
';
+ $html_body .= 'Stellenangebot in WordPress prüfen
';
+ $html_body .= '---
';
+ $html_body .= 'Diese E-Mail wurde automatisch gesendet.';
// Set email headers
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
- // Convert plain text to HTML with line breaks
- $html_body = nl2br( esc_html( $body ) );
-
// Send email
$sent = wp_mail( $admin_email, $subject, $html_body, $headers );
@@ -161,6 +155,13 @@ class DDHH_JM_Notifications {
$job_deadline = get_post_meta( $post->ID, 'job_deadline', true );
$job_contact_email = get_post_meta( $post->ID, 'job_contact_email', true );
+ // Get job description (truncate if too long)
+ $job_description = $post->post_content;
+ $description_text = wp_strip_all_tags( $job_description );
+ if ( strlen( $description_text ) > 500 ) {
+ $description_text = substr( $description_text, 0, 500 ) . '...';
+ }
+
// Format deadline if present
$deadline_formatted = 'Nicht angegeben';
if ( ! empty( $job_deadline ) ) {
@@ -176,36 +177,23 @@ class DDHH_JM_Notifications {
// Build email subject
$subject = sprintf( 'Stellenangebot bearbeitet und wartet auf Prüfung: %s', $job_title );
- // Build email body
- $body = sprintf(
- "Ein Stellenangebot wurde bearbeitet und wartet auf erneute Prüfung.\n\n" .
- "Titel: %s\n" .
- "Anbieter: %s (%s)\n" .
- "Standort: %s\n" .
- "Art: %s\n" .
- "Bewerbungsfrist: %s\n" .
- "Kontakt-E-Mail: %s\n" .
- "Bearbeitet am: %s\n\n" .
- "Prüfen Sie das Stellenangebot hier:\n%s\n\n" .
- "---\n" .
- "Diese E-Mail wurde automatisch gesendet.",
- $job_title,
- $author_name,
- $author_org,
- $job_location ? $job_location : 'Nicht angegeben',
- $job_type ? $job_type : 'Nicht angegeben',
- $deadline_formatted,
- $job_contact_email ? $job_contact_email : 'Nicht angegeben',
- $submission_date,
- $edit_link
- );
+ // Build email body as HTML
+ $html_body = 'Ein Stellenangebot wurde bearbeitet und wartet auf erneute Prüfung.
';
+ $html_body .= 'Titel: ' . esc_html( $job_title ) . '
';
+ $html_body .= 'Anbieter: ' . esc_html( $author_name ) . ' (' . esc_html( $author_org ) . ')
';
+ $html_body .= 'Standort: ' . esc_html( $job_location ? $job_location : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Art: ' . esc_html( $job_type ? $job_type : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Bewerbungsfrist: ' . esc_html( $deadline_formatted ) . '
';
+ $html_body .= 'Kontakt-E-Mail: ' . esc_html( $job_contact_email ? $job_contact_email : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Beschreibung:
' . esc_html( $description_text ) . '
';
+ $html_body .= 'Bearbeitet am: ' . esc_html( $submission_date ) . '
';
+ $html_body .= 'Stellenangebot in WordPress prüfen
';
+ $html_body .= '---
';
+ $html_body .= 'Diese E-Mail wurde automatisch gesendet.';
// Set email headers
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
- // Convert plain text to HTML with line breaks
- $html_body = nl2br( esc_html( $body ) );
-
// Send email
$sent = wp_mail( $admin_email, $subject, $html_body, $headers );
@@ -224,19 +212,12 @@ class DDHH_JM_Notifications {
/**
* Send admin notification when a job is deactivated by provider
*
- * @param string $new_status New post status.
- * @param string $old_status Old post status.
- * @param WP_Post $post Post object.
+ * @param int $post_id Post ID.
+ * @param int $entry_id Entry ID.
*/
- public static function send_admin_job_deactivation_notification( $new_status, $old_status, $post ) {
- // Only trigger on job_offer posts transitioning from publish to draft
- if ( 'job_offer' !== $post->post_type ) {
- return;
- }
-
- // Only send notification when published job becomes draft (deactivation)
- // Avoid notification on draft saves or initial draft creation
- if ( 'draft' !== $new_status || 'publish' !== $old_status ) {
+ public static function send_admin_job_deactivation_notification( $post_id, $entry_id ) {
+ $post = get_post( $post_id );
+ if ( ! $post || 'job_offer' !== $post->post_type ) {
return;
}
@@ -268,7 +249,7 @@ class DDHH_JM_Notifications {
$deadline_formatted = date( 'd.m.Y', strtotime( $job_deadline ) );
}
- // Get deactivation reason from post meta
+ // Get deactivation reason from post meta (now saved before this hook fires)
$deactivation_reason = get_post_meta( $post->ID, 'job_deactivation_reason', true );
if ( empty( $deactivation_reason ) ) {
$deactivation_reason = 'Kein Grund angegeben';
@@ -283,38 +264,23 @@ class DDHH_JM_Notifications {
// Build email subject
$subject = sprintf( 'Stellenangebot deaktiviert: %s', $job_title );
- // Build email body
- $body = sprintf(
- "Ein Stellenangebot wurde vom Anbieter deaktiviert.\n\n" .
- "Titel: %s\n" .
- "Anbieter: %s (%s)\n" .
- "Standort: %s\n" .
- "Art: %s\n" .
- "Bewerbungsfrist: %s\n" .
- "Kontakt-E-Mail: %s\n" .
- "Deaktiviert am: %s\n\n" .
- "Grund für Deaktivierung:\n%s\n\n" .
- "Stelle ansehen:\n%s\n\n" .
- "---\n" .
- "Diese E-Mail wurde automatisch gesendet.",
- $job_title,
- $author_name,
- $author_org,
- $job_location ? $job_location : 'Nicht angegeben',
- $job_type ? $job_type : 'Nicht angegeben',
- $deadline_formatted,
- $job_contact_email ? $job_contact_email : 'Nicht angegeben',
- $deactivation_date,
- $deactivation_reason ? $deactivation_reason : 'Nicht angegeben',
- $edit_link
- );
+ // Build email body as HTML
+ $html_body = 'Ein Stellenangebot wurde vom Anbieter deaktiviert.
';
+ $html_body .= 'Titel: ' . esc_html( $job_title ) . '
';
+ $html_body .= 'Anbieter: ' . esc_html( $author_name ) . ' (' . esc_html( $author_org ) . ')
';
+ $html_body .= 'Standort: ' . esc_html( $job_location ? $job_location : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Art: ' . esc_html( $job_type ? $job_type : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Bewerbungsfrist: ' . esc_html( $deadline_formatted ) . '
';
+ $html_body .= 'Kontakt-E-Mail: ' . esc_html( $job_contact_email ? $job_contact_email : 'Nicht angegeben' ) . '
';
+ $html_body .= 'Deaktiviert am: ' . esc_html( $deactivation_date ) . '
';
+ $html_body .= 'Grund für Deaktivierung:
' . esc_html( $deactivation_reason ) . '
';
+ $html_body .= 'Stellenangebot in WordPress ansehen
';
+ $html_body .= '---
';
+ $html_body .= 'Diese E-Mail wurde automatisch gesendet.';
// Set email headers
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
- // Convert plain text to HTML with line breaks
- $html_body = nl2br( esc_html( $body ) );
-
// Send email
$sent = wp_mail( $admin_email, $subject, $html_body, $headers );