wp-ingame-shop/wp-ingame-shop.php aktualisiert

This commit is contained in:
2026-04-02 19:50:12 +00:00
parent b398a706fe
commit 47915c6dd8

View File

@@ -2,26 +2,226 @@
/*
Plugin Name: WP Ingame Shop Pro
Plugin URI:https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro
Description: Vollautomatischer Shop mit Warenkorb + eigener DB-Struktur (SPIGOT COMPATIBLE)
Version: 2.1.2
Description: Vollautomatischer Shop mit Warenkorb (kein echtgeld Handel)
Version: 2.1.3
Author: M_Viper
Author URI: https://m-viper.de
Requires at least: 6.9.1
Tested up to: 6.9.1
Requires PHP: 7.4
License: GPL-2.0-or-later
PHP Version: 7.4
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: WP-Ingame-Shop-Pro
Text Domain: wp-ingame-shop-pro
Tags: shop, items, minecraft, coupons, deals, categories
Support: [Discord Support](https://discord.com/invite/FdRs4BRd8D)
Support: [Telegram Support](https://t.me/M_Viper04)
*/
if (!defined('ABSPATH')) exit;
// Plugin Constants
define('WIS_VERSION', '2.1.2');
define('WIS_VERSION', '2.1.3');
define('WIS_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('WIS_PLUGIN_URL', plugin_dir_url(__FILE__));
// ===========================================================
// DASHBOARD WIDGET & UPDATES
// ===========================================================
class WIS_Dashboard {
private static $update_url = 'https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro/releases';
private static $api_url = 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/WP-Ingame-Shop-Pro/releases/latest';
private static $transient_name = 'wis_update_check';
public static function init() {
add_action('wp_dashboard_setup', [__CLASS__, 'add_dashboard_widget']);
add_action('admin_init', [__CLASS__, 'check_for_update']);
// AJAX Handler für Cache leeren
add_action('wp_ajax_wis_clear_cache', [__CLASS__, 'ajax_clear_cache']);
}
// Button im Dashboard: Cache leeren
public static function ajax_clear_cache() {
check_ajax_referer('wis_clear_cache_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_send_json_error('Keine Berechtigung.');
}
// Leere den Object Cache
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
}
// Optional: Leere auch unseren Transienten für den Update-Check, damit er neu lädt
delete_transient(self::$transient_name);
wp_send_json_success(['message' => 'Cache erfolgreich geleert!']);
}
// Prüfe auf Updates (läuft im Admin-Hintergrund)
public static function check_for_update() {
$update_data = get_transient(self::$transient_name);
if (false === $update_data) {
$response = wp_remote_get(self::$api_url, ['timeout' => 10]);
if (is_wp_error($response)) {
return; // Fehler beim Abrufen, nichts tun
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body);
if (isset($data->tag_name) && isset($data->html_url)) {
// Entferne 'v' vom Tag (z.B. v2.1.3 -> 2.1.3)
$remote_version = ltrim($data->tag_name, 'v');
$update_data = [
'new_version' => $remote_version,
'url' => self::$update_url,
'package_url' => isset($data->assets[0]->browser_download_url) ? $data->assets[0]->browser_download_url : '',
'changelog' => isset($data->body) ? substr($data->body, 0, 200) . '...' : ''
];
// Speichere für 12 Stunden
set_transient(self::$transient_name, $update_data, 12 * HOUR_IN_SECONDS);
}
}
}
// Zeige Admin Notice wenn Update verfügbar
public static function show_update_notice() {
$update_data = get_transient(self::$transient_name);
if ($update_data && version_compare(WIS_VERSION, $update_data['new_version'], '<')) {
?>
<div class="notice notice-info is-dismissible">
<p>
<strong>🚀 WP Ingame Shop Pro Update verfügbar!</strong><br>
Neue Version: <?php echo esc_html($update_data['new_version']); ?> (Du hast <?php echo WIS_VERSION; ?>)<br>
<a href="<?php echo esc_url($update_data['url']); ?>" target="_blank">Hier im Git Repository ansehen</a> oder unten im Widget Details prüfen.
</p>
</div>
<?php
}
}
// Widget registrieren
public static function add_dashboard_widget() {
wp_add_dashboard_widget(
'wis_dashboard_widget',
'🛒 WP Ingame Shop Pro Dashboard',
[__CLASS__, 'render_widget']
);
}
// Widget Inhalt rendern
public static function render_widget() {
global $wpdb;
$update_data = get_transient(self::$transient_name);
// Statistiken holen
$stats = [
'items' => $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}wis_items WHERE status = 'publish'"),
'orders' => $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}wis_orders WHERE status = 'completed'"),
'pending' => $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}wis_orders WHERE status IN ('pending', 'claimed')"),
'revenue' => $wpdb->get_var("SELECT SUM(price) FROM {$wpdb->prefix}wis_orders WHERE status = 'completed'"),
];
$currency = get_option('wis_currency_name', 'Coins');
// Update Status bestimmen
$update_html = '<span style="color:green;">✅ Aktuell (v' . WIS_VERSION . ')</span>';
if ($update_data && version_compare(WIS_VERSION, $update_data['new_version'], '<')) {
$update_html = '<span style="color:#d63638; font-weight:bold;">⚠️ Update verfügbar!</span>';
}
?>
<style>
.wis-dash-stats { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; }
.wis-stat-box { flex: 1; min-width: 100px; background: #f9f9f9; padding: 10px; border-radius: 5px; text-align: center; border: 1px solid #eee; }
.wis-stat-num { display: block; font-size: 1.5em; font-weight: bold; color: #333; }
.wis-stat-label { font-size: 0.85em; color: #666; }
.wis-dash-actions { margin-top: 15px; padding-top: 15px; border-top: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
</style>
<div class="wis-dash-stats">
<div class="wis-stat-box">
<span class="wis-stat-num"><?php echo intval($stats['items']); ?></span>
<span class="wis-stat-label">Items</span>
</div>
<div class="wis-stat-box">
<span class="wis-stat-num"><?php echo intval($stats['orders']); ?></span>
<span class="wis-stat-label">Bestellungen</span>
</div>
<div class="wis-stat-box">
<span class="wis-stat-num"><?php echo intval($stats['pending']); ?></span>
<span class="wis-stat-label">Offen</span>
</div>
<div class="wis-stat-box">
<span class="wis-stat-num"><?php echo number_format($stats['revenue']); ?></span>
<span class="wis-stat-label">Umsatz (<?php echo esc_html($currency); ?>)</span>
</div>
</div>
<p style="margin-bottom: 10px;">
<strong>Status:</strong> <?php echo $update_html; ?>
</p>
<?php if ($update_data && version_compare(WIS_VERSION, $update_data['new_version'], '<')): ?>
<div style="background:#fff3cd; color:#856404; padding:10px; border-radius:4px; margin-bottom:10px; font-size:13px;">
<strong>Neue Version <?php echo esc_html($update_data['new_version']); ?></strong><br>
<a href="<?php echo esc_url($update_data['url']); ?>" target="_blank">Updates ansehen</a>
</div>
<?php endif; ?>
<div class="wis-dash-actions">
<a href="<?php echo admin_url('admin.php?page=wis_orders'); ?>" class="button">Bestellungen ansehen</a>
<button type="button" id="wis-clear-cache-btn" class="button button-secondary button-small">
🔄 Update-Cache jetzt leeren
</button>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#wis-clear-cache-btn').on('click', function() {
var $btn = $(this);
$btn.prop('disabled', true).text('Leere...');
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'wis_clear_cache',
nonce: '<?php echo wp_create_nonce('wis_clear_cache_nonce'); ?>'
},
success: function(response) {
if (response.success) {
$btn.removeClass('button-secondary').addClass('button-primary').text('✅ ' + response.data.message);
setTimeout(function() {
$btn.prop('disabled', false).removeClass('button-primary').addClass('button-secondary').text('🔄 Update-Cache jetzt leeren');
}, 3000);
} else {
alert('Fehler: ' + (response.data || 'Unbekannt'));
$btn.prop('disabled', false).text('🔄 Update-Cache jetzt leeren');
}
},
error: function() {
alert('Verbindungsfehler.');
$btn.prop('disabled', false).text('🔄 Update-Cache jetzt leeren');
}
});
});
});
</script>
<?php
}
}
WIS_Dashboard::init();
// Zeige Notice auch im Admin-Bereich (außer auf dem Dashboard selbst, da dort das Widget ist)
add_action('admin_notices', [WIS_Dashboard::class, 'show_update_notice']);
// ===========================================================
// ACTIVATION & DATABASE
// ===========================================================