From bc7c87500c8bb7453b4282f1d835b2ebe4886dc3 Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sat, 12 Apr 2025 11:12:18 +0000 Subject: [PATCH] wp-multi-comment-notifications.php aktualisiert --- wp-multi-comment-notifications.php | 84 ++++++++++++++---------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/wp-multi-comment-notifications.php b/wp-multi-comment-notifications.php index 2f44cd7..32251a9 100644 --- a/wp-multi-comment-notifications.php +++ b/wp-multi-comment-notifications.php @@ -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' => [