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,51 +218,45 @@ 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_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); $comment_url = get_comment_link($comment_ID);
// Nachricht für Discord nur einmal senden // Hole den Benutzernamen aus den Plugin-Einstellungen
if ($discord_webhook && $discord_template) { $user_name = get_option("wp_user_1_name"); // Beispiel: Benutzer 1
// Nachricht für Discord
$discord_msg = strtr($discord_template, [ $discord_msg = strtr($discord_template, [
'{{COMMENT_AUTHOR}}' => $author, '{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text, '{{COMMENT_TEXT}}' => $text,
'{{POST_TITLE}}' => $post_title, // Titel in die Nachricht einfügen '{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site, '{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url, '{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date, '{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url, // Discord akzeptiert keine HTML-Links, aber URL als Text '{{COMMENT_URL}}' => $comment_url,
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
]); ]);
wp_remote_post($discord_webhook, [
'body' => json_encode([
'content' => $discord_msg
])
]);
}
// Nachricht per E-Mail verschicken // Nachricht per E-Mail verschicken
$email_message = get_option('wp_email_message'); $email_message = get_option('wp_email_message');
$email_message = strtr($email_message, [ $email_message = strtr($email_message, [
'{{COMMENT_AUTHOR}}' => $author, '{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text, '{{COMMENT_TEXT}}' => $text,
'{{USER_NAME}}' => $author, '{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
'{{POST_TITLE}}' => $post_title, '{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site, '{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url, '{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date, '{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url '{{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);
// Telegram-Nachricht // Telegram-Nachricht
$telegram_message = get_option('wp_telegram_message'); $telegram_message = get_option('wp_telegram_message');
$telegram_message = strtr($telegram_message, [ $telegram_message = strtr($telegram_message, [
'{{COMMENT_AUTHOR}}' => $author, '{{COMMENT_AUTHOR}}' => $author,
'{{COMMENT_TEXT}}' => $text, '{{COMMENT_TEXT}}' => $text,
'{{USER_NAME}}' => $author, // Nur für Testzwecke '{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
'{{POST_TITLE}}' => $post_title, '{{POST_TITLE}}' => $post_title,
'{{SITE_NAME}}' => $site, '{{SITE_NAME}}' => $site,
'{{POST_URL}}' => $post_url, '{{POST_URL}}' => $post_url,
'{{COMMENT_DATE}}' => $comment_date, '{{COMMENT_DATE}}' => $comment_date,
'{{COMMENT_URL}}' => $comment_url // Telegram akzeptiert keine HTML-Links, aber URL als Text '{{COMMENT_URL}}' => $comment_url
]); ]);
$telegram_chat_id = get_option('wp_user_1_telegram_chat_id'); // Beispiel für den ersten Benutzer $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", [ wp_remote_post("https://api.telegram.org/bot" . get_option('wp_telegram_token') . "/sendMessage", [