' . sprintf( __('Fehler beim Aktivieren von WP Multi Toolkit: %s', 'wp-multi-comment-notifications'), esc_html($result->get_error_message()) ) . '

'; }); } } } // Funktion zum Installieren des erforderlichen Plugins function wpmcn_install_required_plugin($download_url, $plugin_file) { if (!current_user_can('install_plugins')) { return; // Nur Admins können Plugins installieren } require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; // Dateisystemzugriff initialisieren $access_type = get_filesystem_method(); if ($access_type !== 'direct') { add_action('admin_notices', function () { echo '

' . __('Direkter Dateizugriff erforderlich, um WP Multi Toolkit zu installieren. Bitte überprüfe die Dateisystemkonfiguration.', 'wp-multi-comment-notifications') . '

'; }); return; } $creds = request_filesystem_credentials(admin_url(), '', false, false, null); if (!WP_Filesystem($creds)) { add_action('admin_notices', function () { echo '

' . __('Dateisystemzugriff fehlgeschlagen. WP Multi Toolkit konnte nicht installiert werden.', 'wp-multi-comment-notifications') . '

'; }); return; } $upgrader = new Plugin_Upgrader(); $result = $upgrader->install($download_url); if (is_wp_error($result)) { add_action('admin_notices', function () use ($result) { echo '

' . sprintf( __('Fehler beim Installieren von WP Multi Toolkit: %s', 'wp-multi-comment-notifications'), esc_html($result->get_error_message()) ) . '

'; }); } else { // Installation erfolgreich, aktiviere das Plugin $activate = activate_plugin($plugin_file); if (is_wp_error($activate)) { add_action('admin_notices', function () use ($activate) { echo '

' . sprintf( __('Fehler beim Aktivieren von WP Multi Toolkit nach Installation: %s', 'wp-multi-comment-notifications'), esc_html($activate->get_error_message()) ) . '

'; }); } else { add_action('admin_notices', function () { echo '

' . __('WP Multi Toolkit wurde erfolgreich installiert und aktiviert.', 'wp-multi-comment-notifications') . '

'; }); } } } // Prüfung bei Plugin-Aktivierung und jedem Admin-Ladevorgang register_activation_hook(__FILE__, 'wpmcn_check_dependency'); add_action('admin_init', 'wpmcn_check_dependency'); // 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen function wp_multi_comment_notifications_menu() { add_submenu_page( 'edit-comments.php', 'WP Multi Comment Notifications', 'Kommentar Benachrichtigungen', 'manage_options', 'wp-multi-comment-notifications', 'wp_multi_comment_notifications_settings_page' ); } add_action('admin_menu', 'wp_multi_comment_notifications_menu'); function wp_multi_comment_notifications_settings_page() { ?>

WP Multi Comment Notifications Einstellungen

Telegram Bot Token

Discord Webhook URL

Nachricht für Discord

Verwende Platzhalter wie {{COMMENT_AUTHOR}}, {{COMMENT_TEXT}}, {{USER_NAME}} für dynamische Daten.

Nachricht für E-Mail

Verwende Platzhalter wie {{COMMENT_AUTHOR}}, {{COMMENT_TEXT}}, {{USER_NAME}} für dynamische Daten.

Nachricht für Telegram

Verwende Platzhalter wie {{COMMENT_AUTHOR}}, {{COMMENT_TEXT}}, {{USER_NAME}} für dynamische Daten.

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; $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'); // Nachricht für Discord nur einmal senden if ($discord_webhook && $discord_template) { $discord_msg = strtr($discord_template, [ '{{COMMENT_AUTHOR}}' => $author, '{{COMMENT_TEXT}}' => $text, ]); wp_multi_comment_notifications_send_discord($discord_webhook, $discord_msg); } // 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 ); } } } add_action('wp_insert_comment', 'wp_multi_comment_notifications_on_comment', 10, 1); /** ------------------------- * 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, ]); }