Update from Git Manager GUI

This commit is contained in:
2026-03-19 23:51:55 +01:00
parent 5e155c8398
commit 3d08d57d64
2 changed files with 389 additions and 594 deletions

View File

@@ -1,478 +1,325 @@
<?php
/**
* Minecraft Modern Theme - Customizer Settings
*
* Enthält Einstellungen für:
* - Header Slider & Hero
* - Theme Presets (Nether, End, Classic)
* - Farben & Darstellung
* - Social Media
* - Footer
* - Login
* - Sidebar
* - Import/Export
* FIXES:
* - Google Font via wp_enqueue_style() statt <link> direkt in wp_head
* - slider_loop Setting ergänzt (war in slider-init.js referenziert, aber nie definiert)
* - Scroll-to-Top Toggle ergänzt
* - footer_copyright Default mit aktuellem Jahr zur Laufzeit
* - Import_Export_Control Klasse aus dem Callback extrahiert
*/
function minecraft_modern_customize_register( $wp_customize ) {
// =========================================================================
// === 1. HEADER-BEREICH ===================================================
// Import/Export Control außerhalb des Callbacks definiert
// =========================================================================
// --- Sektion: Header Slider ---
$wp_customize->add_section( 'header_slider', array(
'title' => 'Header Slider',
'priority' => 20,
'description' => 'Konfiguriere den großen Slider auf der Startseite.',
) );
// Checkbox zum Aktivieren des Sliders
$wp_customize->add_setting( 'slider_enabled', array(
'default' => false,
'transport' => 'refresh',
'sanitize_callback' => 'wp_validate_boolean',
) );
$wp_customize->add_control( 'slider_enabled', array(
'label' => 'Header Slider aktivieren',
'section' => 'header_slider',
'settings' => 'slider_enabled',
'type' => 'checkbox',
) );
// Dynamische Slider-Bilder, Titel und Untertitel
for ($i = 1; $i <= 5; $i++) {
$wp_customize->add_setting( 'slider_image_' . $i, array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'slider_image_' . $i, array(
'label' => sprintf( 'Banner %d - Bild', $i ),
'section' => 'header_slider',
'settings' => 'slider_image_' . $i,
) ) );
$wp_customize->add_setting( 'slider_title_' . $i, array( 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_title_' . $i, array(
'label' => sprintf( 'Banner %d - Titel', $i ),
'section' => 'header_slider',
'settings' => 'slider_title_' . $i,
'type' => 'text',
) );
$wp_customize->add_setting( 'slider_subtitle_' . $i, array( 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_subtitle_' . $i, array(
'label' => sprintf( 'Banner %d - Untertitel', $i ),
'section' => 'header_slider',
'settings' => 'slider_subtitle_' . $i,
'type' => 'text',
) );
}
// Slider Text- & Stil-Einstellungen
$wp_customize->add_setting( 'slider_font_family', array( 'default' => 'Raleway', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_font_family', array(
'label' => 'Schriftart', 'section' => 'header_slider', 'settings' => 'slider_font_family', 'type' => 'select',
'choices' => array( 'Raleway' => 'Raleway', 'Poppins' => 'Poppins', 'Montserrat' => 'Montserrat', 'Oswald' => 'Oswald', 'Roboto' => 'Roboto', 'Lato' => 'Lato' ),
) );
$wp_customize->add_setting( 'slider_font_size', array( 'default' => 'mittel', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_font_size', array(
'label' => 'Schriftgröße', 'section' => 'header_slider', 'settings' => 'slider_font_size', 'type' => 'select',
'choices' => array( 'klein' => 'Klein', 'mittel' => 'Mittel', 'gross' => 'Groß', 'extra-gross' => 'Extra Groß' ),
) );
$wp_customize->add_setting( 'slider_font_color', array( 'default' => '#ffffff', 'sanitize_callback' => 'sanitize_hex_color' ) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'slider_font_color', array(
'label' => 'Schriftfarbe', 'section' => 'header_slider', 'settings' => 'slider_font_color',
) ) );
// Header-Höhe
$wp_customize->add_setting( 'header_height', array( 'default' => 'mittel', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'header_height', array(
'label' => 'Header-Höhe', 'section' => 'header_slider', 'settings' => 'header_height', 'type' => 'select',
'choices' => array( 'klein' => 'Klein', 'mittel' => 'Mittel', 'gross' => 'Groß' ),
) );
$wp_customize->add_setting( 'slider_hide_arrows', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'slider_hide_arrows', array(
'label' => 'Pfeile ausblenden', 'section' => 'header_slider', 'settings' => 'slider_hide_arrows', 'type' => 'checkbox',
) );
$wp_customize->add_setting( 'slider_hide_pagination', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'slider_hide_pagination', array(
'label' => 'Paginierung (Punkte) ausblenden', 'section' => 'header_slider', 'settings' => 'slider_hide_pagination', 'type' => 'checkbox',
) );
// --- Sektion: Startseiten-Hero (Fallback) ---
$wp_customize->add_section( 'hero_section', array(
'title' => 'Startseiten-Hero (wenn Slider deaktiviert)',
'priority' => 21,
'description' => 'Diese Inhalte werden angezeigt, wenn der Slider ausgeschaltet ist.',
) );
$wp_customize->add_setting( 'hero_title', array( 'default' => 'Willkommen auf unserem Server', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_title', array( 'label' => 'Haupttitel', 'section' => 'hero_section', 'settings' => 'hero_title', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_subtitle', array( 'default' => 'Trete einer Community voller Abenteuer bei.', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_subtitle', array( 'label' => 'Untertitel', 'section' => 'hero_section', 'settings' => 'hero_subtitle', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_bg_image', array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'hero_bg_image', array(
'label' => 'Hintergrundbild', 'section' => 'hero_section', 'settings' => 'hero_bg_image',
) ) );
$wp_customize->add_setting( 'hero_button_1_text', array( 'default' => 'Zum Forum', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_button_1_text', array( 'label' => 'Button 1 Text', 'section' => 'hero_section', 'settings' => 'hero_button_1_text', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_button_1_url', array( 'default' => '#', 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'hero_button_1_url', array( 'label' => 'Button 1 URL', 'section' => 'hero_section', 'settings' => 'hero_button_1_url', 'type' => 'url' ) );
$wp_customize->add_setting( 'hero_button_2_text', array( 'default' => 'Zum Teamspeak', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_button_2_text', array( 'label' => 'Button 2 Text', 'section' => 'hero_section', 'settings' => 'hero_button_2_text', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_button_2_url', array( 'default' => '#', 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'hero_button_2_url', array( 'label' => 'Button 2 URL', 'section' => 'hero_section', 'settings' => 'hero_button_2_url', 'type' => 'url' ) );
// --- Checkbox: Seitentitel auf Startseite verstecken ---
$wp_customize->add_setting( 'show_home_title', array(
'default' => false,
'sanitize_callback' => 'wp_validate_boolean',
) );
$wp_customize->add_control( 'show_home_title', array(
'label' => 'Seitentitel "Home" anzeigen',
'description' => 'Aktiviere diese Option, wenn der Titel "Home" über dem Slider/Inhalt angezeigt werden soll.',
'section' => 'hero_section',
'settings' => 'show_home_title',
'type' => 'checkbox',
) );
// =========================================================================
// === 2. FARBEN & DARSTELLUNG (KOMBINIERT) ================================
// =========================================================================
// --- Sektion: Farben & Darstellung ---
$wp_customize->add_section( 'theme_appearance_settings', array(
'title' => 'Farben & Darstellung',
'priority' => 30,
) );
// =========================================================================
// === NEU: THEME PRESETS (VOREINSTELLUNGEN) ==============================
// =========================================================================
$wp_customize->add_setting( 'theme_color_preset', array(
'default' => 'classic',
'sanitize_callback' => 'sanitize_key',
'transport' => 'refresh',
) );
$wp_customize->add_control( 'theme_color_preset', array(
'label' => 'Theme Preset (Farbschema)',
'description' => 'Wähle ein voreingestelltes Farbschema (z. B. für Nether oder End Dimension).',
'section' => 'theme_appearance_settings',
'settings' => 'theme_color_preset',
'type' => 'select',
'priority' => 1, // Zeig es ganz oben in dieser Sektion an
'choices' => array(
'classic' => 'Classic Minecraft (Diamant-Blau)',
'nether' => 'Nether (Lava-Rot)',
'end' => 'The End (Ender-Purpur)',
),
) );
// =========================================================================
// === ENDE THEME PRESETS ==================================================
// =========================================================================
// Akzentfarbe
$wp_customize->add_setting( 'primary_accent_color', array( 'default' => '#00d4ff', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'refresh' ) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'primary_accent_color', array(
'label' => 'Akzentfarbe', 'section' => 'theme_appearance_settings', 'settings' => 'primary_accent_color',
) ) );
// Hintergrundfarbe
$wp_customize->add_setting( 'background_color', array(
'default' => '#ffffff',
'sanitize_callback' => 'sanitize_hex_color',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_color', array(
'label' => 'Hintergrundfarbe',
'section' => 'theme_appearance_settings',
'settings' => 'background_color',
) ) );
// Dark / Light Mode
$wp_customize->add_setting( 'default_theme_mode', array( 'default' => 'dark', 'sanitize_callback' => 'sanitize_key' ) );
$wp_customize->add_control( 'default_theme_mode', array(
'label' => 'Standard-Theme-Modus', 'section' => 'theme_appearance_settings', 'type' => 'radio',
'choices' => array( 'dark' => 'Dark Mode (Standard)', 'light' => 'Light Mode' ),
) );
// =========================================================================
// === 3. SIDEBAR EINSTELLUNGEN ============================================
// =========================================================================
$wp_customize->add_section( 'sidebar_settings', array(
'title' => 'Sidebar Einstellungen',
'priority' => 35,
'description' => 'Konfiguriere die Sidebar auf der Startseite.',
) );
// Sidebar aktivieren
$wp_customize->add_setting( 'homepage_sidebar_enabled', array(
'default' => false,
'sanitize_callback' => 'wp_validate_boolean',
) );
$wp_customize->add_control( 'homepage_sidebar_enabled', array(
'label' => 'Sidebar auf Startseite aktivieren',
'description' => 'Zeigt eine Sidebar neben dem Hauptinhalt an.',
'section' => 'sidebar_settings',
'settings' => 'homepage_sidebar_enabled',
'type' => 'checkbox',
) );
// Sidebar Position
$wp_customize->add_setting( 'homepage_sidebar_position', array(
'default' => 'right',
'sanitize_callback' => 'sanitize_key',
) );
$wp_customize->add_control( 'homepage_sidebar_position', array(
'label' => 'Sidebar Position',
'section' => 'sidebar_settings',
'settings' => 'homepage_sidebar_position',
'type' => 'select',
'choices' => array(
'left' => 'Links',
'right' => 'Rechts',
),
) );
// =========================================================================
// === 4. SOCIAL MEDIA =====================================================
// =========================================================================
$wp_customize->add_section( 'social_links', array( 'title' => 'Social Media Links', 'priority' => 40 ) );
$social_platforms = array( 'discord' => 'Discord', 'youtube' => 'YouTube', 'twitter' => 'Twitter (X)', 'facebook' => 'Facebook', 'instagram' => 'Instagram', 'tiktok' => 'TikTok', 'twitch' => 'Twitch', 'steam' => 'Steam', 'github' => 'GitHub', 'linkedin' => 'LinkedIn', 'pinterest' => 'Pinterest', 'reddit' => 'Reddit', 'teamspeak' => 'Teamspeak', 'spotify' => 'Spotify' );
foreach ($social_platforms as $key => $label) {
$wp_customize->add_setting( 'social_' . $key, array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'social_' . $key, array(
'label' => $label . ' URL', 'section' => 'social_links', 'settings' => 'social_' . $key, 'type' => 'url',
) );
}
// =========================================================================
// === 5. FOOTER-BEREICH ==================================================
// =========================================================================
$wp_customize->add_section( 'footer_settings', array( 'title' => 'Footer-Einstellungen', 'priority' => 50 ) );
// Copyright-Text
$wp_customize->add_setting( 'footer_copyright', array( 'default' => '&copy; ' . date('Y') . ' ' . get_bloginfo('name'), 'sanitize_callback' => 'wp_kses_post' ) );
$wp_customize->add_control( 'footer_copyright', array(
'label' => 'Copyright-Text', 'section' => 'footer_settings', 'settings' => 'footer_copyright', 'type' => 'textarea',
) );
// Impressum & Datenschutz Links
$wp_customize->add_setting( 'footer_impressum_url', array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'footer_impressum_url', array(
'label' => 'URL für Impressum', 'section' => 'footer_settings', 'settings' => 'footer_impressum_url', 'type' => 'url',
) );
$wp_customize->add_setting( 'footer_datenschutz_url', array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'footer_datenschutz_url', array(
'label' => 'URL für Datenschutz', 'section' => 'footer_settings', 'settings' => 'footer_datenschutz_url', 'type' => 'url',
) );
// Footer-Credit
$wp_customize->add_setting( 'show_footer_credit', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'show_footer_credit', array(
'label' => 'Footer-Credit ("Minecraft Theme Erstellt von...") anzeigen', 'section' => 'footer_settings', 'settings' => 'show_footer_credit', 'type' => 'checkbox',
) );
// =========================================================================
// === 6. ZUSÄTZLICHE FUNKTIONEN ==========================================
// =========================================================================
// --- Sektion: FAQ Einstellungen ---
$wp_customize->add_section( 'faq_settings', array( 'title' => 'FAQ Einstellungen', 'priority' => 60 ) );
$wp_customize->add_setting( 'faq_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'faq_enabled', array(
'label' => 'FAQ System aktivieren', 'section' => 'faq_settings', 'settings' => 'faq_enabled', 'type' => 'checkbox',
) );
// --- Sektion: Team Einstellungen ---
$wp_customize->add_section( 'team_settings', array( 'title' => 'Team Einstellungen', 'priority' => 65 ) );
$wp_customize->add_setting( 'team_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'team_enabled', array(
'label' => 'Team Showcase aktivieren', 'section' => 'team_settings', 'settings' => 'team_enabled', 'type' => 'checkbox',
) );
// =========================================================================
// === 7. LOGIN-BEREICH ====================================================
// =========================================================================
$wp_customize->add_section( 'login_settings', array(
'title' => 'Login-Einstellungen',
'priority' => 70,
'description' => 'Passe das Aussehen der wp-admin Login-Seite an.',
) );
// Login-Hintergrundbild
$wp_customize->add_setting( 'login_background_image', array(
'sanitize_callback' => 'esc_url_raw',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'login_background_image', array(
'label' => 'Login-Hintergrundbild',
'section' => 'login_settings',
'settings' => 'login_background_image',
) ) );
// Login-Logo
$wp_customize->add_setting( 'login_logo', array(
'sanitize_callback' => 'esc_url_raw',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'login_logo', array(
'label' => 'Login-Logo (ersetzt das WordPress-Logo)',
'section' => 'login_settings',
'settings' => 'login_logo',
) ) );
// Multi-Avatar UUIDs
for ($i = 1; $i <= 5; $i++) {
$wp_customize->add_setting( 'login_avatar_uuid_' . $i, array(
'sanitize_callback' => 'sanitize_text_field',
'transport' => 'refresh',
) );
$wp_customize->add_control( 'login_avatar_uuid_' . $i, array(
'label' => sprintf( 'Avatar %d UUID', $i ),
'description' => sprintf( 'Gib die UUID für den %d. Avatar an. (Leer lassen, um zu deaktivieren)', $i ),
'section' => 'login_settings',
'settings' => 'login_avatar_uuid_' . $i,
'type' => 'text',
) );
}
// Slider-Geschwindigkeit
$wp_customize->add_setting( 'login_avatar_slider_speed', array(
'default' => 4,
'sanitize_callback' => 'absint',
'transport' => 'refresh',
) );
$wp_customize->add_control( 'login_avatar_slider_speed', array(
'label' => 'Avatar-Wechsel (in Sekunden)',
'description' => 'Wie viele Sekunden soll ein Avatar angezeigt werden?',
'section' => 'login_settings',
'settings' => 'login_avatar_slider_speed',
'type' => 'number',
'input_attrs' => array( 'min' => 2, 'max' => 10, 'step' => 1 ),
) );
// =========================================================================
// === 8. EXPORT / IMPORT SECTION =========================================
// =========================================================================
$wp_customize->add_section( 'theme_mods_import_export', array(
'title' => __( 'Einstellungen sichern', 'minecraft-modern-theme' ),
'priority' => 999,
'description' => '',
) );
// Füge ein Custom Control mit HTML hinzu
$wp_customize->add_setting( 'import_export_placeholder', array(
'sanitize_callback' => 'sanitize_text_field',
) );
// Custom Control Class für Export/Import
class Import_Export_Control extends WP_Customize_Control {
public $type = 'import_export';
if ( class_exists('WP_Customize_Control') && ! class_exists('MM_Import_Export_Control') ) :
class MM_Import_Export_Control extends WP_Customize_Control {
public $type = 'mm_import_export';
public function render_content() {
$export_url = admin_url('admin-post.php?action=export_theme_settings');
$nonce = wp_create_nonce('theme-import-nonce');
?>
<div class="import-export-wrapper" style="margin-top: 15px;">
<p class="description" style="margin-bottom: 20px;">
<strong>Hinweis:</strong> Hier kannst du alle deine Theme-Einstellungen sichern und wiederherstellen.
<div class="mm-import-export-wrapper">
<p class="description" style="margin-bottom:16px;">
<strong><?php _e('Hinweis:', 'minecraft-modern-theme'); ?></strong>
<?php _e('Hier kannst du alle Theme-Einstellungen sichern und wiederherstellen.', 'minecraft-modern-theme'); ?>
</p>
<a href="<?php echo esc_url($export_url); ?>" class="button button-primary button-hero" id="export-settings-btn" style="display: inline-flex; align-items: center; gap: 8px; margin-bottom: 20px;">
<span class="dashicons dashicons-download" style="margin-top:3px;"></span> Einstellungen Exportieren
<a href="<?php echo esc_url($export_url); ?>" class="button button-primary" style="display:inline-flex;align-items:center;gap:6px;margin-bottom:20px;">
<span class="dashicons dashicons-download"></span>
<?php _e('Einstellungen exportieren', 'minecraft-modern-theme'); ?>
</a>
<div style="border-top: 2px solid #ddd; padding-top: 20px; margin-top: 20px;">
<label style="display:block; margin-bottom:10px; font-weight:bold;">
Backup wiederherstellen:
</label>
<input type="file" id="import-settings-file" accept=".json" style="width:100%; margin-bottom:10px;">
<button type="button" class="button button-secondary" id="import-settings-btn" disabled style="display: inline-flex; align-items: center; gap: 8px;">
<span class="dashicons dashicons-upload" style="margin-top:3px;"></span> Einstellungen Importieren
</button>
</div>
<hr style="margin:16px 0;">
<p class="description" style="margin-top:15px; padding: 10px; background: #fff3cd; border-left: 4px solid #ffc107;">
<strong>⚠️ Warnung:</strong> Beim Import werden alle aktuellen Einstellungen überschrieben!
<label style="display:block;margin-bottom:8px;font-weight:600;">
<?php _e('Backup wiederherstellen:', 'minecraft-modern-theme'); ?>
</label>
<input type="file" id="mm-import-file" accept=".json" style="width:100%;margin-bottom:10px;">
<button type="button" class="button" id="mm-import-btn" disabled style="display:inline-flex;align-items:center;gap:6px;">
<span class="dashicons dashicons-upload"></span>
<?php _e('Einstellungen importieren', 'minecraft-modern-theme'); ?>
</button>
<p class="description" style="margin-top:12px;padding:10px;background:#fff3cd;border-left:4px solid #ffc107;color:#856404;">
⚠️ <?php _e('Beim Import werden alle aktuellen Einstellungen überschrieben!', 'minecraft-modern-theme'); ?>
</p>
</div>
<script type="text/javascript">
<script>
(function($){
var ajaxUrl = '<?php echo admin_url('admin-ajax.php'); ?>';
var nonce = '<?php echo $nonce; ?>';
var ajaxUrl = '<?php echo esc_js(admin_url('admin-ajax.php')); ?>';
var nonce = '<?php echo esc_js($nonce); ?>';
$('#import-settings-file').on('change', function() {
$('#import-settings-btn').prop('disabled', $(this).val() === '');
$('#mm-import-file').on('change', function(){
$('#mm-import-btn').prop('disabled', $(this).val() === '');
});
$('#import-settings-btn').on('click', function() {
var fileInput = $('#import-settings-file')[0];
$('#mm-import-btn').on('click', function(){
var file = $('#mm-import-file')[0].files[0];
if (!file) return;
if (!confirm('<?php echo esc_js(__('Alle aktuellen Einstellungen werden überschrieben. Fortfahren?', 'minecraft-modern-theme')); ?>')) return;
if (fileInput.files.length === 0) {
alert('Bitte wähle eine JSON-Datei aus.');
return;
}
var $btn = $(this).prop('disabled', true).text('<?php echo esc_js(__('Importiere…', 'minecraft-modern-theme')); ?>');
var fd = new FormData();
fd.append('import_file', file);
fd.append('action', 'import_theme_settings');
fd.append('nonce', nonce);
if (!confirm('WARNUNG: Alle aktuellen Einstellungen werden überschrieben. Bist du sicher?')) {
return;
}
var formData = new FormData();
formData.append('import_file', fileInput.files[0]);
formData.append('action', 'import_theme_settings');
formData.append('nonce', nonce);
var $btn = $(this);
var originalText = $btn.html();
$btn.prop('disabled', true).html('<span class="dashicons dashicons-update" style="margin-top:3px; animation: rotation 1s infinite linear;"></span> Importiere...');
$.ajax({
url: ajaxUrl,
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
if (response.success) {
alert('✅ ' + response.data);
location.reload();
} else {
alert('❌ Fehler: ' + response.data);
$btn.prop('disabled', false).html(originalText);
}
$.ajax({ url: ajaxUrl, type: 'POST', data: fd, processData: false, contentType: false,
success: function(r){
if (r.success) { alert('✅ ' + r.data); location.reload(); }
else { alert('❌ ' + r.data); $btn.prop('disabled', false).text('<?php echo esc_js(__('Einstellungen importieren', 'minecraft-modern-theme')); ?>'); }
},
error: function() {
alert('❌ Ein technischer Fehler ist aufgetreten.');
$btn.prop('disabled', false).html(originalText);
}
error: function(){ alert('<?php echo esc_js(__('Technischer Fehler.', 'minecraft-modern-theme')); ?>'); $btn.prop('disabled', false); }
});
});
})(jQuery);
</script>
<style>
@keyframes rotation {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
</style>
<?php
}
}
endif;
$wp_customize->add_control( new Import_Export_Control( $wp_customize, 'import_export_placeholder', array(
// =========================================================================
// Customizer Register
// =========================================================================
function minecraft_modern_customize_register( $wp_customize ) {
// =========================================================================
// 1. HEADER SLIDER
// =========================================================================
$wp_customize->add_section( 'header_slider', array(
'title' => __('Header Slider', 'minecraft-modern-theme'),
'priority' => 20,
'description' => __('Konfiguriere den großen Slider auf der Startseite.', 'minecraft-modern-theme'),
) );
$wp_customize->add_setting( 'slider_enabled', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'slider_enabled', array( 'label' => __('Header Slider aktivieren', 'minecraft-modern-theme'), 'section' => 'header_slider', 'type' => 'checkbox' ) );
// FIX: slider_loop war in slider-init.js als sliderSettings.loop referenziert, aber nie definiert
$wp_customize->add_setting( 'slider_loop', array( 'default' => true, 'transport' => 'refresh', 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'slider_loop', array(
'label' => __('Slider Endlos-Loop aktivieren', 'minecraft-modern-theme'),
'description' => __('Der Slider springt nach dem letzten Slide wieder zum ersten zurück.', 'minecraft-modern-theme'),
'section' => 'header_slider',
'type' => 'checkbox',
) );
for ( $i = 1; $i <= 5; $i++ ) {
$wp_customize->add_setting( 'slider_image_' . $i, array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'slider_image_' . $i, array(
'label' => sprintf( __('Banner %d - Bild', 'minecraft-modern-theme'), $i ), 'section' => 'header_slider',
) ) );
$wp_customize->add_setting( 'slider_title_' . $i, array( 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_title_' . $i, array( 'label' => sprintf( __('Banner %d - Titel', 'minecraft-modern-theme'), $i ), 'section' => 'header_slider', 'type' => 'text' ) );
$wp_customize->add_setting( 'slider_subtitle_' . $i, array( 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_subtitle_' . $i, array( 'label' => sprintf( __('Banner %d - Untertitel', 'minecraft-modern-theme'), $i ), 'section' => 'header_slider', 'type' => 'text' ) );
}
$wp_customize->add_setting( 'slider_font_family', array( 'default' => 'Raleway', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_font_family', array(
'label' => __('Schriftart', 'minecraft-modern-theme'), 'section' => 'header_slider', 'type' => 'select',
'choices' => array( 'Raleway' => 'Raleway', 'Poppins' => 'Poppins', 'Montserrat' => 'Montserrat', 'Oswald' => 'Oswald', 'Roboto' => 'Roboto', 'Lato' => 'Lato' ),
) );
$wp_customize->add_setting( 'slider_font_size', array( 'default' => 'mittel', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'slider_font_size', array(
'label' => __('Schriftgröße', 'minecraft-modern-theme'), 'section' => 'header_slider', 'type' => 'select',
'choices' => array( 'klein' => __('Klein', 'minecraft-modern-theme'), 'mittel' => __('Mittel', 'minecraft-modern-theme'), 'gross' => __('Groß', 'minecraft-modern-theme'), 'extra-gross' => __('Extra Groß', 'minecraft-modern-theme') ),
) );
$wp_customize->add_setting( 'slider_font_color', array( 'default' => '#ffffff', 'sanitize_callback' => 'sanitize_hex_color' ) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'slider_font_color', array(
'label' => __('Schriftfarbe', 'minecraft-modern-theme'), 'section' => 'header_slider',
) ) );
$wp_customize->add_setting( 'header_height', array( 'default' => 'mittel', 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'header_height', array(
'label' => __('Header-Höhe', 'minecraft-modern-theme'), 'section' => 'header_slider', 'type' => 'select',
'choices' => array( 'klein' => __('Klein', 'minecraft-modern-theme'), 'mittel' => __('Mittel', 'minecraft-modern-theme'), 'gross' => __('Groß', 'minecraft-modern-theme') ),
) );
$wp_customize->add_setting( 'slider_hide_arrows', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'slider_hide_arrows', array( 'label' => __('Pfeile ausblenden', 'minecraft-modern-theme'), 'section' => 'header_slider', 'type' => 'checkbox' ) );
$wp_customize->add_setting( 'slider_hide_pagination', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'slider_hide_pagination', array( 'label' => __('Paginierung (Punkte) ausblenden', 'minecraft-modern-theme'), 'section' => 'header_slider', 'type' => 'checkbox' ) );
// =========================================================================
// 2. HERO SECTION (Fallback)
// =========================================================================
$wp_customize->add_section( 'hero_section', array(
'title' => __('Startseiten-Hero (wenn Slider deaktiviert)', 'minecraft-modern-theme'),
'priority' => 21,
) );
$wp_customize->add_setting( 'hero_title', array( 'default' => __('Willkommen auf unserem Server', 'minecraft-modern-theme'), 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_title', array( 'label' => __('Haupttitel', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_subtitle', array( 'default' => __('Trete einer Community voller Abenteuer bei.', 'minecraft-modern-theme'), 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_subtitle', array( 'label' => __('Untertitel', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_bg_image', array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'hero_bg_image', array( 'label' => __('Hintergrundbild', 'minecraft-modern-theme'), 'section' => 'hero_section' ) ) );
$wp_customize->add_setting( 'hero_button_1_text', array( 'default' => __('Zum Forum', 'minecraft-modern-theme'), 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_button_1_text', array( 'label' => __('Button 1 Text', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_button_1_url', array( 'default' => '#', 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'hero_button_1_url', array( 'label' => __('Button 1 URL', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'url' ) );
$wp_customize->add_setting( 'hero_button_2_text', array( 'default' => __('Zum Teamspeak', 'minecraft-modern-theme'), 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( 'hero_button_2_text', array( 'label' => __('Button 2 Text', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'text' ) );
$wp_customize->add_setting( 'hero_button_2_url', array( 'default' => '#', 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'hero_button_2_url', array( 'label' => __('Button 2 URL', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'url' ) );
$wp_customize->add_setting( 'show_home_title', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'show_home_title', array( 'label' => __('Seitentitel "Home" anzeigen', 'minecraft-modern-theme'), 'section' => 'hero_section', 'type' => 'checkbox' ) );
// =========================================================================
// 3. FARBEN & DARSTELLUNG
// =========================================================================
$wp_customize->add_section( 'theme_appearance_settings', array(
'title' => __('Farben & Darstellung', 'minecraft-modern-theme'), 'priority' => 30,
) );
$wp_customize->add_setting( 'theme_color_preset', array( 'default' => 'classic', 'sanitize_callback' => 'sanitize_key', 'transport' => 'refresh' ) );
$wp_customize->add_control( 'theme_color_preset', array(
'label' => __('Theme Preset (Farbschema)', 'minecraft-modern-theme'),
'section' => 'theme_appearance_settings',
'type' => 'select',
'priority' => 1,
'choices' => array(
'classic' => __('Classic Minecraft (Diamant-Blau)', 'minecraft-modern-theme'),
'nether' => __('Nether (Lava-Rot)', 'minecraft-modern-theme'),
'end' => __('The End (Ender-Purpur)', 'minecraft-modern-theme'),
),
) );
$wp_customize->add_setting( 'primary_accent_color', array( 'default' => '#00d4ff', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'refresh' ) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'primary_accent_color', array( 'label' => __('Akzentfarbe', 'minecraft-modern-theme'), 'section' => 'theme_appearance_settings' ) ) );
$wp_customize->add_setting( 'default_theme_mode', array( 'default' => 'dark', 'sanitize_callback' => 'sanitize_key' ) );
$wp_customize->add_control( 'default_theme_mode', array(
'label' => __('Standard-Theme-Modus', 'minecraft-modern-theme'),
'section' => 'theme_appearance_settings',
'type' => 'radio',
'choices' => array( 'dark' => __('Dark Mode', 'minecraft-modern-theme'), 'light' => __('Light Mode', 'minecraft-modern-theme') ),
) );
// FIX: Scroll-to-Top war nie im Customizer steuerbar
$wp_customize->add_setting( 'show_scroll_to_top', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'show_scroll_to_top', array(
'label' => __('Scroll-to-Top Button anzeigen', 'minecraft-modern-theme'),
'description' => __('Zeigt einen Button unten rechts zum Hochscrollen an.', 'minecraft-modern-theme'),
'section' => 'theme_appearance_settings',
'type' => 'checkbox',
) );
// =========================================================================
// 4. SIDEBAR
// =========================================================================
$wp_customize->add_section( 'sidebar_settings', array( 'title' => __('Sidebar Einstellungen', 'minecraft-modern-theme'), 'priority' => 35 ) );
$wp_customize->add_setting( 'homepage_sidebar_enabled', array( 'default' => false, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'homepage_sidebar_enabled', array( 'label' => __('Sidebar auf Startseite aktivieren', 'minecraft-modern-theme'), 'section' => 'sidebar_settings', 'type' => 'checkbox' ) );
$wp_customize->add_setting( 'homepage_sidebar_position', array( 'default' => 'right', 'sanitize_callback' => 'sanitize_key' ) );
$wp_customize->add_control( 'homepage_sidebar_position', array(
'label' => __('Sidebar Position', 'minecraft-modern-theme'), 'section' => 'sidebar_settings', 'type' => 'select',
'choices' => array( 'left' => __('Links', 'minecraft-modern-theme'), 'right' => __('Rechts', 'minecraft-modern-theme') ),
) );
// =========================================================================
// 5. SOCIAL MEDIA
// =========================================================================
$wp_customize->add_section( 'social_links', array( 'title' => __('Social Media Links', 'minecraft-modern-theme'), 'priority' => 40 ) );
$social_platforms = array(
'discord' => 'Discord', 'youtube' => 'YouTube', 'twitter' => 'Twitter (X)',
'facebook' => 'Facebook', 'instagram' => 'Instagram', 'tiktok' => 'TikTok',
'twitch' => 'Twitch', 'steam' => 'Steam', 'github' => 'GitHub',
'linkedin' => 'LinkedIn', 'pinterest' => 'Pinterest', 'reddit' => 'Reddit',
'teamspeak' => 'Teamspeak', 'spotify' => 'Spotify',
);
foreach ( $social_platforms as $key => $label ) {
$wp_customize->add_setting( 'social_' . $key, array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'social_' . $key, array( 'label' => $label . ' URL', 'section' => 'social_links', 'type' => 'url' ) );
}
// =========================================================================
// 6. FOOTER
// =========================================================================
$wp_customize->add_section( 'footer_settings', array( 'title' => __('Footer-Einstellungen', 'minecraft-modern-theme'), 'priority' => 50 ) );
// FIX: Default mit aktuellem Jahr zur Laufzeit auswerten, nicht bei class-load
$wp_customize->add_setting( 'footer_copyright', array(
'default' => '', // Leer = dynamisch berechnet in footer.php
'sanitize_callback' => 'wp_kses_post',
) );
$wp_customize->add_control( 'footer_copyright', array(
'label' => __('Copyright-Text', 'minecraft-modern-theme'),
'description' => __('Leer lassen für automatischen Text mit aktuellem Jahr.', 'minecraft-modern-theme'),
'section' => 'footer_settings',
'type' => 'textarea',
) );
$wp_customize->add_setting( 'footer_impressum_url', array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'footer_impressum_url', array( 'label' => __('URL für Impressum', 'minecraft-modern-theme'), 'section' => 'footer_settings', 'type' => 'url' ) );
$wp_customize->add_setting( 'footer_datenschutz_url', array( 'sanitize_callback' => 'esc_url_raw' ) );
$wp_customize->add_control( 'footer_datenschutz_url', array( 'label' => __('URL für Datenschutz', 'minecraft-modern-theme'), 'section' => 'footer_settings', 'type' => 'url' ) );
$wp_customize->add_setting( 'show_footer_credit', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'show_footer_credit', array( 'label' => __('Footer-Credit anzeigen', 'minecraft-modern-theme'), 'section' => 'footer_settings', 'type' => 'checkbox' ) );
// =========================================================================
// 7. FAQ & TEAM
// =========================================================================
$wp_customize->add_section( 'faq_settings', array( 'title' => __('FAQ Einstellungen', 'minecraft-modern-theme'), 'priority' => 60 ) );
$wp_customize->add_setting( 'faq_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'faq_enabled', array( 'label' => __('FAQ System aktivieren', 'minecraft-modern-theme'), 'section' => 'faq_settings', 'type' => 'checkbox' ) );
$wp_customize->add_section( 'team_settings', array( 'title' => __('Team Einstellungen', 'minecraft-modern-theme'), 'priority' => 65 ) );
$wp_customize->add_setting( 'team_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean' ) );
$wp_customize->add_control( 'team_enabled', array( 'label' => __('Team Showcase aktivieren', 'minecraft-modern-theme'), 'section' => 'team_settings', 'type' => 'checkbox' ) );
// =========================================================================
// 8. LOGIN
// =========================================================================
$wp_customize->add_section( 'login_settings', array( 'title' => __('Login-Einstellungen', 'minecraft-modern-theme'), 'priority' => 70 ) );
$wp_customize->add_setting( 'login_background_image', array( 'sanitize_callback' => 'esc_url_raw', 'transport' => 'refresh' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'login_background_image', array( 'label' => __('Login-Hintergrundbild', 'minecraft-modern-theme'), 'section' => 'login_settings' ) ) );
$wp_customize->add_setting( 'login_logo', array( 'sanitize_callback' => 'esc_url_raw', 'transport' => 'refresh' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'login_logo', array( 'label' => __('Login-Logo', 'minecraft-modern-theme'), 'section' => 'login_settings' ) ) );
for ( $i = 1; $i <= 5; $i++ ) {
$wp_customize->add_setting( 'login_avatar_uuid_' . $i, array( 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'refresh' ) );
$wp_customize->add_control( 'login_avatar_uuid_' . $i, array(
'label' => sprintf( __('Avatar %d UUID', 'minecraft-modern-theme'), $i ),
'section' => 'login_settings',
'type' => 'text',
) );
}
$wp_customize->add_setting( 'login_avatar_slider_speed', array( 'default' => 4, 'sanitize_callback' => 'absint', 'transport' => 'refresh' ) );
$wp_customize->add_control( 'login_avatar_slider_speed', array(
'label' => __('Avatar-Wechsel (Sekunden)', 'minecraft-modern-theme'),
'section' => 'login_settings',
'type' => 'number',
'input_attrs' => array( 'min' => 2, 'max' => 10, 'step' => 1 ),
) );
// =========================================================================
// 9. EXPORT / IMPORT
// =========================================================================
$wp_customize->add_section( 'theme_mods_import_export', array(
'title' => __('Einstellungen sichern', 'minecraft-modern-theme'),
'priority' => 999,
) );
$wp_customize->add_setting( 'import_export_placeholder', array( 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( new MM_Import_Export_Control( $wp_customize, 'import_export_placeholder', array(
'section' => 'theme_mods_import_export',
) ) );
}
@@ -480,110 +327,81 @@ add_action( 'customize_register', 'minecraft_modern_customize_register' );
// =========================================================================
// === DYNAMISCHES CSS =====================================================
// DYNAMISCHES CSS FIX: Google Font via wp_enqueue_style(), nicht <link> in wp_head
// =========================================================================
function minecraft_modern_enqueue_dynamic_styles() {
$font = get_theme_mod( 'slider_font_family', 'Raleway' );
function minecraft_modern_dynamic_css_output() {
// Google Font sauber einbinden
$font_url = 'https://fonts.googleapis.com/css2?family=' . urlencode($font) . ':wght@400;600;700&display=swap';
wp_enqueue_style( 'minecraft-modern-google-font', $font_url, array(), null );
// Dynamisches CSS als inline style
$accent_color = get_theme_mod( 'primary_accent_color', '#00d4ff' );
$slider_font = get_theme_mod( 'slider_font_family', 'Raleway' );
$slider_color = get_theme_mod( 'slider_font_color', '#ffffff' );
$slider_size_setting = get_theme_mod( 'slider_font_size', 'mittel' );
$header_height_setting = get_theme_mod( 'header_height', 'mittel' );
// Header-Höhe umwandeln
$header_height_value = '300px';
if ( $header_height_setting === 'klein' ) {
$header_height_value = '200px';
} elseif ( $header_height_setting === 'gross' ) {
$header_height_value = '400px';
}
$height_map = array( 'klein' => '200px', 'mittel' => '300px', 'gross' => '400px' );
$header_height_value = isset($height_map[$header_height_setting]) ? $height_map[$header_height_setting] : '300px';
// Schriftgrößen umwandeln
$font_sizes = array(
'klein' => array( 'title' => '2.5rem', 'subtitle' => '1.2rem' ),
'mittel' => array( 'title' => '3.5rem', 'subtitle' => '1.4rem' ),
'gross' => array( 'title' => '4.5rem', 'subtitle' => '1.6rem' ),
'extra-gross' => array( 'title' => '5.5rem', 'subtitle' => '1.8rem' ),
);
$chosen_sizes = isset( $font_sizes[$slider_size_setting] ) ? $font_sizes[$slider_size_setting] : $font_sizes['mittel'];
$sizes = isset($font_sizes[$slider_size_setting]) ? $font_sizes[$slider_size_setting] : $font_sizes['mittel'];
$fonts_to_load = array($slider_font);
$fonts_url = 'https://fonts.googleapis.com/css2?family=' . implode( ':wght@400;600;700&family=', $fonts_to_load ) . '&display=swap';
?>
<link rel="stylesheet" href="<?php echo esc_url($fonts_url); ?>">
<style type="text/css">
$css = "
:root {
--primary-accent: <?php echo esc_attr($accent_color); ?>;
--header-height: <?php echo esc_attr($header_height_value); ?>;
--primary-accent: " . esc_attr($accent_color) . ";
--header-height: " . esc_attr($header_height_value) . ";
}
.slider-title, .slider-subtitle, .hero-title, .hero-subtitle, .hero-button-1, .hero-button-2 {
font-family: '<?php echo esc_attr($slider_font); ?>', sans-serif;
color: <?php echo esc_attr($slider_color); ?>;
}
.slider-title, .hero-title {
font-size: <?php echo esc_attr($chosen_sizes['title']); ?>;
}
.slider-subtitle, .hero-subtitle {
font-size: <?php echo esc_attr($chosen_sizes['subtitle']); ?>;
font-family: '" . esc_attr($font) . "', sans-serif;
color: " . esc_attr($slider_color) . ";
}
.slider-title, .hero-title { font-size: " . esc_attr($sizes['title']) . "; }
.slider-subtitle, .hero-subtitle { font-size: " . esc_attr($sizes['subtitle']) . "; }
.site-header { border-bottom: 4px solid var(--primary-accent); }
.hero-slider { border-bottom: 4px solid var(--primary-accent); }
.site-footer { border-top: 4px solid var(--primary-accent); }
";
/* Trennlinie unter dem Header */
.site-header {
border-bottom: 4px solid var(--primary-accent);
wp_add_inline_style( 'minecraft-modern-style', $css );
}
add_action( 'wp_enqueue_scripts', 'minecraft_modern_enqueue_dynamic_styles', 20 );
/* Trennlinie unter dem Slider */
.hero-slider {
border-bottom: 4px solid var(--primary-accent);
}
/* Trennlinie am oberen Rand des Footers */
.site-footer {
border-top: 4px solid var(--primary-accent);
}
</style>
<?php
}
add_action( 'wp_head', 'minecraft_modern_dynamic_css_output' );
// =========================================================================
// === THEME PRESET LOGIC (JAVASCRIPT) =====================================
// PRESET LOGIC (JS im Customizer)
// =========================================================================
/**
* Verbindet das Preset-Dropdown mit der Akzentfarbe-Einstellung.
* Sobald ein Preset gewählt wird, wird die Farbe im Customizer aktualisiert.
*/
function minecraft_preset_customize_js() {
?>
<script type="text/javascript">
function minecraft_preset_customize_js() { ?>
<script>
(function($){
// Definiere die Farben für die Presets
var presetColors = {
'classic': '#00d4ff', // Diamant Blau
'nether': '#ff3333', // Lava Rot
'end': '#aa00ff' // Ender Purpur
};
// Warten bis der Customizer bereit ist
var presetColors = { classic: '#00d4ff', nether: '#ff3333', end: '#aa00ff' };
wp.customize.bind('ready', function(){
// Listener für das Preset-Dropdown
wp.customize('theme_color_preset', function(setting){
setting.bind(function(to){
// Wenn eine Farbe für das gewählte Preset existiert...
if (presetColors[to]) {
// ...setze die Akzentfarbe auf diesen Wert.
// Das aktualisiert auch den Color Picker und die Live-Vorschau.
wp.customize('primary_accent_color').set(presetColors[to]);
}
});
});
});
})(jQuery);
</script>
<?php
}
<?php }
add_action( 'customize_controls_print_footer_scripts', 'minecraft_preset_customize_js' );
// =========================================================================
// FIX: slider_loop an JS übergeben (in functions.php in wp_localize_script ergänzen)
// Der folgende Filter hängt den Wert an sliderSettings an.
// Alternativ: direkt in functions.php bei wp_localize_script 'loop' hinzufügen.
// =========================================================================
add_filter( 'minecraft_modern_slider_settings', function( $settings ) {
$settings['loop'] = get_theme_mod('slider_loop', true) ? '1' : '0';
return $settings;
} );

View File

@@ -1,160 +1,137 @@
<?php
/**
* Minecraft Modern Theme - Updater & Dashboard Status
* * Diese Datei prüft auf neue Versionen via Gitea API und zeigt den Status im Dashboard an.
* Aus Sicherheitsgründen ist das automatische Update deaktiviert, um Datenverlust zu vermeiden.
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// === THEME VERSION AUTOMATISCH AUS style.css LADEN (PARENT THEME PRIORITÄT) ===
function minecraft_modern_get_theme_version() {
// Holt das aktuell aktive Theme (child oder parent)
$theme = wp_get_theme();
class Minecraft_Modern_Theme_Manager {
// Wenn ein Child-Theme aktiv ist und ein Parent vorhanden ist, nutze die Parent-Version
$parent = $theme->parent();
if ( $parent && $parent->exists() ) {
$parent_version = $parent->get( 'Version' );
if ( ! empty( $parent_version ) ) {
return $parent_version;
}
private $theme_slug = 'Minecraft-Modern-Theme';
private $repo = 'M_Viper/Minecraft-Modern-Theme';
private $transient_key = 'mm_theme_update_check';
public function __construct() {
// Update-Prüfung und Benachrichtigung
add_action( 'admin_notices', [ $this, 'display_update_notice' ] );
// Dashboard Widget
add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
// Refresh Logik
add_action( 'admin_init', [ $this, 'handle_refresh_request' ] );
}
// Fallback: Version des aktuell aktiven Themes (wenn kein Parent existiert oder Parent keine Version hat)
return $theme->get( 'Version' );
/**
* Holt die API-Daten von Gitea
*/
private function get_latest_release() {
$update_data = get_transient( $this->transient_key );
if ( false === $update_data ) {
$api_url = "https://git.viper.ipv64.net/api/v1/repos/{$this->repo}/releases/latest";
$response = wp_remote_get( $api_url, [ 'timeout' => 10 ] );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
set_transient( $this->transient_key, [ 'error' => true ], 2 * HOUR_IN_SECONDS );
return [ 'error' => true ];
}
// === THEME UPDATE NOTIFICATION SYSTEM ===
$data = json_decode( wp_remote_retrieve_body( $response ) );
$new_version = ltrim( $data->tag_name, 'vV' );
// Funktion zum Leeren des Caches (wenn man auf "Update prüfen" klickt)
function minecraft_modern_clear_cache() {
if ( isset( $_GET['mm_clear_cache'] ) && current_user_can( 'manage_options' ) ) {
check_admin_referer( 'mm_clear_cache_action' );
delete_transient( 'minecraft_modern_latest_release' );
wp_redirect( admin_url( 'index.php' ) );
exit;
}
}
add_action( 'admin_init', 'minecraft_modern_clear_cache' );
$update_data = [
'version' => $new_version,
'url' => "https://git.viper.ipv64.net/{$this->repo}/releases"
];
// Funktion zum Abrufen der neuesten Release-Informationen
function minecraft_modern_get_latest_release_info( $force_refresh = false ) {
$transient_key = 'minecraft_modern_latest_release';
// Wenn erzwungen wird (oder Cache leer), frische Daten holen
if ( $force_refresh ) {
delete_transient( $transient_key );
set_transient( $this->transient_key, $update_data, 12 * HOUR_IN_SECONDS );
}
$release_info = get_transient( $transient_key );
if ( false === $release_info ) {
// Timeout auf 10 Sekunden erhöht für langsame Verbindungen
$response = wp_remote_get(
'https://git.viper.ipv64.net/api/v1/repos/M_Viper/Minecraft-Modern-Theme/releases/latest',
array( 'timeout' => 10 )
);
if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) {
$body = wp_remote_retrieve_body( $response );
$release_data = json_decode( $body, true );
if ( $release_data && isset( $release_data['tag_name'] ) ) {
// Tag bereinigen (falls 'v' davor steht, z.B. v1.6 -> 1.6)
$tag_name = $release_data['tag_name'];
if ( strpos( $tag_name, 'v' ) === 0 ) {
$tag_name = ltrim( $tag_name, 'v' );
return $update_data;
}
$release_info = array(
'version' => $tag_name,
'download_url' => $release_data['zipball_url'],
'release_notes' => isset( $release_data['body'] ) ? $release_data['body'] : '',
'published_at' => isset( $release_data['published_at'] ) ? $release_data['published_at'] : ''
);
/**
* Zeigt die gelbe Info-Box oben im Admin-Bereich
*/
public function display_update_notice() {
if ( ! current_user_can( 'update_themes' ) ) return;
// Cache für 6 Stunden
set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS );
} else {
// Fehlerhafte Daten leer cachen
set_transient( $transient_key, array(), HOUR_IN_SECONDS );
}
} else {
// Fehler beim Abrufen
set_transient( $transient_key, array(), HOUR_IN_SECONDS );
}
}
$latest = $this->get_latest_release();
if ( isset( $latest['error'] ) ) return;
return $release_info;
}
$current_version = wp_get_theme( $this->theme_slug )->get( 'Version' );
// === BENACHRICHTIGUNG IM ADMIN-BEREICH ===
function minecraft_modern_show_update_notification() {
if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
return;
}
$current_version = minecraft_modern_get_theme_version();
$latest_release = minecraft_modern_get_latest_release_info();
if ( ! empty( $latest_release ) && isset( $latest_release['version'] ) && version_compare( $current_version, $latest_release['version'], '<' ) ) {
if ( version_compare( $current_version, $latest['version'], '<' ) ) {
?>
<div class="notice notice-warning is-dismissible">
<h3><?php _e( 'Minecraft Modern Theme Update Available', 'minecraft-modern-theme' ); ?></h3>
<p>
<?php
printf(
__( 'You are using version %1$s of the Minecraft Modern Theme. Version %2$s is now available.', 'minecraft-modern-theme' ),
'<strong>' . esc_html( $current_version ) . '</strong>',
'<strong>' . esc_html( $latest_release['version'] ) . '</strong>'
);
?>
</p>
<p>
<a href="<?php echo esc_url( $latest_release['download_url'] ); ?>" class="button button-primary" target="_blank">
<?php _e( 'Download Latest Version', 'minecraft-modern-theme' ); ?>
</a>
<a href="https://git.viper.ipv64.net/M_Viper/Minecraft-Modern-Theme/releases" class="button" target="_blank">
<?php _e( 'View Release Notes', 'minecraft-modern-theme' ); ?>
</a>
<span class="dashicons dashicons-update" style="color: #dba617; margin-right: 5px;"></span>
<strong>Minecraft Modern Update verfügbar:</strong> Version <strong><?php echo esc_html( $latest['version'] ); ?></strong> ist bereit zum Download.
<a href="<?php echo esc_url( $latest['url'] ); ?>" target="_blank" style="margin-left: 10px; font-weight: bold;">Zum Download →</a>
</p>
</div>
<?php
}
}
add_action( 'admin_notices', 'minecraft_modern_show_update_notification' );
// === DASHBOARD WIDGET ===
function minecraft_modern_add_dashboard_widget() {
/**
* Fügt das Widget zum Dashboard hinzu
*/
public function add_dashboard_widget() {
wp_add_dashboard_widget(
'minecraft_modern_update_widget',
'mm_theme_status_widget',
'Minecraft Modern Theme Status',
'minecraft_modern_update_widget_function'
[ $this, 'render_widget_content' ]
);
}
add_action( 'wp_dashboard_setup', 'minecraft_modern_add_dashboard_widget' );
function minecraft_modern_update_widget_function() {
$current_version = minecraft_modern_get_theme_version();
$latest_release = minecraft_modern_get_latest_release_info();
/**
* HTML-Inhalt des Widgets
*/
public function render_widget_content() {
$current_version = wp_get_theme( $this->theme_slug )->get( 'Version' );
$latest = $this->get_latest_release();
echo '<p><strong>' . __( 'Current Version:', 'minecraft-modern-theme' ) . '</strong> ' . esc_html( $current_version ) . '</p>';
echo '<div class="mm-status-widget">';
echo '<p><span class="dashicons dashicons-admin-appearance"></span> <strong>Installiert:</strong> ' . esc_html( $current_version ) . '</p>';
if ( ! empty( $latest_release ) && isset( $latest_release['version'] ) ) {
echo '<p><strong>' . __( 'Latest Version:', 'minecraft-modern-theme' ) . '</strong> ' . esc_html( $latest_release['version'] ) . '</p>';
if ( isset( $latest['version'] ) ) {
echo '<p><span class="dashicons dashicons-cloud"></span> <strong>Aktuellste:</strong> ' . esc_html( $latest['version'] ) . '</p>';
if ( version_compare( $current_version, $latest_release['version'], '<' ) ) {
echo '<p><strong>' . __( 'Status:', 'minecraft-modern-theme' ) . '</strong> <span style="color:#d63638;">' . __( 'Update Available', 'minecraft-modern-theme' ) . '</span></p>';
echo '<p><a href="' . esc_url( $latest_release['download_url'] ) . '" class="button button-primary" target="_blank">' . __( 'Download Update', 'minecraft-modern-theme' ) . '</a></p>';
if ( version_compare( $current_version, $latest['version'], '<' ) ) {
echo '<div style="background: #fff8e5; border-left: 4px solid #ffb900; padding: 12px; margin: 15px 0;">';
echo '<p style="margin: 0 0 10px; color: #856404;"><strong>Update verfügbar!</strong></p>';
echo '<a href="' . esc_url( $latest['url'] ) . '" class="button button-primary" target="_blank">Download ZIP von Gitea</a>';
echo '</div>';
} else {
echo '<p><strong>' . __( 'Status:', 'minecraft-modern-theme' ) . '</strong> <span style="color:#46b450;">' . __( 'Up to Date', 'minecraft-modern-theme' ) . '</span></p>';
echo '<p style="color: #46b450; font-weight: bold; margin-top: 15px;">';
echo '<span class="dashicons dashicons-yes"></span> Theme ist aktuell.</p>';
}
} else {
echo '<p><strong>' . __( 'Status:', 'minecraft-modern-theme' ) . '</strong> ' . __( 'Unable to check for updates', 'minecraft-modern-theme' ) . '</p>';
echo '<p style="color: #d63638;"><span class="dashicons dashicons-warning"></span> Prüfung fehlgeschlagen.</p>';
}
// Link für "Jetzt prüfen"
$refresh_url = wp_nonce_url( admin_url( 'index.php?mm_clear_cache=1' ), 'mm_clear_cache_action' );
echo '<p><a href="' . esc_url( $refresh_url ) . '" onclick="return confirm(\'Cache leeren und neu prüfen?\');">' . __( 'Check for Updates Now', 'minecraft-modern-theme' ) . '</a></p>';
echo '<p><a href="https://git.viper.ipv64.net/M_Viper/Minecraft-Modern-Theme/releases" target="_blank">' . __( 'View All Releases', 'minecraft-modern-theme' ) . '</a></p>';
$refresh_url = wp_nonce_url( admin_url( 'index.php?mm_refresh_check=1' ), 'mm_refresh_action' );
echo '<hr><p><small><a href="' . esc_url( $refresh_url ) . '">Update-Cache jetzt leeren</a></small></p>';
echo '</div>';
}
/**
* Verarbeitet den Klick auf "Jetzt prüfen"
*/
public function handle_refresh_request() {
if ( isset( $_GET['mm_refresh_check'] ) && check_admin_referer( 'mm_refresh_action' ) ) {
delete_transient( $this->transient_key );
wp_redirect( admin_url( 'index.php' ) );
exit;
}
}
}
// Initialisierung
new Minecraft_Modern_Theme_Manager();