Add theme installation functionality: - Add JavaScript handlers for theme installation and activation - Use wp.updates.installTheme for installation - Add proper error handling and status messages - Refresh theme display after installation
This commit is contained in:
@ -510,6 +510,9 @@ function wpa_superstar_settings_page() {
|
|||||||
ensureMinLoadingTime(function() {
|
ensureMinLoadingTime(function() {
|
||||||
$('#wpa-theme-list').html(response.data);
|
$('#wpa-theme-list').html(response.data);
|
||||||
$('.wpa-loading-overlay').fadeOut();
|
$('.wpa-loading-overlay').fadeOut();
|
||||||
|
|
||||||
|
// Initialize theme installation handlers
|
||||||
|
initThemeHandlers();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error('Server returned error:', response);
|
console.error('Server returned error:', response);
|
||||||
@ -525,6 +528,75 @@ function wpa_superstar_settings_page() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: 'switch_theme',
|
||||||
|
stylesheet: slug,
|
||||||
|
_wpnonce: '<?php echo wp_create_nonce("switch-theme_" . "kadence"); ?>'
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.success) {
|
||||||
|
$button
|
||||||
|
.removeClass('updating-message')
|
||||||
|
.text('Activated');
|
||||||
|
|
||||||
|
// Optionally redirect to customize page
|
||||||
|
window.location.href = '<?php echo admin_url("customize.php"); ?>';
|
||||||
|
} else {
|
||||||
|
$button.removeClass('updating-message');
|
||||||
|
console.error('Theme activation failed:', response);
|
||||||
|
alert('Theme activation failed. Please try again.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
$button.removeClass('updating-message');
|
||||||
|
console.error('Theme activation failed:', error);
|
||||||
|
alert('Theme activation failed. Please try again.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Function to ensure minimum loading time
|
// Function to ensure minimum loading time
|
||||||
function ensureMinLoadingTime(callback) {
|
function ensureMinLoadingTime(callback) {
|
||||||
var currentTime = Date.now();
|
var currentTime = Date.now();
|
||||||
|
Reference in New Issue
Block a user