wp-multi-comment-notifications.php aktualisiert
This commit is contained in:
parent
4cd6849f1f
commit
5da4627c4c
@ -3,7 +3,7 @@
|
|||||||
* 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 & Discord. Ideal für Teams, die schnell informiert werden wollen.
|
||||||
* Version: 1.3
|
* Version: 1.4
|
||||||
* 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
|
||||||
@ -65,7 +65,6 @@ if (wp_multi_comment_notifications_check_dependency()) {
|
|||||||
define('WPMCN_PLUGIN_VERSION', '1.2');
|
define('WPMCN_PLUGIN_VERSION', '1.2');
|
||||||
define('WPMCN_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
define('WPMCN_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||||
|
|
||||||
|
|
||||||
// 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen
|
// 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen
|
||||||
function wp_multi_comment_notifications_menu() {
|
function wp_multi_comment_notifications_menu() {
|
||||||
add_submenu_page(
|
add_submenu_page(
|
||||||
@ -98,16 +97,15 @@ function wp_multi_comment_notifications_settings_page() {
|
|||||||
|
|
||||||
<h3>Nachricht für Discord</h3>
|
<h3>Nachricht für Discord</h3>
|
||||||
<textarea name="wp_discord_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_discord_message')); ?></textarea>
|
<textarea name="wp_discord_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_discord_message')); ?></textarea>
|
||||||
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code> für dynamische Daten.</p>
|
<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>
|
||||||
|
|
||||||
|
|
||||||
<h3>Nachricht für E-Mail</h3>
|
<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>
|
<textarea name="wp_email_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_email_message')); ?></textarea>
|
||||||
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code> für dynamische Daten.</p>
|
<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>
|
||||||
|
|
||||||
<h3>Nachricht für Telegram</h3>
|
<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>
|
<textarea name="wp_telegram_message" rows="5" class="large-text"><?php echo esc_textarea(get_option('wp_telegram_message')); ?></textarea>
|
||||||
<p>Verwende Platzhalter wie <code>{{COMMENT_AUTHOR}}</code>, <code>{{COMMENT_TEXT}}</code>, <code>{{USER_NAME}}</code> für dynamische Daten.</p>
|
<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>
|
||||||
|
|
||||||
<h3>Backend-Button URL</h3>
|
<h3>Backend-Button URL</h3>
|
||||||
<label for="wp_backend_button_url">URL für Backend Button</label>
|
<label for="wp_backend_button_url">URL für Backend Button</label>
|
||||||
@ -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_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_webhook_url');
|
||||||
register_setting('wp_multi_comment_notifications_settings_group', 'wp_discord_message');
|
register_setting('wp_multi_comment_notifications_settings_group', 'wp_discord_message');
|
||||||
|
|
||||||
}
|
}
|
||||||
add_action('admin_init', 'wp_multi_comment_notifications_register_settings');
|
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);
|
$comment = get_comment($comment_ID);
|
||||||
$author = $comment->comment_author;
|
$author = $comment->comment_author;
|
||||||
$text = $comment->comment_content;
|
$text = $comment->comment_content;
|
||||||
|
$post_id = $comment->comment_post_ID;
|
||||||
|
$post_title = get_the_title($post_id); // Titel des Beitrags
|
||||||
$site = get_bloginfo('name');
|
$site = get_bloginfo('name');
|
||||||
$url = get_option('wp_backend_button_url');
|
$url = get_option('wp_backend_button_url');
|
||||||
$logo = esc_url(get_option('wp_email_logo_url'));
|
$logo = esc_url(get_option('wp_email_logo_url'));
|
||||||
$discord_webhook = get_option('wp_discord_webhook_url');
|
$discord_webhook = get_option('wp_discord_webhook_url');
|
||||||
$discord_template = get_option('wp_discord_message');
|
$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
|
// Nachricht für Discord nur einmal senden
|
||||||
if ($discord_webhook && $discord_template) {
|
if ($discord_webhook && $discord_template) {
|
||||||
$discord_msg = strtr($discord_template, [
|
$discord_msg = strtr($discord_template, [
|
||||||
'{{COMMENT_AUTHOR}}' => $author,
|
'{{COMMENT_AUTHOR}}' => $author,
|
||||||
'{{COMMENT_TEXT}}' => $text,
|
'{{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}}' => '<a href="' . $comment_url . '" target="_blank">Kommentar ansehen</a>' // 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
|
// Telegram-Nachricht
|
||||||
for ($i = 1; $i <= 6; $i++) {
|
$telegram_message = get_option('wp_telegram_message');
|
||||||
$name = get_option("wp_user_{$i}_name");
|
$telegram_message = strtr($telegram_message, [
|
||||||
$email = get_option("wp_user_{$i}_email");
|
'{{COMMENT_AUTHOR}}' => $author,
|
||||||
$chat_id = get_option("wp_user_{$i}_telegram_chat_id");
|
'{{COMMENT_TEXT}}' => $text,
|
||||||
|
'{{USER_NAME}}' => $author, // Nur für Testzwecke
|
||||||
// Nachricht für E-Mail & Telegram
|
'{{POST_TITLE}}' => $post_title,
|
||||||
$replacements = [
|
'{{SITE_NAME}}' => $site,
|
||||||
'{{COMMENT_AUTHOR}}' => $author,
|
'{{POST_URL}}' => $post_url,
|
||||||
'{{COMMENT_TEXT}}' => $text,
|
'{{COMMENT_DATE}}' => $comment_date,
|
||||||
'{{USER_NAME}}' => $name,
|
'{{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
|
||||||
$email_msg = strtr(get_option('wp_email_message'), $replacements);
|
wp_remote_post("https://api.telegram.org/bot" . get_option('wp_telegram_token') . "/sendMessage", [
|
||||||
if ($url) $email_msg .= "\n\nWeitere Details hier: $url";
|
'body' => [
|
||||||
|
'chat_id' => $telegram_chat_id,
|
||||||
if ($email) {
|
'text' => $telegram_message
|
||||||
$html = $logo ? "<img src='$logo' style='max-width:100%;margin-bottom:20px;'><br>" : '';
|
]
|
||||||
$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);
|
|
||||||
|
|
||||||
|
add_action('comment_post', 'wp_multi_comment_notifications_on_comment');
|
||||||
|
|
||||||
/** -------------------------
|
/** -------------------------
|
||||||
* Testnachrichten senden
|
* Testnachrichten senden
|
||||||
@ -301,7 +311,6 @@ function wp_multi_comment_notifications_send_test_message($user_number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------
|
/** -------------------------
|
||||||
* Telegram-Nachricht mit Button
|
* Telegram-Nachricht mit Button
|
||||||
* ------------------------- */
|
* ------------------------- */
|
||||||
@ -328,7 +337,6 @@ function wp_multi_comment_notifications_send_telegram($token, $chat_id, $comment
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------
|
/** -------------------------
|
||||||
* Discord-Nachricht senden
|
* Discord-Nachricht senden
|
||||||
* ------------------------- */
|
* ------------------------- */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user