From 10dc0e2d72949fa66fd82495a5feb12f3d58aaab Mon Sep 17 00:00:00 2001 From: Marcus Quinn Date: Sun, 16 Mar 2025 02:58:51 +0000 Subject: [PATCH] Fix panel border radius, chevron size, and plugins/theme loading --- admin/css/wp-allstars-admin.css | 7 +- admin/js/wp-allstars-admin.js | 109 +++++++++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 4 deletions(-) diff --git a/admin/css/wp-allstars-admin.css b/admin/css/wp-allstars-admin.css index 27296a9..b3fb683 100644 --- a/admin/css/wp-allstars-admin.css +++ b/admin/css/wp-allstars-admin.css @@ -192,6 +192,8 @@ input:checked + .wp-toggle-slider:before { padding: 24px; background: #f9f9f9; display: none; + border-bottom-left-radius: 8px; + border-bottom-right-radius: 8px; } .wp-allstars-toggle .description { @@ -241,10 +243,11 @@ input:checked + .wp-toggle-slider:before { .wp-allstars-toggle-header::after { content: ""; display: block; - width: 16px; - height: 16px; + width: 20px; + height: 20px; background: url('data:image/svg+xml;utf8,') no-repeat center; transition: transform 0.2s ease; + background-size: 20px; } .wp-allstars-toggle-header[aria-expanded="true"]::after { diff --git a/admin/js/wp-allstars-admin.js b/admin/js/wp-allstars-admin.js index f75d8fd..0dbc3a9 100644 --- a/admin/js/wp-allstars-admin.js +++ b/admin/js/wp-allstars-admin.js @@ -49,7 +49,7 @@ jQuery(document).ready(function($) { action: 'wp_allstars_update_option', option: option, value: value, - nonce: wpAllstarsData.nonce + nonce: wpAllstars.nonce }, success: function(response) { if (response.success) { @@ -148,7 +148,7 @@ jQuery(document).ready(function($) { data: { action: 'wp_allstars_get_plugins', category: category || 'minimal', - _ajax_nonce: wpAllstarsData.nonce + _ajax_nonce: wpAllstars.nonce }, success: function(response) { if (response.success) { @@ -166,4 +166,109 @@ jQuery(document).ready(function($) { } }); } + + // Load theme on page load + if ($('#wpa-theme-list').length) { + loadTheme(); + } + + // Function to load theme + function loadTheme() { + // Show loading overlay + $('.wpa-loading-overlay').fadeIn(); + + $.ajax({ + url: ajaxurl, + data: { + action: 'wp_allstars_get_theme', + _ajax_nonce: wpAllstars.nonce + }, + success: function(response) { + if (response.success) { + $('#wpa-theme-list').html(response.data); + initThemeHandlers(); + } else { + console.error('Server returned error:', response); + $('#wpa-theme-list').html('

Failed to load theme: ' + (response.data || 'Unknown error') + '

'); + } + $('.wpa-loading-overlay').fadeOut(); + }, + error: function(xhr, status, error) { + console.error('Failed to load theme:', {xhr: xhr, status: status, error: error}); + $('#wpa-theme-list').html('

Failed to load theme. Please try again. Error: ' + error + '

'); + $('.wpa-loading-overlay').fadeOut(); + } + }); + } + + // Initialize theme handlers + function initThemeHandlers() { + // Handle theme installation + $('.install-theme').on('click', function(e) { + e.preventDefault(); + var $button = $(this); + var slug = $button.data('slug'); + + $button.addClass('updating-message').text('Installing...'); + + wp.updates.installTheme({ + slug: slug, + success: function(response) { + $button + .removeClass('updating-message install-theme') + .addClass('button-primary activate-theme') + .text('Activate'); + + // Refresh the theme display + loadTheme(); + }, + error: function(error) { + $button.removeClass('updating-message'); + console.error('Theme installation failed:', error); + if (error.errorMessage) { + alert(error.errorMessage); + } + } + }); + }); + + // Handle theme activation + $('.activate-theme').on('click', function(e) { + e.preventDefault(); + var $button = $(this); + var slug = $button.data('slug'); + + $button.addClass('updating-message').text('Activating...'); + + $.ajax({ + url: ajaxurl, + type: 'POST', + data: { + action: 'wp_allstars_activate_theme', + theme: slug, + _ajax_nonce: wpAllstars.nonce + }, + success: function(response) { + if (response.success) { + $button.removeClass('updating-message').text('Activated'); + setTimeout(function() { + if (response.data && response.data.customize_url) { + window.location.href = response.data.customize_url; + } else { + window.location.reload(); + } + }, 1000); + } else { + $button.removeClass('updating-message').text('Activate'); + alert(response.data || 'Theme activation failed. Please try again.'); + } + }, + error: function(xhr, status, error) { + $button.removeClass('updating-message').text('Activate'); + console.error('Theme activation failed:', error); + alert('Theme activation failed: ' + error); + } + }); + }); + } }); \ No newline at end of file