diff --git a/wp-ingame-shop/wp-ingame-shop.php b/wp-ingame-shop/wp-ingame-shop.php index af52521..915f41a 100644 --- a/wp-ingame-shop/wp-ingame-shop.php +++ b/wp-ingame-shop/wp-ingame-shop.php @@ -2,11 +2,118 @@ /* Plugin Name: WP Ingame Shop Pro - NO RCON & CUSTOM CURRENCY Description: Vollautomatischer Shop mit Warenkorb. -Version: 1.0.1 +Version: 1.0.2 Author: M_Viper */ if (!defined('ABSPATH')) exit; +// =============================== +// WIS PRO - UPDATE NOTICE SYSTEM +// =============================== + +// Plugin-Version aus Header lesen +function wis_get_plugin_version() { + if ( ! function_exists( 'get_plugin_data' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + $plugin_data = get_plugin_data( __FILE__ ); + return $plugin_data['Version'] ?? '0.0.0'; +} + +// Cache manuell leeren +function wis_clear_update_cache() { + if ( isset($_GET['wis_clear_cache']) && current_user_can('manage_options') ) { + check_admin_referer('wis_clear_cache_action'); + delete_transient('wis_latest_release'); + wp_redirect( admin_url('plugins.php') ); + exit; + } +} +add_action('admin_init', 'wis_clear_update_cache'); + +// Neueste Release-Infos von Gitea holen +function wis_get_latest_release_info( $force_refresh = false ) { + $transient_key = 'wis_latest_release'; + + if ( $force_refresh ) { + delete_transient( $transient_key ); + } + + $release_info = get_transient( $transient_key ); + + if ( false === $release_info ) { + $response = wp_remote_get( + 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/WP-Ingame-Shop-Pro/releases/latest', + ['timeout' => 10] + ); + + if ( ! is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response) ) { + $body = wp_remote_retrieve_body($response); + $data = json_decode($body, true); + + if ( $data && isset($data['tag_name']) ) { + $tag = ltrim( $data['tag_name'], 'vV' ); + + $release_info = [ + 'version' => $tag, + 'download_url' => $data['zipball_url'] ?? '', + 'notes' => $data['body'] ?? '', + 'published_at' => $data['published_at'] ?? '', + ]; + + set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS ); + } else { + set_transient( $transient_key, [], HOUR_IN_SECONDS ); + } + } else { + set_transient( $transient_key, [], HOUR_IN_SECONDS ); + } + } + + return $release_info; +} + +// Admin-Update-Hinweis anzeigen +function wis_show_update_notice() { + if ( ! current_user_can('manage_options') ) { + return; + } + + $current_version = wis_get_plugin_version(); + $latest_release = wis_get_latest_release_info(); + + if ( ! empty($latest_release['version']) && version_compare($current_version, $latest_release['version'], '<') ) { + + $refresh_url = wp_nonce_url( + admin_url('plugins.php?wis_clear_cache=1'), + 'wis_clear_cache_action' + ); + ?> +
+

WP Ingame Shop Pro – Update verfügbar

+

+ Installiert:
+ Neueste Version: +

+

+ + Update herunterladen + + + Release Notes + + + Jetzt neu prüfen + +

+
+