festive-seasons-pro.php aktualisiert
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
Plugin Name: Festive Seasons Pro
|
Plugin Name: Festive Seasons Pro
|
||||||
Description: Zeigt saisonale Effekte (Schnee, Eier, Spinnen, Ballons, Feuerwerk) für feste Feiertage und individuelle Geburtstage an.
|
Description: Zeigt saisonale Effekte (Schnee, Eier, Spinnen, Ballons, Feuerwerk) für feste Feiertage und individuelle Geburtstage an.
|
||||||
Version: 1.1
|
Version: 1.2
|
||||||
Author: M_Viper
|
Author: M_Viper
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,6 +10,110 @@ if (!defined('ABSPATH')) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === FESTIVE SEASONS PRO - UPDATE SYSTEM ===
|
||||||
|
|
||||||
|
// Aktuelle Plugin-Version aus Plugin-Header lesen
|
||||||
|
function fsp_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 löschen (manueller Refresh)
|
||||||
|
function fsp_clear_update_cache() {
|
||||||
|
if ( isset($_GET['fsp_clear_cache']) && current_user_can('manage_options') ) {
|
||||||
|
check_admin_referer('fsp_clear_cache_action');
|
||||||
|
delete_transient('fsp_latest_release');
|
||||||
|
wp_redirect( admin_url('plugins.php') );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('admin_init', 'fsp_clear_update_cache');
|
||||||
|
|
||||||
|
// Neueste Release-Infos von Gitea holen
|
||||||
|
function fsp_get_latest_release_info( $force_refresh = false ) {
|
||||||
|
$transient_key = 'fsp_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/Festive-Seasons-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'], 'v');
|
||||||
|
|
||||||
|
$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-Notice für Plugin-Update
|
||||||
|
function fsp_show_update_notice() {
|
||||||
|
if ( ! current_user_can('manage_options') ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current_version = fsp_get_plugin_version();
|
||||||
|
$latest_release = fsp_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?fsp_clear_cache=1'),
|
||||||
|
'fsp_clear_cache_action'
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<div class="notice notice-warning is-dismissible">
|
||||||
|
<h3>Festive Seasons Pro – Update verfügbar</h3>
|
||||||
|
<p>
|
||||||
|
Aktuelle Version: <strong><?php echo esc_html($current_version); ?></strong><br>
|
||||||
|
Neueste Version: <strong><?php echo esc_html($latest_release['version']); ?></strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="<?php echo esc_url($latest_release['download_url']); ?>" class="button button-primary" target="_blank">
|
||||||
|
Update herunterladen
|
||||||
|
</a>
|
||||||
|
<a href="https://git.viper.ipv64.net/M_Viper/Festive-Seasons-Pro/releases" class="button" target="_blank">
|
||||||
|
Release Notes
|
||||||
|
</a>
|
||||||
|
<a href="<?php echo esc_url($refresh_url); ?>" class="button">
|
||||||
|
Jetzt neu prüfen
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('admin_notices', 'fsp_show_update_notice');
|
||||||
|
|
||||||
|
|
||||||
class Festive_Seasons_Pro {
|
class Festive_Seasons_Pro {
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
|||||||
Reference in New Issue
Block a user