fix(quick-001): fix 3 admin email notification issues

- Add job description to submission and edit emails (truncated to 500 chars)
- Fix deactivation reason timing bug by hooking into ddhh_job_deactivated action instead of transition_post_status
- Make all admin email links clickable HTML hyperlinks using proper <a> tags
- Convert all admin emails from plain text to proper HTML format with esc_html() on individual values
This commit is contained in:
2026-01-29 13:00:38 +09:00
parent 84a4ae7c1b
commit 3dab3f9034

View File

@@ -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.<br><br>';
$html_body .= '<strong>Titel:</strong> ' . esc_html( $job_title ) . '<br>';
$html_body .= '<strong>Anbieter:</strong> ' . esc_html( $author_name ) . ' (' . esc_html( $author_org ) . ')<br>';
$html_body .= '<strong>Standort:</strong> ' . esc_html( $job_location ? $job_location : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Art:</strong> ' . esc_html( $job_type ? $job_type : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Bewerbungsfrist:</strong> ' . esc_html( $deadline_formatted ) . '<br>';
$html_body .= '<strong>Kontakt-E-Mail:</strong> ' . esc_html( $job_contact_email ? $job_contact_email : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Beschreibung:</strong><br>' . esc_html( $description_text ) . '<br><br>';
$html_body .= '<strong>Eingereicht am:</strong> ' . esc_html( $submission_date ) . '<br><br>';
$html_body .= '<a href="' . esc_url( $edit_link ) . '">Stellenangebot in WordPress prüfen</a><br><br>';
$html_body .= '---<br>';
$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.<br><br>';
$html_body .= '<strong>Titel:</strong> ' . esc_html( $job_title ) . '<br>';
$html_body .= '<strong>Anbieter:</strong> ' . esc_html( $author_name ) . ' (' . esc_html( $author_org ) . ')<br>';
$html_body .= '<strong>Standort:</strong> ' . esc_html( $job_location ? $job_location : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Art:</strong> ' . esc_html( $job_type ? $job_type : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Bewerbungsfrist:</strong> ' . esc_html( $deadline_formatted ) . '<br>';
$html_body .= '<strong>Kontakt-E-Mail:</strong> ' . esc_html( $job_contact_email ? $job_contact_email : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Beschreibung:</strong><br>' . esc_html( $description_text ) . '<br><br>';
$html_body .= '<strong>Bearbeitet am:</strong> ' . esc_html( $submission_date ) . '<br><br>';
$html_body .= '<a href="' . esc_url( $edit_link ) . '">Stellenangebot in WordPress prüfen</a><br><br>';
$html_body .= '---<br>';
$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.<br><br>';
$html_body .= '<strong>Titel:</strong> ' . esc_html( $job_title ) . '<br>';
$html_body .= '<strong>Anbieter:</strong> ' . esc_html( $author_name ) . ' (' . esc_html( $author_org ) . ')<br>';
$html_body .= '<strong>Standort:</strong> ' . esc_html( $job_location ? $job_location : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Art:</strong> ' . esc_html( $job_type ? $job_type : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Bewerbungsfrist:</strong> ' . esc_html( $deadline_formatted ) . '<br>';
$html_body .= '<strong>Kontakt-E-Mail:</strong> ' . esc_html( $job_contact_email ? $job_contact_email : 'Nicht angegeben' ) . '<br>';
$html_body .= '<strong>Deaktiviert am:</strong> ' . esc_html( $deactivation_date ) . '<br><br>';
$html_body .= '<strong>Grund für Deaktivierung:</strong><br>' . esc_html( $deactivation_reason ) . '<br><br>';
$html_body .= '<a href="' . esc_url( $edit_link ) . '">Stellenangebot in WordPress ansehen</a><br><br>';
$html_body .= '---<br>';
$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 );