Compare commits
No commits in common. "main" and "1.0" have entirely different histories.
@ -3,7 +3,7 @@
|
|||||||
**Benachrichtigt bei neuen WordPress-Kommentaren per E-Mail und optional über Telegram.**
|
**Benachrichtigt bei neuen WordPress-Kommentaren per E-Mail und optional über Telegram.**
|
||||||
Ideal für Teams und Website-Administratoren, die nichts verpassen möchten.
|
Ideal für Teams und Website-Administratoren, die nichts verpassen möchten.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
@ -46,5 +46,5 @@ Die Plugin-eigene Logik verwendet WordPress’ Kommentar-Hooks, um Administrator
|
|||||||
|
|
||||||
### Dashboard-Widget
|
### Dashboard-Widget
|
||||||
|
|
||||||
Das Plugin zeigt ein Widget im WP-Admin-Dashboard, das auf die neueste Version des Plugins prüft
|
Das Plugin zeigt ein Widget im WP-Admin-Dashboard, das auf die neueste Version des Plugins prüft – über die öffentliche Gitea-API:
|
||||||
|
|
||||||
|
@ -1,345 +1,359 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* Plugin Name: WP Multi Comment Notifications
|
* Plugin Name: WP Multi Comment Notifications
|
||||||
* Plugin URI: https://git.viper.ipv64.net/M_Viper/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.
|
* Description: Benachrichtigt bei neuen Kommentaren per E-Mail und optional über Telegram. Ideal für Teams, die schnell informiert werden wollen.
|
||||||
* Version: 1.4
|
* Version: 1.0
|
||||||
* Author: M_Viper
|
* Author: M_Viper
|
||||||
* Author URI: https://m-viper.de
|
* Author URI: https://m-viper.de
|
||||||
* Requires at least: 6.7.2
|
* Requires at least: 6.7.2
|
||||||
* Tested up to: 6.7.2
|
* Tested up to: 6.7.2
|
||||||
* License: GPL2
|
* License: GPL2
|
||||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
* Text Domain: wp-multi-comment-notifications
|
* Text Domain: wp-multi-comment-notifications
|
||||||
* Domain Path: /languages
|
* Domain Path: /languages
|
||||||
* Tags: kommentare, benachrichtigung, e-mail, telegram, discord, kommentarüberwachung, teamkommunikation
|
* Tags: kommentare, benachrichtigung, e-mail, telegram, kommentarüberwachung, teamkommunikation
|
||||||
*
|
*
|
||||||
* Support:
|
* Support:
|
||||||
* - Microsoft Teams: https://teams.live.com/l/community/FEAzokphpZTJ2u6OgI
|
* - Microsoft Teams: https://teams.live.com/l/community/FEAzokphpZTJ2u6OgI
|
||||||
* - Telegram: https://t.me/M_Viper04
|
* - Telegram: https://t.me/M_Viper04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('ABSPATH')) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion zur Überprüfung des WP Multi Toolkit Plugins
|
/**
|
||||||
function wp_multi_comment_notifications_check_dependency() {
|
* Dashboard Widget – Update Info für dieses Plugin
|
||||||
if (!function_exists('is_plugin_active')) {
|
*/
|
||||||
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
function wp_multi_cmn_dashboard_widget() {
|
||||||
}
|
wp_add_dashboard_widget(
|
||||||
|
'wp_multi_cmn_update_widget',
|
||||||
// Prüft, ob WP Multi Toolkit installiert und aktiv ist
|
__('WP Multi Comment Notifications – Update Info', 'wp-multi-comment-notifications'),
|
||||||
if (!is_plugin_active('wp-multi-toolkit/wp-multi-toolkit.php')) {
|
'wp_multi_cmn_update_dashboard_widget_content'
|
||||||
add_action('admin_notices', 'wp_multi_comment_notifications_dependency_notice');
|
);
|
||||||
return false;
|
}
|
||||||
}
|
add_action('wp_dashboard_setup', 'wp_multi_cmn_dashboard_widget');
|
||||||
return true;
|
|
||||||
}
|
// Cron-Intervall „stündlich“ definieren
|
||||||
|
add_filter('cron_schedules', function ($schedules) {
|
||||||
// Fehlermeldung für Admin-Bereich mit Download-Button
|
$schedules['hourly'] = array(
|
||||||
function wp_multi_comment_notifications_dependency_notice() {
|
'interval' => 3600,
|
||||||
?>
|
'display' => __('Stündlich', 'wp-multi-comment-notifications'),
|
||||||
<div class="notice notice-error">
|
);
|
||||||
<p>
|
return $schedules;
|
||||||
<?php _e('Das Plugin "WP Multi Comment Notifications" benötigt "WP Multi Toolkit", um zu funktionieren. Bitte installieren und aktivieren Sie "WP Multi Toolkit".', 'wp-multi-comment-notifications'); ?>
|
});
|
||||||
<a href="https://git.viper.ipv64.net/M_Viper/wp-multi-toolkit/releases" target="_blank" class="button button-primary" style="margin-left: 10px;">
|
|
||||||
<?php _e('WP Multi Toolkit herunterladen', 'wp-multi-comment-notifications'); ?>
|
// Cron-Event planen
|
||||||
</a>
|
function wp_multi_cmn_schedule_update_check() {
|
||||||
</p>
|
if (!wp_next_scheduled('wp_multi_cmn_update_check_event')) {
|
||||||
</div>
|
wp_schedule_event(time(), 'hourly', 'wp_multi_cmn_update_check_event');
|
||||||
<?php
|
}
|
||||||
}
|
}
|
||||||
|
add_action('wp', 'wp_multi_cmn_schedule_update_check');
|
||||||
// Plugin nur initialisieren, wenn Abhängigkeit erfüllt ist
|
|
||||||
if (wp_multi_comment_notifications_check_dependency()) {
|
// Gitea API aufrufen
|
||||||
// Hier würde der restliche Plugin-Code folgen
|
function wp_multi_cmn_fetch_latest_release($show_prereleases = false) {
|
||||||
|
$api_url = 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/wp-multi-comment-notifications/releases';
|
||||||
} else {
|
$response = wp_remote_get($api_url, array('timeout' => 10));
|
||||||
// Optional: Plugin komplett deaktivieren, wenn Abhängigkeit fehlt
|
|
||||||
add_action('admin_init', function() {
|
if (is_wp_error($response)) {
|
||||||
deactivate_plugins(plugin_basename(__FILE__));
|
error_log('WP Multi Comment Notifications – Update Fehler: ' . $response->get_error_message());
|
||||||
});
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
define('WPMCN_PLUGIN_VERSION', '1.2');
|
$body = wp_remote_retrieve_body($response);
|
||||||
define('WPMCN_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
$data = json_decode($body, true);
|
||||||
|
|
||||||
// 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen
|
if (!is_array($data)) {
|
||||||
function wp_multi_comment_notifications_menu() {
|
error_log('WP Multi Comment Notifications – Ungültige API-Antwort');
|
||||||
add_submenu_page(
|
return false;
|
||||||
'edit-comments.php',
|
}
|
||||||
'WP Multi Comment Notifications',
|
|
||||||
'Kommentar Benachrichtigungen',
|
foreach ($data as $release) {
|
||||||
'manage_options',
|
if (!$show_prereleases && isset($release['prerelease']) && $release['prerelease']) {
|
||||||
'wp-multi-comment-notifications',
|
continue;
|
||||||
'wp_multi_comment_notifications_settings_page'
|
}
|
||||||
);
|
if (!empty($release['tag_name'])) {
|
||||||
}
|
return $release;
|
||||||
add_action('admin_menu', 'wp_multi_comment_notifications_menu');
|
}
|
||||||
|
}
|
||||||
function wp_multi_comment_notifications_settings_page() {
|
|
||||||
?>
|
return null;
|
||||||
<div class="wrap">
|
}
|
||||||
<h1>WP Multi Comment Notifications Einstellungen</h1>
|
|
||||||
<form method="post" action="options.php">
|
// Cron Callback
|
||||||
<?php
|
function wp_multi_cmn_update_check() {
|
||||||
settings_fields( 'wp_multi_comment_notifications_settings_group' );
|
if (!function_exists('get_plugin_data')) {
|
||||||
do_settings_sections( 'wp-multi-comment-notifications' );
|
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||||
?>
|
}
|
||||||
<h3>Telegram Bot Token</h3>
|
|
||||||
<label for="wp_telegram_token">Telegram Bot Token</label>
|
$plugin_data = get_plugin_data(__FILE__);
|
||||||
<input type="text" name="wp_telegram_token" value="<?php echo esc_attr(get_option('wp_telegram_token')); ?>" class="regular-text" />
|
$installed_version = $plugin_data['Version'];
|
||||||
|
$show_prereleases = get_option('wp_multi_cmn_show_prereleases', false);
|
||||||
<h3>Discord Webhook URL</h3>
|
|
||||||
<label for="wp_discord_webhook_url">Webhook URL</label>
|
$release = wp_multi_cmn_fetch_latest_release($show_prereleases);
|
||||||
<input type="text" name="wp_discord_webhook_url" value="<?php echo esc_attr(get_option('wp_discord_webhook_url')); ?>" class="regular-text" />
|
|
||||||
|
if ($release) {
|
||||||
<h3>Nachricht für Discord</h3>
|
update_option('wp_multi_cmn_latest_version', $release['tag_name']);
|
||||||
<textarea name="wp_discord_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_discord_message')); ?></textarea>
|
update_option('wp_multi_cmn_release_notes', $release['body']);
|
||||||
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code>, <code>{{POST_TITLE}}</code>, <code>{{SITE_NAME}}</code>, <code>{{POST_URL}}</code>, <code>{{COMMENT_DATE}}</code>, <code>{{COMMENT_URL}}</code> </p>
|
update_option('wp_multi_cmn_is_prerelease', $release['prerelease']);
|
||||||
|
}
|
||||||
<h3>Nachricht für E-Mail</h3>
|
}
|
||||||
<textarea name="wp_email_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_email_message')); ?></textarea>
|
add_action('wp_multi_cmn_update_check_event', 'wp_multi_cmn_update_check');
|
||||||
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code>, <code>{{POST_TITLE}}</code>, <code>{{SITE_NAME}}</code>, <code>{{POST_URL}}</code>, <code>{{COMMENT_DATE}}</code>, <code>{{COMMENT_URL}}</code> </p>
|
|
||||||
|
// Widget Callback
|
||||||
<h3>Nachricht für Telegram</h3>
|
function wp_multi_cmn_update_dashboard_widget_content() {
|
||||||
<textarea name="wp_telegram_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_telegram_message')); ?></textarea>
|
if (!function_exists('get_plugin_data')) {
|
||||||
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code>, <code>{{POST_TITLE}}</code>, <code>{{SITE_NAME}}</code>, <code>{{POST_URL}}</code>, <code>{{COMMENT_DATE}}</code>, <code>{{COMMENT_URL}}</code> </p>
|
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||||
|
}
|
||||||
<h3>Backend-Button URL</h3>
|
|
||||||
<label for="wp_backend_button_url">URL für Backend Button</label>
|
$plugin_data = get_plugin_data(__FILE__);
|
||||||
<input type="text" name="wp_backend_button_url" value="<?php echo esc_attr(get_option('wp_backend_button_url')); ?>" class="regular-text" />
|
$installed_version = $plugin_data['Version'];
|
||||||
|
$show_prereleases = get_option('wp_multi_cmn_show_prereleases', false);
|
||||||
<h3>Logo/Banner für E-Mail</h3>
|
|
||||||
<label for="wp_email_logo_url">Logo/Banner URL</label>
|
$release = wp_multi_cmn_fetch_latest_release($show_prereleases);
|
||||||
<input type="text" name="wp_email_logo_url" value="<?php echo esc_attr(get_option('wp_email_logo_url')); ?>" class="regular-text" />
|
|
||||||
<p>Füge hier die vollständige URL zum Logo/Banner ein, das in der E-Mail angezeigt werden soll.</p>
|
if ($release === false) {
|
||||||
|
echo '<p style="color:red;">Fehler beim Abrufen der Update-Informationen.</p>';
|
||||||
<div class="user-boxes">
|
return;
|
||||||
<?php for ($i = 1; $i <= 6; $i++) : ?>
|
}
|
||||||
<div class="user-box">
|
|
||||||
<h3>User <?php echo $i; ?></h3>
|
$latest_version = $release['tag_name'];
|
||||||
<label for="wp_user_<?php echo $i; ?>_name">Name</label>
|
$release_notes = isset($release['body']) ? $release['body'] : '';
|
||||||
<input type="text" name="wp_user_<?php echo $i; ?>_name" value="<?php echo esc_attr(get_option("wp_user_{$i}_name")); ?>" />
|
$is_prerelease = isset($release['prerelease']) && $release['prerelease'];
|
||||||
|
|
||||||
<label for="wp_user_<?php echo $i; ?>_email">E-Mail Adresse</label>
|
if (version_compare($installed_version, $latest_version, '>=')) {
|
||||||
<input type="email" name="wp_user_<?php echo $i; ?>_email" value="<?php echo esc_attr(get_option("wp_user_{$i}_email")); ?>" />
|
echo '<p style="color:green;">Du verwendest die aktuelle Version: <strong>' . esc_html($installed_version) . '</strong></p>';
|
||||||
|
} else {
|
||||||
<label for="wp_user_<?php echo $i; ?>_telegram_chat_id">Telegram Chat ID</label>
|
echo '<p style="color:red;"><strong>Neue Version verfügbar: ' . esc_html($latest_version) . '</strong></p>';
|
||||||
<input type="text" name="wp_user_<?php echo $i; ?>_telegram_chat_id" value="<?php echo esc_attr(get_option("wp_user_{$i}_telegram_chat_id")); ?>" />
|
echo '<p>Installiert: <strong>' . esc_html($installed_version) . '</strong></p>';
|
||||||
|
|
||||||
<!-- Button für individuelle Testnachricht -->
|
if ($is_prerelease && $show_prereleases) {
|
||||||
<input type="submit" name="send_test_message_user_<?php echo $i; ?>" class="button button-secondary" value="Testnachricht an <?php echo esc_attr(get_option("wp_user_{$i}_name")); ?>" />
|
echo '<p style="color:blue;">Hinweis: Dies ist ein PreRelease.</p>';
|
||||||
</div>
|
}
|
||||||
<?php endfor; ?>
|
|
||||||
</div>
|
if (!empty($release_notes)) {
|
||||||
<?php submit_button(); ?>
|
echo '<p><strong>Release Notes:</strong><br>' . nl2br(esc_html($release_notes)) . '</p>';
|
||||||
</form>
|
}
|
||||||
</div>
|
|
||||||
|
$download_url = isset($release['assets'][0]['browser_download_url']) ? $release['assets'][0]['browser_download_url'] : '#';
|
||||||
<style>
|
echo '<p><a href="' . esc_url($download_url) . '" class="button button-primary">Update herunterladen</a></p>';
|
||||||
.user-boxes {
|
}
|
||||||
display: flex;
|
}
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 20px;
|
|
||||||
}
|
// 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen
|
||||||
|
function wp_multi_comment_notifications_menu() {
|
||||||
.user-box {
|
add_submenu_page(
|
||||||
width: 30%;
|
'edit-comments.php',
|
||||||
padding: 15px;
|
'WP Multi Comment Notifications',
|
||||||
border: 1px solid #ddd;
|
'Kommentar Benachrichtigungen',
|
||||||
border-radius: 5px;
|
'manage_options',
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
'wp-multi-comment-notifications',
|
||||||
}
|
'wp_multi_comment_notifications_settings_page'
|
||||||
|
);
|
||||||
.user-box h3 {
|
}
|
||||||
margin-top: 0;
|
add_action('admin_menu', 'wp_multi_comment_notifications_menu');
|
||||||
}
|
|
||||||
|
function wp_multi_comment_notifications_settings_page() {
|
||||||
.user-box label {
|
?>
|
||||||
display: block;
|
<div class="wrap">
|
||||||
margin-bottom: 5px;
|
<h1>WP Multi Comment Notifications Einstellungen</h1>
|
||||||
}
|
<form method="post" action="options.php">
|
||||||
|
<?php
|
||||||
.user-box input,
|
settings_fields( 'wp_multi_comment_notifications_settings_group' );
|
||||||
.user-box textarea {
|
do_settings_sections( 'wp-multi-comment-notifications' );
|
||||||
width: 100%;
|
?>
|
||||||
padding: 8px;
|
<h3>Telegram Bot Token</h3>
|
||||||
margin-bottom: 10px;
|
<label for="wp_telegram_token">Telegram Bot Token</label>
|
||||||
border: 1px solid #ddd;
|
<input type="text" name="wp_telegram_token" value="<?php echo esc_attr(get_option('wp_telegram_token')); ?>" class="regular-text" />
|
||||||
border-radius: 5px;
|
|
||||||
}
|
<h3>Nachricht für E-Mail</h3>
|
||||||
|
<textarea name="wp_email_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_email_message')); ?></textarea>
|
||||||
.regular-text {
|
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code> für dynamische Daten.</p>
|
||||||
width: 100%;
|
|
||||||
}
|
<h3>Nachricht für Telegram</h3>
|
||||||
|
<textarea name="wp_telegram_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_telegram_message')); ?></textarea>
|
||||||
.large-text {
|
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code> für dynamische Daten.</p>
|
||||||
width: 100%;
|
|
||||||
height: 150px;
|
<h3>Backend-Button URL</h3>
|
||||||
}
|
<label for="wp_backend_button_url">URL für Backend Button</label>
|
||||||
</style>
|
<input type="text" name="wp_backend_button_url" value="<?php echo esc_attr(get_option('wp_backend_button_url')); ?>" class="regular-text" />
|
||||||
<?php
|
|
||||||
}
|
<h3>Logo/Banner für E-Mail</h3>
|
||||||
|
<label for="wp_email_logo_url">Logo/Banner URL</label>
|
||||||
function wp_multi_comment_notifications_register_settings() {
|
<input type="text" name="wp_email_logo_url" value="<?php echo esc_attr(get_option('wp_email_logo_url')); ?>" class="regular-text" />
|
||||||
for ($i = 1; $i <= 6; $i++) {
|
<p>Füge hier die vollständige URL zum Logo/Banner ein, das in der E-Mail angezeigt werden soll.</p>
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', "wp_user_{$i}_name");
|
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', "wp_user_{$i}_email");
|
<div class="user-boxes">
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', "wp_user_{$i}_telegram_chat_id");
|
<?php for ($i = 1; $i <= 6; $i++) : ?>
|
||||||
}
|
<div class="user-box">
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_telegram_token');
|
<h3>User <?php echo $i; ?></h3>
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_email_message');
|
<label for="wp_user_<?php echo $i; ?>_name">Name</label>
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_telegram_message');
|
<input type="text" name="wp_user_<?php echo $i; ?>_name" value="<?php echo esc_attr(get_option("wp_user_{$i}_name")); ?>" />
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_backend_button_url');
|
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_email_logo_url');
|
<label for="wp_user_<?php echo $i; ?>_email">E-Mail Adresse</label>
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_discord_webhook_url');
|
<input type="email" name="wp_user_<?php echo $i; ?>_email" value="<?php echo esc_attr(get_option("wp_user_{$i}_email")); ?>" />
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_discord_message');
|
|
||||||
}
|
<label for="wp_user_<?php echo $i; ?>_telegram_chat_id">Telegram Chat ID</label>
|
||||||
add_action('admin_init', 'wp_multi_comment_notifications_register_settings');
|
<input type="text" name="wp_user_<?php echo $i; ?>_telegram_chat_id" value="<?php echo esc_attr(get_option("wp_user_{$i}_telegram_chat_id")); ?>" />
|
||||||
|
</div>
|
||||||
/** -------------------------
|
<?php endfor; ?>
|
||||||
* Kommentar-Benachrichtigung
|
</div>
|
||||||
* ------------------------- */
|
<?php submit_button(); ?>
|
||||||
function wp_multi_comment_notifications_on_comment($comment_ID) {
|
</form>
|
||||||
$comment = get_comment($comment_ID);
|
</div>
|
||||||
$author = $comment->comment_author;
|
|
||||||
$text = $comment->comment_content;
|
<style>
|
||||||
$post_id = $comment->comment_post_ID;
|
.user-boxes {
|
||||||
$post_title = get_the_title($post_id); // Titel des Beitrags
|
display: flex;
|
||||||
$site = get_bloginfo('name');
|
flex-wrap: wrap;
|
||||||
$url = get_option('wp_backend_button_url');
|
gap: 20px;
|
||||||
$logo = esc_url(get_option('wp_email_logo_url'));
|
}
|
||||||
$discord_webhook = get_option('wp_discord_webhook_url');
|
|
||||||
$discord_template = get_option('wp_discord_message');
|
.user-box {
|
||||||
|
width: 30%;
|
||||||
$post_url = get_permalink($post_id);
|
padding: 15px;
|
||||||
$comment_date = get_comment_date('H:i - d.m.Y', $comment_ID); // Zeit und Datum im gewünschten Format
|
border: 1px solid #ddd;
|
||||||
$comment_url = get_comment_link($comment_ID);
|
border-radius: 5px;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||||
// Hole den Benutzernamen aus den Plugin-Einstellungen
|
}
|
||||||
$user_name = get_option("wp_user_1_name"); // Beispiel: Benutzer 1
|
|
||||||
|
.user-box h3 {
|
||||||
// Nachricht für Discord
|
margin-top: 0;
|
||||||
$discord_msg = strtr($discord_template, [
|
}
|
||||||
'{{COMMENT_AUTHOR}}' => $author,
|
|
||||||
'{{COMMENT_TEXT}}' => $text,
|
.user-box label {
|
||||||
'{{POST_TITLE}}' => $post_title,
|
display: block;
|
||||||
'{{SITE_NAME}}' => $site,
|
margin-bottom: 5px;
|
||||||
'{{POST_URL}}' => $post_url,
|
}
|
||||||
'{{COMMENT_DATE}}' => $comment_date,
|
|
||||||
'{{COMMENT_URL}}' => $comment_url,
|
.user-box input,
|
||||||
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
|
.user-box textarea {
|
||||||
]);
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
// Nachricht per E-Mail verschicken
|
margin-bottom: 10px;
|
||||||
$email_message = get_option('wp_email_message');
|
border: 1px solid #ddd;
|
||||||
$email_message = strtr($email_message, [
|
border-radius: 5px;
|
||||||
'{{COMMENT_AUTHOR}}' => $author,
|
}
|
||||||
'{{COMMENT_TEXT}}' => $text,
|
|
||||||
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
|
.regular-text {
|
||||||
'{{POST_TITLE}}' => $post_title,
|
width: 100%;
|
||||||
'{{SITE_NAME}}' => $site,
|
}
|
||||||
'{{POST_URL}}' => $post_url,
|
|
||||||
'{{COMMENT_DATE}}' => $comment_date,
|
.large-text {
|
||||||
'{{COMMENT_URL}}' => $comment_url
|
width: 100%;
|
||||||
]);
|
height: 150px;
|
||||||
|
}
|
||||||
// Telegram-Nachricht
|
</style>
|
||||||
$telegram_message = get_option('wp_telegram_message');
|
<?php
|
||||||
$telegram_message = strtr($telegram_message, [
|
}
|
||||||
'{{COMMENT_AUTHOR}}' => $author,
|
|
||||||
'{{COMMENT_TEXT}}' => $text,
|
function wp_multi_comment_notifications_register_settings() {
|
||||||
'{{USER_NAME}}' => $user_name, // Benutzername aus den Optionen
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
'{{POST_TITLE}}' => $post_title,
|
register_setting('wp_multi_comment_notifications_settings_group', "wp_user_{$i}_name");
|
||||||
'{{SITE_NAME}}' => $site,
|
register_setting('wp_multi_comment_notifications_settings_group', "wp_user_{$i}_email");
|
||||||
'{{POST_URL}}' => $post_url,
|
register_setting('wp_multi_comment_notifications_settings_group', "wp_user_{$i}_telegram_chat_id");
|
||||||
'{{COMMENT_DATE}}' => $comment_date,
|
}
|
||||||
'{{COMMENT_URL}}' => $comment_url
|
register_setting('wp_multi_comment_notifications_settings_group', 'wp_telegram_token');
|
||||||
]);
|
register_setting('wp_multi_comment_notifications_settings_group', 'wp_email_message');
|
||||||
$telegram_chat_id = get_option('wp_user_1_telegram_chat_id'); // Beispiel für den ersten Benutzer
|
register_setting('wp_multi_comment_notifications_settings_group', 'wp_telegram_message');
|
||||||
wp_remote_post("https://api.telegram.org/bot" . get_option('wp_telegram_token') . "/sendMessage", [
|
register_setting('wp_multi_comment_notifications_settings_group', 'wp_backend_button_url');
|
||||||
'body' => [
|
register_setting('wp_multi_comment_notifications_settings_group', 'wp_email_logo_url');
|
||||||
'chat_id' => $telegram_chat_id,
|
}
|
||||||
'text' => $telegram_message
|
add_action('admin_init', 'wp_multi_comment_notifications_register_settings');
|
||||||
]
|
|
||||||
]);
|
// 2. Kommentar-Benachrichtigung bei neuem Kommentar
|
||||||
}
|
function wp_multi_comment_notifications_on_comment($comment_ID) {
|
||||||
|
$comment = get_comment($comment_ID);
|
||||||
add_action('comment_post', 'wp_multi_comment_notifications_on_comment');
|
$comment_author = $comment->comment_author;
|
||||||
|
$comment_text = $comment->comment_content;
|
||||||
/** -------------------------
|
$site_name = get_bloginfo('name');
|
||||||
* Testnachrichten senden
|
$backend_url = get_option('wp_backend_button_url');
|
||||||
* ------------------------- */
|
$logo_url = esc_url(get_option('wp_email_logo_url'));
|
||||||
add_action('admin_init', function () {
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
for ($i = 1; $i <= 6; $i++) {
|
$user_name = get_option("wp_user_{$i}_name");
|
||||||
if (isset($_POST["send_test_message_user_$i"])) {
|
$user_email = get_option("wp_user_{$i}_email");
|
||||||
wp_multi_comment_notifications_send_test_message($i);
|
$telegram_chat_id = get_option("wp_user_{$i}_telegram_chat_id");
|
||||||
}
|
|
||||||
}
|
$email_message = str_replace(
|
||||||
}
|
['{{COMMENT_AUTHOR}}', '{{COMMENT_TEXT}}', '{{USER_NAME}}'],
|
||||||
});
|
[$comment_author, $comment_text, $user_name],
|
||||||
|
get_option('wp_email_message')
|
||||||
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");
|
if (!empty($backend_url)) {
|
||||||
$chat_id = get_option("wp_user_{$user_number}_telegram_chat_id");
|
$email_message .= "\n\nWeitere Details hier: " . $backend_url;
|
||||||
$discord_webhook = get_option('wp_discord_webhook_url');
|
}
|
||||||
$token = get_option('wp_telegram_token');
|
|
||||||
$button_url = get_option('wp_backend_button_url');
|
if ($user_email) {
|
||||||
|
$html_message = '';
|
||||||
$message = "Dies ist eine Testnachricht für $name.";
|
if (!empty($logo_url)) {
|
||||||
|
$html_message .= '<img src="' . $logo_url . '" alt="Logo" style="max-width: 100%; height: auto; margin-bottom: 20px;"><br>';
|
||||||
if ($email) {
|
}
|
||||||
wp_mail($email, 'Testnachricht', $message);
|
|
||||||
}
|
$html_message .= nl2br(esc_html($email_message));
|
||||||
|
|
||||||
if ($chat_id) {
|
$headers = [
|
||||||
wp_multi_comment_notifications_send_telegram($token, $chat_id, 0, $message);
|
'Content-Type: text/html; charset=UTF-8',
|
||||||
}
|
'From: ' . $site_name . ' <no-reply@' . $_SERVER['SERVER_NAME'] . '>'
|
||||||
|
];
|
||||||
if ($discord_webhook) {
|
|
||||||
wp_multi_comment_notifications_send_discord($discord_webhook, $message);
|
wp_mail(trim($user_email), 'Neuer Kommentar', $html_message, $headers);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
$telegram_message = str_replace(
|
||||||
/** -------------------------
|
['{{COMMENT_AUTHOR}}', '{{COMMENT_TEXT}}', '{{USER_NAME}}'],
|
||||||
* Telegram-Nachricht mit Button
|
[$comment_author, $comment_text, $user_name],
|
||||||
* ------------------------- */
|
get_option('wp_telegram_message')
|
||||||
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');
|
if ($telegram_chat_id) {
|
||||||
|
wp_multi_comment_notifications_send_telegram(get_option('wp_telegram_token'), $telegram_chat_id, $comment_ID, $telegram_message);
|
||||||
$data = [
|
}
|
||||||
'chat_id' => $chat_id,
|
}
|
||||||
'text' => $message,
|
}
|
||||||
'parse_mode' => 'HTML'
|
add_action('wp_insert_comment', 'wp_multi_comment_notifications_on_comment', 10, 1);
|
||||||
];
|
|
||||||
|
// 3. Telegram Nachricht senden (mit Inline-Button)
|
||||||
if ($button_url) {
|
function wp_multi_comment_notifications_send_telegram($token, $chat_id, $comment_ID, $message) {
|
||||||
$data['reply_markup'] = json_encode([
|
$url = "https://api.telegram.org/bot$token/sendMessage";
|
||||||
'inline_keyboard' => [[['text' => 'Zum Backend', 'url' => $button_url]]]
|
$button_url = get_option('wp_backend_button_url');
|
||||||
]);
|
$inline_button = [];
|
||||||
}
|
|
||||||
|
if (!empty($button_url)) {
|
||||||
wp_remote_post($url, [
|
$inline_button = [
|
||||||
'body' => $data,
|
'inline_keyboard' => [
|
||||||
'timeout' => 10,
|
[
|
||||||
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
|
['text' => 'Zum Backend', 'url' => $button_url]
|
||||||
]);
|
]
|
||||||
}
|
]
|
||||||
|
];
|
||||||
/** -------------------------
|
}
|
||||||
* Discord-Nachricht senden
|
|
||||||
* ------------------------- */
|
$data = [
|
||||||
function wp_multi_comment_notifications_send_discord($webhook_url, $message) {
|
'chat_id' => $chat_id,
|
||||||
$payload = json_encode(['content' => $message]);
|
'text' => $message,
|
||||||
|
];
|
||||||
wp_remote_post($webhook_url, [
|
|
||||||
'headers' => ['Content-Type' => 'application/json'],
|
if (!empty($inline_button)) {
|
||||||
'body' => $payload,
|
$data['reply_markup'] = json_encode($inline_button);
|
||||||
'timeout' => 10,
|
}
|
||||||
]);
|
|
||||||
}
|
$options = [
|
||||||
|
'http' => [
|
||||||
|
'method' => 'POST',
|
||||||
|
'content' => http_build_query($data),
|
||||||
|
'header' => "Content-Type: application/x-www-form-urlencoded\r\n"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$context = stream_context_create($options);
|
||||||
|
$response = file_get_contents($url, false, $context);
|
||||||
|
|
||||||
|
if ($response === FALSE) {
|
||||||
|
error_log("Fehler bei Telegram-Nachricht: $url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user