wp-multi-comment-notifications.php aktualisiert

This commit is contained in:
M_Viper 2025-04-12 11:12:18 +00:00
parent 37b41fd014
commit bc7c87500c

View File

@ -218,52 +218,46 @@ function wp_multi_comment_notifications_on_comment($comment_ID) {
$comment_date = get_comment_date('H:i - d.m.Y', $comment_ID); // Zeit und Datum im gewünschten Format
$comment_url = get_comment_link($comment_ID);
// Nachricht für Discord nur einmal senden
if ($discord_webhook && $discord_template) {
$discord_msg = strtr($discord_template, [
'{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text,
'{{POST_TITLE}}' => $post_title, // Titel in die Nachricht einfügen
'{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url, // Discord akzeptiert keine HTML-Links, aber URL als Text
]);
wp_remote_post($discord_webhook, [
'body' => json_encode([
'content' => $discord_msg
])
]);
}
// Nachricht per E-Mail verschicken
$email_message = get_option('wp_email_message');
$email_message = strtr($email_message, [
'{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text,
'{{USER_NAME}}' => $author,
'{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url
]);
$subject = "Neuer Kommentar auf $site: $post_title";
$email_recipient = get_option('wp_user_1_email'); // Beispiel für den ersten Benutzer
wp_mail($email_recipient, $subject, $email_message);
// Hole den Benutzernamen aus den Plugin-Einstellungen
$user_name = get_option("wp_user_1_name"); // Beispiel: Benutzer 1
// Telegram-Nachricht
$telegram_message = get_option('wp_telegram_message');
$telegram_message = strtr($telegram_message, [
'{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text,
'{{USER_NAME}}' => $author, // Nur für Testzwecke
'{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url // Telegram akzeptiert keine HTML-Links, aber URL als Text
]);
// Nachricht für Discord
$discord_msg = strtr($discord_template, [
'{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text,
'{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url,
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
]);
// Nachricht per E-Mail verschicken
$email_message = get_option('wp_email_message');
$email_message = strtr($email_message, [
'{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text,
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
'{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url
]);
// Telegram-Nachricht
$telegram_message = get_option('wp_telegram_message');
$telegram_message = strtr($telegram_message, [
'{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text,
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
'{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url
]);
$telegram_chat_id = get_option('wp_user_1_telegram_chat_id'); // Beispiel für den ersten Benutzer
wp_remote_post("https://api.telegram.org/bot" . get_option('wp_telegram_token') . "/sendMessage", [
'body' => [