Minecraft-Modern-Theme/functions.php aktualisiert
This commit is contained in:
@@ -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');
|
||||
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' ) );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user