Fix activation buttons for both free plugins grid and theme panel
This commit is contained in:
@ -206,6 +206,11 @@ jQuery(document).ready(function($) {
|
||||
|
||||
// Initialize plugin action buttons
|
||||
function initPluginActions() {
|
||||
// Remove any existing event handlers to prevent duplicates
|
||||
$('.plugin-card .install-now').off('click');
|
||||
$('.plugin-card .update-now').off('click');
|
||||
$('.plugin-card .activate-now').off('click');
|
||||
|
||||
// Install plugin
|
||||
$('.plugin-card .install-now').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
@ -219,10 +224,13 @@ jQuery(document).ready(function($) {
|
||||
success: function(response) {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Installed!');
|
||||
setTimeout(function() {
|
||||
$button.removeClass('updated-message install-now')
|
||||
.addClass('activate-now')
|
||||
.text('Activate')
|
||||
.attr('href', response.activateUrl);
|
||||
// Replace the button with an activate button
|
||||
var $parent = $button.parent();
|
||||
$button.remove();
|
||||
$parent.html('<a class="button activate-now" href="' + response.activateUrl + '" data-slug="' + slug + '" aria-label="Activate ' + slug + '">Activate</a>');
|
||||
|
||||
// Re-initialize the event handlers
|
||||
initPluginActions();
|
||||
}, 1000);
|
||||
},
|
||||
error: function(response) {
|
||||
@ -230,9 +238,7 @@ jQuery(document).ready(function($) {
|
||||
alert(response.errorMessage);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Update plugin
|
||||
$('.plugin-card .update-now').on('click', function(e) {
|
||||
@ -257,15 +263,14 @@ jQuery(document).ready(function($) {
|
||||
alert(response.errorMessage);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Activate plugin
|
||||
$('.plugin-card .activate-now').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var $button = $(this);
|
||||
var url = $button.attr('href');
|
||||
var slug = $button.data('slug');
|
||||
|
||||
$button.addClass('updating-message').text('Activating...');
|
||||
|
||||
@ -275,9 +280,10 @@ jQuery(document).ready(function($) {
|
||||
success: function() {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Activated!');
|
||||
setTimeout(function() {
|
||||
$button.removeClass('activate-now updated-message')
|
||||
.addClass('button-disabled')
|
||||
.text('Active');
|
||||
// Replace the button with an active button
|
||||
var $parent = $button.parent();
|
||||
$button.remove();
|
||||
$parent.html('<button type="button" class="button button-disabled" disabled="disabled">Active</button>');
|
||||
}, 1000);
|
||||
},
|
||||
error: function() {
|
||||
@ -285,13 +291,15 @@ jQuery(document).ready(function($) {
|
||||
alert('Failed to activate plugin. Please try again or activate from the Plugins page.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Initialize theme handlers
|
||||
function initThemeHandlers() {
|
||||
// Remove any existing event handlers to prevent duplicates
|
||||
$('.theme-actions .install-now').off('click');
|
||||
$('.theme-actions .activate-now').off('click');
|
||||
|
||||
// Install theme
|
||||
$('.theme-actions .install-now').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
@ -306,10 +314,13 @@ jQuery(document).ready(function($) {
|
||||
success: function(response) {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Installed!');
|
||||
setTimeout(function() {
|
||||
$button.removeClass('updated-message install-now')
|
||||
.addClass('activate-now')
|
||||
.text('Activate')
|
||||
.attr('href', response.activateUrl);
|
||||
// Replace the button with an activate button
|
||||
var $parent = $button.closest('.theme-actions');
|
||||
$button.remove();
|
||||
$parent.prepend('<button type="button" class="button button-primary activate-now" data-slug="' + slug + '" data-nonce="' + wpAllstars.nonce + '">Activate</button>');
|
||||
|
||||
// Re-initialize the event handlers
|
||||
initThemeHandlers();
|
||||
}, 1000);
|
||||
},
|
||||
error: function(response) {
|
||||
@ -340,9 +351,10 @@ jQuery(document).ready(function($) {
|
||||
if (response.success) {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Activated!');
|
||||
setTimeout(function() {
|
||||
$button.removeClass('activate-now updated-message')
|
||||
.addClass('button-disabled')
|
||||
.text('Active');
|
||||
// Replace the button with an active button
|
||||
var $parent = $button.closest('.theme-actions');
|
||||
$button.remove();
|
||||
$parent.prepend('<button type="button" class="button button-disabled" disabled="disabled">Active</button>');
|
||||
}, 1000);
|
||||
} else {
|
||||
$button.removeClass('updating-message').text('Activate');
|
||||
|
@ -22,7 +22,14 @@ if (!defined('ABSPATH')) {
|
||||
<?php if (current_user_can('install_themes')): ?>
|
||||
<?php
|
||||
$installed_theme = wp_get_theme('kadence');
|
||||
if ($installed_theme->exists()): ?>
|
||||
$current_theme = wp_get_theme();
|
||||
$is_active = ($current_theme->get_stylesheet() === 'kadence');
|
||||
|
||||
if ($is_active): ?>
|
||||
<button type="button" class="button button-disabled" disabled="disabled">
|
||||
<?php esc_html_e('Active'); ?>
|
||||
</button>
|
||||
<?php elseif ($installed_theme->exists()): ?>
|
||||
<button type="button" class="button button-primary activate-now" data-slug="kadence" data-nonce="<?php echo esc_attr(wp_create_nonce('wp-allstars-nonce')); ?>">
|
||||
<?php esc_html_e('Activate'); ?>
|
||||
</button>
|
||||
|
@ -1312,6 +1312,13 @@ function wp_allstars_activate_theme() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the theme object
|
||||
$theme_obj = wp_get_theme($theme);
|
||||
if (!$theme_obj->exists() || $theme_obj->errors()) {
|
||||
wp_send_json_error('Theme does not exist');
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch the theme
|
||||
switch_theme($theme);
|
||||
|
||||
|
Reference in New Issue
Block a user