diff --git a/wp-multi-comment-notifications.php b/wp-multi-comment-notifications.php index b0e5a32..90edaf3 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.1 + * Version: 1.3 * Author: M_Viper * Author URI: https://m-viper.de * Requires at least: 6.7.2 @@ -19,129 +19,99 @@ * - Telegram: https://t.me/M_Viper04 */ -if ( ! defined( 'ABSPATH' ) ) { +if (!defined('ABSPATH')) { exit; } -/** - * Dashboard Widget – Update Info für dieses Plugin - */ -function wp_multi_cmn_dashboard_widget() { - wp_add_dashboard_widget( - 'wp_multi_cmn_update_widget', - __('WP Multi Comment Notifications – Update Info', 'wp-multi-comment-notifications'), - 'wp_multi_cmn_update_dashboard_widget_content' - ); -} -add_action('wp_dashboard_setup', 'wp_multi_cmn_dashboard_widget'); +define('WPMCN_PLUGIN_VERSION', '1.2'); +define('WPMCN_PLUGIN_DIR', plugin_dir_path(__FILE__)); -// Cron-Intervall „stündlich“ definieren -add_filter('cron_schedules', function ($schedules) { - $schedules['hourly'] = array( - 'interval' => 3600, - 'display' => __('Stündlich', 'wp-multi-comment-notifications'), - ); - return $schedules; -}); +// 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 -// Cron-Event planen -function wp_multi_cmn_schedule_update_check() { - if (!wp_next_scheduled('wp_multi_cmn_update_check_event')) { - wp_schedule_event(time(), 'hourly', 'wp_multi_cmn_update_check_event'); - } -} -add_action('wp', 'wp_multi_cmn_schedule_update_check'); - -// Gitea API aufrufen -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'; - $response = wp_remote_get($api_url, array('timeout' => 10)); - - if (is_wp_error($response)) { - error_log('WP Multi Comment Notifications – Update Fehler: ' . $response->get_error_message()); - return false; + // 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); } - $body = wp_remote_retrieve_body($response); - $data = json_decode($body, true); - - if (!is_array($data)) { - error_log('WP Multi Comment Notifications – Ungültige API-Antwort'); - return false; - } - - foreach ($data as $release) { - if (!$show_prereleases && isset($release['prerelease']) && $release['prerelease']) { - continue; - } - if (!empty($release['tag_name'])) { - return $release; + // 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 '
' . sprintf( + __('Fehler beim Aktivieren von WP Multi Toolkit: %s', 'wp-multi-comment-notifications'), + esc_html($result->get_error_message()) + ) . '
Fehler beim Abrufen der Update-Informationen.
'; + // 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') . '
' . __('Dateisystemzugriff fehlgeschlagen. WP Multi Toolkit konnte nicht installiert werden.', 'wp-multi-comment-notifications') . '
Du verwendest die aktuelle Version: ' . esc_html($installed_version) . '
'; + $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()) + ) . '
Neue Version verfügbar: ' . esc_html($latest_version) . '
'; - echo 'Installiert: ' . esc_html($installed_version) . '
'; - - if ($is_prerelease && $show_prereleases) { - echo 'Hinweis: Dies ist ein PreRelease.
'; + // 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()) + ) . '
' . __('WP Multi Toolkit wurde erfolgreich installiert und aktiviert.', 'wp-multi-comment-notifications') . '
Release Notes:
' . nl2br(esc_html($release_notes)) . '