admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('apus_admin_nonce'), 'strings' => array( 'selectImage' => __('Select Image', 'apus-theme'), 'useImage' => __('Use Image', 'apus-theme'), 'removeImage' => __('Remove Image', 'apus-theme'), 'confirmReset' => __('Are you sure you want to reset all options to default values? This cannot be undone.', 'apus-theme'), 'saved' => __('Settings saved successfully!', 'apus-theme'), 'error' => __('An error occurred while saving settings.', 'apus-theme'), ), )); } add_action('admin_enqueue_scripts', 'apus_enqueue_admin_scripts'); /** * Add settings link to theme actions */ function apus_add_settings_link($links) { $settings_link = '' . __('Settings', 'apus-theme') . ''; array_unshift($links, $settings_link); return $links; } add_filter('theme_action_links_' . get_template(), 'apus_add_settings_link'); /** * AJAX handler for resetting options */ function apus_reset_options_ajax() { check_ajax_referer('apus_admin_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Insufficient permissions.', 'apus-theme'))); } // Delete options to reset to defaults delete_option('apus_theme_options'); wp_send_json_success(array('message' => __('Options reset to defaults successfully.', 'apus-theme'))); } add_action('wp_ajax_apus_reset_options', 'apus_reset_options_ajax'); /** * AJAX handler for exporting options */ function apus_export_options_ajax() { check_ajax_referer('apus_admin_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Insufficient permissions.', 'apus-theme'))); } $options = get_option('apus_theme_options', array()); wp_send_json_success(array( 'data' => json_encode($options, JSON_PRETTY_PRINT), 'filename' => 'apus-theme-options-' . date('Y-m-d') . '.json' )); } add_action('wp_ajax_apus_export_options', 'apus_export_options_ajax'); /** * AJAX handler for importing options */ function apus_import_options_ajax() { check_ajax_referer('apus_admin_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Insufficient permissions.', 'apus-theme'))); } if (!isset($_POST['import_data'])) { wp_send_json_error(array('message' => __('No import data provided.', 'apus-theme'))); } $import_data = json_decode(stripslashes($_POST['import_data']), true); if (json_last_error() !== JSON_ERROR_NONE) { wp_send_json_error(array('message' => __('Invalid JSON data.', 'apus-theme'))); } // Sanitize imported data $sanitized_data = apus_sanitize_options($import_data); // Update options update_option('apus_theme_options', $sanitized_data); wp_send_json_success(array('message' => __('Options imported successfully.', 'apus-theme'))); } add_action('wp_ajax_apus_import_options', 'apus_import_options_ajax'); /** * Add admin notices */ function apus_admin_notices() { $screen = get_current_screen(); if ($screen->id !== 'appearance_page_apus-theme-options') { return; } // Check if settings were updated if (isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true') { ?>