WP Multi Comment Notifications Einstellungen

Telegram Bot Token

Discord Webhook URL

Nachricht für Discord

Verwende Platzhalter wie {{COMMENT_AUTHOR}}, {{COMMENT_TEXT}}, {{USER_NAME}}, {{POST_TITLE}}, {{SITE_NAME}}, {{POST_URL}}, {{COMMENT_DATE}}, {{COMMENT_URL}}

Nachricht für E-Mail

Verwende Platzhalter wie {{COMMENT_AUTHOR}}, {{COMMENT_TEXT}}, {{USER_NAME}}, {{POST_TITLE}}, {{SITE_NAME}}, {{POST_URL}}, {{COMMENT_DATE}}, {{COMMENT_URL}}

Nachricht für Telegram

Verwende Platzhalter wie {{COMMENT_AUTHOR}}, {{COMMENT_TEXT}}, {{USER_NAME}}, {{POST_TITLE}}, {{SITE_NAME}}, {{POST_URL}}, {{COMMENT_DATE}}, {{COMMENT_URL}}

Backend-Button URL

Logo/Banner für E-Mail

Füge hier die vollständige URL zum Logo/Banner ein, das in der E-Mail angezeigt werden soll.

User

" /> " /> " /> " />
comment_author; $text = $comment->comment_content; $post_id = $comment->comment_post_ID; $post_title = get_the_title($post_id); // Titel des Beitrags $site = get_bloginfo('name'); $url = get_option('wp_backend_button_url'); $logo = esc_url(get_option('wp_email_logo_url')); $discord_webhook = get_option('wp_discord_webhook_url'); $discord_template = get_option('wp_discord_message'); $post_url = get_permalink($post_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, // Nur für Testzwecke '{{POST_TITLE}}' => $post_title, '{{SITE_NAME}}' => $site, '{{POST_URL}}' => $post_url, '{{COMMENT_DATE}}' => $comment_date, '{{COMMENT_URL}}' => 'Kommentar ansehen' // E-Mail mit anklickbarem Link ]); $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_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 ]); $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' => [ 'chat_id' => $telegram_chat_id, 'text' => $telegram_message ] ]); } add_action('comment_post', 'wp_multi_comment_notifications_on_comment'); /** ------------------------- * Testnachrichten senden * ------------------------- */ add_action('admin_init', function () { if ($_SERVER['REQUEST_METHOD'] === 'POST') { for ($i = 1; $i <= 6; $i++) { if (isset($_POST["send_test_message_user_$i"])) { wp_multi_comment_notifications_send_test_message($i); } } } }); function wp_multi_comment_notifications_send_test_message($user_number) { $name = get_option("wp_user_{$user_number}_name"); $email = get_option("wp_user_{$user_number}_email"); $chat_id = get_option("wp_user_{$user_number}_telegram_chat_id"); $discord_webhook = get_option('wp_discord_webhook_url'); $token = get_option('wp_telegram_token'); $button_url = get_option('wp_backend_button_url'); $message = "Dies ist eine Testnachricht für $name."; if ($email) { wp_mail($email, 'Testnachricht', $message); } if ($chat_id) { wp_multi_comment_notifications_send_telegram($token, $chat_id, 0, $message); } if ($discord_webhook) { wp_multi_comment_notifications_send_discord($discord_webhook, $message); } } /** ------------------------- * Telegram-Nachricht mit Button * ------------------------- */ function wp_multi_comment_notifications_send_telegram($token, $chat_id, $comment_ID, $message) { $url = "https://api.telegram.org/bot$token/sendMessage"; $button_url = get_option('wp_backend_button_url'); $data = [ 'chat_id' => $chat_id, 'text' => $message, 'parse_mode' => 'HTML' ]; if ($button_url) { $data['reply_markup'] = json_encode([ 'inline_keyboard' => [[['text' => 'Zum Backend', 'url' => $button_url]]] ]); } wp_remote_post($url, [ 'body' => $data, 'timeout' => 10, 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], ]); } /** ------------------------- * Discord-Nachricht senden * ------------------------- */ function wp_multi_comment_notifications_send_discord($webhook_url, $message) { $payload = json_encode(['content' => $message]); wp_remote_post($webhook_url, [ 'headers' => ['Content-Type' => 'application/json'], 'body' => $payload, 'timeout' => 10, ]); }