From ae4ec1dc30eca9e8b37257c7b9cf3434c86987e0 Mon Sep 17 00:00:00 2001 From: M_Viper Date: Tue, 6 Jan 2026 23:18:47 +0000 Subject: [PATCH] Minecraft-Modern-Theme/functions.php aktualisiert --- Minecraft-Modern-Theme/functions.php | 70 +++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/Minecraft-Modern-Theme/functions.php b/Minecraft-Modern-Theme/functions.php index 5b8bb40..055a448 100644 --- a/Minecraft-Modern-Theme/functions.php +++ b/Minecraft-Modern-Theme/functions.php @@ -16,7 +16,7 @@ function minecraft_modern_setup() { 'width' => 9999, // Sehr hohe Werte, um den Crop-Dialog zu umgehen 'flex-height' => true, 'flex-width' => true, - 'header-text' => array( 'site-title', 'site-description' ), + 'header_text' => array( 'site-title', 'site-description' ), ) ); // Benutzerdefinierten Hintergrund aktivieren @@ -425,4 +425,70 @@ function minecraft_modern_scroll_to_top_script() { true ); } -add_action('wp_enqueue_scripts', 'minecraft_modern_scroll_to_top_script'); \ No newline at end of file +add_action('wp_enqueue_scripts', 'minecraft_modern_scroll_to_top_script'); + +// ============================================================================= +// === THEME SETTINGS EXPORT / IMPORT (KORRIGIERTE VERSION) ================= +// ============================================================================= + +// 1. Export Handler (Download) +add_action( 'admin_post_export_theme_settings', 'handle_theme_settings_export' ); + +function handle_theme_settings_export() { + // Sicherheitscheck + if ( ! current_user_can( 'edit_theme_options' ) ) { + wp_die( __( 'Du hast keine Berechtigung, diese Aktion auszuführen.', 'minecraft-modern-theme' ) ); + } + + // Theme Slug ermitteln + $theme_slug = get_option( 'stylesheet' ); + + // Alle Einstellungen holen + $mods = get_theme_mods(); + + // Daten als JSON vorbereiten + $data = json_encode( $mods, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); + + // Header für Download setzen + header( 'Content-Type: application/json; charset=utf-8' ); + header( 'Content-Disposition: attachment; filename=' . $theme_slug . '-settings-' . date( 'Y-m-d' ) . '.json' ); + header( 'Pragma: no-cache' ); + header( 'Expires: 0' ); + + echo $data; + exit; +} + +// 2. Import Handler (AJAX) +add_action( 'wp_ajax_import_theme_settings', 'handle_theme_settings_import' ); + +function handle_theme_settings_import() { + // Sicherheitscheck & Nonce + if ( ! current_user_can( 'edit_theme_options' ) ) { + wp_send_json_error( __( 'Keine Berechtigung.', 'minecraft-modern-theme' ) ); + } + + check_ajax_referer( 'theme-import-nonce', 'nonce' ); + + if ( empty( $_FILES['import_file']['tmp_name'] ) ) { + wp_send_json_error( __( 'Keine Datei hochgeladen.', 'minecraft-modern-theme' ) ); + } + + // Datei einlesen + $file = $_FILES['import_file']['tmp_name']; + $json_content = file_get_contents( $file ); + $data = json_decode( $json_content, true ); + + // JSON validieren + if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $data ) ) { + wp_send_json_error( __( 'Die hochgeladene Datei ist keine gültige JSON-Datei.', 'minecraft-modern-theme' ) ); + } + + // Einstellungen in die Datenbank schreiben + foreach ( $data as $mod_key => $mod_value ) { + set_theme_mod( $mod_key, $mod_value ); + } + + wp_send_json_success( __( 'Einstellungen erfolgreich importiert! Die Seite wird neu geladen...', 'minecraft-modern-theme' ) ); +} +