diff --git a/wp-multi-comment-notifications.php b/wp-multi-comment-notifications.php new file mode 100644 index 0000000..1d1d4fe --- /dev/null +++ b/wp-multi-comment-notifications.php @@ -0,0 +1,359 @@ + 3600, + 'display' => __('Stündlich', 'wp-multi-comment-notifications'), + ); + return $schedules; +}); + +// 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; + } + + $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; + } + } + + return null; +} + +// Cron Callback +function wp_multi_cmn_update_check() { + if (!function_exists('get_plugin_data')) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + $plugin_data = get_plugin_data(__FILE__); + $installed_version = $plugin_data['Version']; + $show_prereleases = get_option('wp_multi_cmn_show_prereleases', false); + + $release = wp_multi_cmn_fetch_latest_release($show_prereleases); + + if ($release) { + update_option('wp_multi_cmn_latest_version', $release['tag_name']); + update_option('wp_multi_cmn_release_notes', $release['body']); + update_option('wp_multi_cmn_is_prerelease', $release['prerelease']); + } +} +add_action('wp_multi_cmn_update_check_event', 'wp_multi_cmn_update_check'); + +// Widget Callback +function wp_multi_cmn_update_dashboard_widget_content() { + if (!function_exists('get_plugin_data')) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + $plugin_data = get_plugin_data(__FILE__); + $installed_version = $plugin_data['Version']; + $show_prereleases = get_option('wp_multi_cmn_show_prereleases', false); + + $release = wp_multi_cmn_fetch_latest_release($show_prereleases); + + if ($release === false) { + echo '
Fehler beim Abrufen der Update-Informationen.
'; + return; + } + + $latest_version = $release['tag_name']; + $release_notes = isset($release['body']) ? $release['body'] : ''; + $is_prerelease = isset($release['prerelease']) && $release['prerelease']; + + if (version_compare($installed_version, $latest_version, '>=')) { + echo 'Du verwendest die aktuelle Version: ' . esc_html($installed_version) . '
'; + } else { + echo '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.
'; + } + + if (!empty($release_notes)) { + echo 'Release Notes:
' . nl2br(esc_html($release_notes)) . '