wp-multi-comment-notifications.php aktualisiert
This commit is contained in:
parent
b7ddf09646
commit
38a9395c59
@ -26,92 +26,6 @@ if (!defined('ABSPATH')) {
|
|||||||
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__));
|
||||||
|
|
||||||
// Abhängigkeit prüfen und WP Multi Toolkit installieren/aktivieren
|
|
||||||
function wpmcn_check_dependency() {
|
|
||||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
|
||||||
$required_plugin = 'WP-Multi-Toolkit/wp-multi-toolkit.php';
|
|
||||||
$download_url = 'https://git.viper.ipv64.net/M_Viper/wp-multi-toolkit/releases/latest/download/wp-multi-toolkit.zip'; // Direkter Download-Link zur neuesten ZIP
|
|
||||||
|
|
||||||
// Prüfen, ob WP Multi Toolkit installiert ist
|
|
||||||
if (!file_exists(WP_PLUGIN_DIR . '/' . $required_plugin)) {
|
|
||||||
// Plugin ist nicht installiert, versuche es zu installieren
|
|
||||||
wpmcn_install_required_plugin($download_url, $required_plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prüfen, ob WP Multi Toolkit aktiv ist
|
|
||||||
if (!is_plugin_active($required_plugin)) {
|
|
||||||
// Plugin ist installiert, aber nicht aktiv, aktiviere es
|
|
||||||
$result = activate_plugin($required_plugin);
|
|
||||||
if (is_wp_error($result)) {
|
|
||||||
// Fehlerbehandlung: Admin-Benachrichtigung
|
|
||||||
add_action('admin_notices', function () use ($result) {
|
|
||||||
echo '<div class="notice notice-error"><p>' . sprintf(
|
|
||||||
__('Fehler beim Aktivieren von WP Multi Toolkit: %s', 'wp-multi-comment-notifications'),
|
|
||||||
esc_html($result->get_error_message())
|
|
||||||
) . '</p></div>';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 '<div class="notice notice-error"><p>' . __('Direkter Dateizugriff erforderlich, um WP Multi Toolkit zu installieren. Bitte überprüfe die Dateisystemkonfiguration.', 'wp-multi-comment-notifications') . '</p></div>';
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$creds = request_filesystem_credentials(admin_url(), '', false, false, null);
|
|
||||||
if (!WP_Filesystem($creds)) {
|
|
||||||
add_action('admin_notices', function () {
|
|
||||||
echo '<div class="notice notice-error"><p>' . __('Dateisystemzugriff fehlgeschlagen. WP Multi Toolkit konnte nicht installiert werden.', 'wp-multi-comment-notifications') . '</p></div>';
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$upgrader = new Plugin_Upgrader();
|
|
||||||
$result = $upgrader->install($download_url);
|
|
||||||
|
|
||||||
if (is_wp_error($result)) {
|
|
||||||
add_action('admin_notices', function () use ($result) {
|
|
||||||
echo '<div class="notice notice-error"><p>' . sprintf(
|
|
||||||
__('Fehler beim Installieren von WP Multi Toolkit: %s', 'wp-multi-comment-notifications'),
|
|
||||||
esc_html($result->get_error_message())
|
|
||||||
) . '</p></div>';
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Installation erfolgreich, aktiviere das Plugin
|
|
||||||
$activate = activate_plugin($plugin_file);
|
|
||||||
if (is_wp_error($activate)) {
|
|
||||||
add_action('admin_notices', function () use ($activate) {
|
|
||||||
echo '<div class="notice notice-error"><p>' . sprintf(
|
|
||||||
__('Fehler beim Aktivieren von WP Multi Toolkit nach Installation: %s', 'wp-multi-comment-notifications'),
|
|
||||||
esc_html($activate->get_error_message())
|
|
||||||
) . '</p></div>';
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
add_action('admin_notices', function () {
|
|
||||||
echo '<div class="notice notice-success"><p>' . __('WP Multi Toolkit wurde erfolgreich installiert und aktiviert.', 'wp-multi-comment-notifications') . '</p></div>';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
// 1. Plugin-Optionen im Admin-Bereich unter dem Menü "Kommentare" hinzufügen
|
||||||
function wp_multi_comment_notifications_menu() {
|
function wp_multi_comment_notifications_menu() {
|
||||||
@ -132,8 +46,8 @@ function wp_multi_comment_notifications_settings_page() {
|
|||||||
<h1>WP Multi Comment Notifications Einstellungen</h1>
|
<h1>WP Multi Comment Notifications Einstellungen</h1>
|
||||||
<form method="post" action="options.php">
|
<form method="post" action="options.php">
|
||||||
<?php
|
<?php
|
||||||
settings_fields('wp_multi_comment_notifications_settings_group');
|
settings_fields( 'wp_multi_comment_notifications_settings_group' );
|
||||||
do_settings_sections('wp-multi-comment-notifications');
|
do_settings_sections( 'wp-multi-comment-notifications' );
|
||||||
?>
|
?>
|
||||||
<h3>Telegram Bot Token</h3>
|
<h3>Telegram Bot Token</h3>
|
||||||
<label for="wp_telegram_token">Telegram Bot Token</label>
|
<label for="wp_telegram_token">Telegram Bot Token</label>
|
||||||
@ -147,6 +61,7 @@ function wp_multi_comment_notifications_settings_page() {
|
|||||||
<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> für dynamische Daten.</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> für dynamische Daten.</p>
|
||||||
@ -178,7 +93,7 @@ function wp_multi_comment_notifications_settings_page() {
|
|||||||
<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")); ?>" />
|
<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")); ?>" />
|
||||||
|
|
||||||
<!-- Button für individuelle Testnachricht -->
|
<!-- Button für individuelle Testnachricht -->
|
||||||
<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") ?: "User $i"); ?>" />
|
<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")); ?>" />
|
||||||
</div>
|
</div>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
</div>
|
</div>
|
||||||
@ -244,6 +159,7 @@ 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');
|
||||||
|
|
||||||
@ -289,9 +205,9 @@ function wp_multi_comment_notifications_on_comment($comment_ID) {
|
|||||||
$html = $logo ? "<img src='$logo' style='max-width:100%;margin-bottom:20px;'><br>" : '';
|
$html = $logo ? "<img src='$logo' style='max-width:100%;margin-bottom:20px;'><br>" : '';
|
||||||
$html .= nl2br(esc_html($email_msg));
|
$html .= nl2br(esc_html($email_msg));
|
||||||
$headers = [
|
$headers = [
|
||||||
'Content-Type: text/html; charset=UTF-8',
|
'Content-Type: text/html; charset=UTF-8',
|
||||||
'From' => get_option('admin_email'),
|
'From' => get_option( 'admin_email' ),
|
||||||
];
|
];
|
||||||
wp_mail($email, 'Neuer Kommentar', $html, $headers);
|
wp_mail($email, 'Neuer Kommentar', $html, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,6 +225,7 @@ function wp_multi_comment_notifications_on_comment($comment_ID) {
|
|||||||
}
|
}
|
||||||
add_action('wp_insert_comment', 'wp_multi_comment_notifications_on_comment', 10, 1);
|
add_action('wp_insert_comment', 'wp_multi_comment_notifications_on_comment', 10, 1);
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------
|
/** -------------------------
|
||||||
* Testnachrichten senden
|
* Testnachrichten senden
|
||||||
* ------------------------- */
|
* ------------------------- */
|
||||||
@ -345,6 +262,7 @@ function wp_multi_comment_notifications_send_test_message($user_number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------
|
/** -------------------------
|
||||||
* Telegram-Nachricht mit Button
|
* Telegram-Nachricht mit Button
|
||||||
* ------------------------- */
|
* ------------------------- */
|
||||||
@ -371,6 +289,7 @@ 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