diff --git a/wp-multi-comment-notifications.php b/wp-multi-comment-notifications.php
index 5543b9c..48c639d 100644
--- a/wp-multi-comment-notifications.php
+++ b/wp-multi-comment-notifications.php
@@ -3,7 +3,7 @@
* Plugin Name: WP Multi Comment Notifications
* Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-multi-comment-notifications
* Description: Benachrichtigt bei neuen Kommentaren per E-Mail und optional über Telegram & Discord. Ideal für Teams, die schnell informiert werden wollen.
- * Version: 1.3
+ * Version: 1.4
* Author: M_Viper
* Author URI: https://m-viper.de
* Requires at least: 6.7.2
@@ -65,7 +65,6 @@ if (wp_multi_comment_notifications_check_dependency()) {
define('WPMCN_PLUGIN_VERSION', '1.2');
define('WPMCN_PLUGIN_DIR', plugin_dir_path(__FILE__));
-
// 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen
function wp_multi_comment_notifications_menu() {
add_submenu_page(
@@ -98,16 +97,15 @@ function wp_multi_comment_notifications_settings_page() {
Nachricht für Discord
- Verwende Platzhalter wie {{COMMENT_AUTHOR}}
, {{COMMENT_TEXT}}
, {{USER_NAME}}
für dynamische Daten.
-
+ 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}}
für dynamische Daten.
+ 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}}
für dynamische Daten.
+ Verwende Platzhalter wie {{COMMENT_AUTHOR}}
, {{COMMENT_TEXT}}
, {{USER_NAME}}
, {{POST_TITLE}}
, {{SITE_NAME}}
, {{POST_URL}}
, {{COMMENT_DATE}}
, {{COMMENT_URL}}
Backend-Button URL
@@ -198,7 +196,6 @@ function wp_multi_comment_notifications_register_settings() {
register_setting('wp_multi_comment_notifications_settings_group', 'wp_email_logo_url');
register_setting('wp_multi_comment_notifications_settings_group', 'wp_discord_webhook_url');
register_setting('wp_multi_comment_notifications_settings_group', 'wp_discord_message');
-
}
add_action('admin_init', 'wp_multi_comment_notifications_register_settings');
@@ -209,61 +206,74 @@ function wp_multi_comment_notifications_on_comment($comment_ID) {
$comment = get_comment($comment_ID);
$author = $comment->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
+ ])
]);
- wp_multi_comment_notifications_send_discord($discord_webhook, $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);
- // E-Mail & Telegram Benachrichtigungen pro Benutzer
- for ($i = 1; $i <= 6; $i++) {
- $name = get_option("wp_user_{$i}_name");
- $email = get_option("wp_user_{$i}_email");
- $chat_id = get_option("wp_user_{$i}_telegram_chat_id");
-
- // Nachricht für E-Mail & Telegram
- $replacements = [
- '{{COMMENT_AUTHOR}}' => $author,
- '{{COMMENT_TEXT}}' => $text,
- '{{USER_NAME}}' => $name,
- ];
-
- $email_msg = strtr(get_option('wp_email_message'), $replacements);
- if ($url) $email_msg .= "\n\nWeitere Details hier: $url";
-
- if ($email) {
- $html = $logo ? "
" : '';
- $html .= nl2br(esc_html($email_msg));
- $headers = [
- 'Content-Type: text/html; charset=UTF-8',
- 'From' => get_option( 'admin_email' ),
- ];
- wp_mail($email, 'Neuer Kommentar', $html, $headers);
- }
-
- $tg_msg = strtr(get_option('wp_telegram_message'), $replacements);
-
- if ($chat_id) {
- wp_multi_comment_notifications_send_telegram(
- get_option('wp_telegram_token'),
- $chat_id,
- $comment_ID,
- $tg_msg
- );
- }
- }
+ // 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('wp_insert_comment', 'wp_multi_comment_notifications_on_comment', 10, 1);
+add_action('comment_post', 'wp_multi_comment_notifications_on_comment');
/** -------------------------
* Testnachrichten senden
@@ -301,7 +311,6 @@ function wp_multi_comment_notifications_send_test_message($user_number) {
}
}
-
/** -------------------------
* Telegram-Nachricht mit Button
* ------------------------- */
@@ -328,7 +337,6 @@ function wp_multi_comment_notifications_send_telegram($token, $chat_id, $comment
]);
}
-
/** -------------------------
* Discord-Nachricht senden
* ------------------------- */