diff --git a/admin/css/wpa-superstar-admin.css b/admin/css/wpa-superstar-admin.css new file mode 100644 index 0000000..6546d45 --- /dev/null +++ b/admin/css/wpa-superstar-admin.css @@ -0,0 +1,14 @@ +.wpa-superstar-wrap { + max-width: 800px; + background: #fff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); +} +.wpa-superstar-wrap h1 { + font-size: 24px; + margin-bottom: 20px; +} +.wpa-superstar-toggle { + margin: 10px 0; +} \ No newline at end of file diff --git a/admin/js/wpa-superstar-admin.js b/admin/js/wpa-superstar-admin.js new file mode 100644 index 0000000..249a7bb --- /dev/null +++ b/admin/js/wpa-superstar-admin.js @@ -0,0 +1,14 @@ +jQuery(document).ready(function($) { + $('.wpa-superstar-toggle input').on('change', function() { + var option = $(this).attr('name'); + var value = $(this).is(':checked') ? 1 : 0; + $.post(ajaxurl, { + action: 'wpa_superstar_update_option', + option: option, + value: value, + nonce: '' + }, function(response) { + console.log(response); + }); + }); +}); \ No newline at end of file diff --git a/admin/settings.php b/admin/settings.php index 35e88cb..ead082b 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -18,28 +18,40 @@ add_action( 'admin_menu', 'wpa_superstar_admin_menu' ); // Register settings function wpa_superstar_register_settings() { register_setting( 'wpa-superstar-settings', 'wpa_superstar_lazy_load' ); + register_setting( 'wpa-superstar-settings', 'wpa_superstar_minify_css' ); } add_action( 'admin_init', 'wpa_superstar_register_settings' ); +// AJAX handler +function wpa_superstar_update_option() { + check_ajax_referer( 'wpa-superstar-nonce', 'nonce' ); + $option = sanitize_text_field( $_POST['option'] ); + $value = intval( $_POST['value'] ); + update_option( $option, $value ); + wp_send_json_success( 'Option updated' ); +} +add_action( 'wp_ajax_wpa_superstar_update_option', 'wpa_superstar_update_option' ); + // Settings page HTML function wpa_superstar_settings_page() { ?> -