add_action( 'transition_post_status', 'acf_notify_on_initial_publish', 10, 3 ); function acf_notify_on_initial_publish( $new_status, $old_status, $post ) { // Nur wenn Beitrag veröffentlicht wird (erstmals) if ( $new_status !== 'publish' || $old_status === 'publish' ) { return; } // Nur für Beitragstyp "post" if ( get_post_type( $post ) !== 'post' ) { return; } $post_id = $post->ID; // Bereits versendet? if ( get_post_meta( $post_id, '_notification_sent', true ) ) { return; } // Felder aus ACF laden $recipient_name = get_field( 'review_recipient_name', $post_id ); $recipient_email = get_field( 'review_recipient_email', $post_id ); if ( ! $recipient_email ) { $recipient_email = get_post_meta( $post_id, 'review_recipient_email', true ); } if ( ! $recipient_name ) { $recipient_name = get_post_meta( $post_id, 'review_recipient_name', true ); } if ( ! $recipient_email || ! is_email( $recipient_email ) ) { $log = '❌ Ungültige oder fehlende E-Mail-Adresse am ' . current_time( 'mysql' ); update_post_meta( $post_id, '_notification_log', $log ); error_log( "ACF Notify: Ungültige oder fehlende E-Mail-Adresse für Beitrag #{$post_id}" ); return; } // HTML-Inhalt $title = get_the_title( $post_id ); $permalink = get_permalink( $post_id ); $subject = 'Dein Beitrag wurde veröffentlicht'; $message = "
Hallo {$recipient_name},
der folgende Beitrag wurde soeben auf unserem Blog veröffentlicht:
Viele Grüße
Dein Blog-Team