From b7a1a2889f98017332c61d0c44011301222a31b5 Mon Sep 17 00:00:00 2001 From: Marcus Quinn Date: Thu, 13 Mar 2025 00:47:22 +0000 Subject: [PATCH] Add CSS minification, AJAX settings, and modern admin styling --- admin/js/wpa-superstar-admin.js | 4 ++-- includes/speed-functions.php | 1 - wpa-superstar-plugin.php | 9 +++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/admin/js/wpa-superstar-admin.js b/admin/js/wpa-superstar-admin.js index 249a7bb..5014e1b 100644 --- a/admin/js/wpa-superstar-admin.js +++ b/admin/js/wpa-superstar-admin.js @@ -2,11 +2,11 @@ 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, { + $.post(wpaSuperstar.ajaxurl, { action: 'wpa_superstar_update_option', option: option, value: value, - nonce: '' + nonce: wpaSuperstar.nonce }, function(response) { console.log(response); }); diff --git a/includes/speed-functions.php b/includes/speed-functions.php index ad704f4..1aabef1 100644 --- a/includes/speed-functions.php +++ b/includes/speed-functions.php @@ -17,7 +17,6 @@ function wpa_superstar_lazy_load_images( $content ) { add_filter( 'the_content', 'wpa_superstar_lazy_load_images' ); add_filter( 'wp_get_attachment_image', 'wpa_superstar_lazy_load_images' ); -// After lazy load function function wpa_superstar_minify_css( $html ) { if ( is_admin() || ! get_option( 'wpa_superstar_minify_css', 0 ) ) { return $html; diff --git a/wpa-superstar-plugin.php b/wpa-superstar-plugin.php index 900b444..1ecdaaf 100644 --- a/wpa-superstar-plugin.php +++ b/wpa-superstar-plugin.php @@ -36,6 +36,15 @@ if ( is_admin() ) { require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php'; } +// Localize script for AJAX +function wpa_superstar_localize_script() { + wp_localize_script( 'wpa-superstar-admin', 'wpaSuperstar', [ + 'ajaxurl' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'wpa-superstar-nonce' ) + ] ); +} +add_action( 'admin_enqueue_scripts', 'wpa_superstar_localize_script' ); + // Admin assets function wpa_superstar_admin_assets() { wp_enqueue_style( 'wpa-superstar-admin', plugins_url( 'admin/css/wpa-superstar-admin.css', __FILE__ ), [], WPA_SUPERSTAR_VERSION );