Fix theme installation button to use standard WordPress URL format
This commit is contained in:
@ -301,64 +301,15 @@ jQuery(document).ready(function($) {
|
|||||||
$('.theme-actions .install-now').off('click');
|
$('.theme-actions .install-now').off('click');
|
||||||
$('.theme-actions .activate-now').off('click');
|
$('.theme-actions .activate-now').off('click');
|
||||||
|
|
||||||
// Install theme - use WordPress AJAX-based installation
|
// Install theme - use standard WordPress behavior
|
||||||
$('.theme-actions .install-now').on('click', function(e) {
|
$('.theme-actions .install-now').on('click', function(e) {
|
||||||
e.preventDefault();
|
// We're not preventing default here - let the standard WordPress installer handle it
|
||||||
|
// Just add the updating message
|
||||||
var $button = $(this);
|
var $button = $(this);
|
||||||
var slug = $button.data('slug');
|
var slug = $button.data('slug');
|
||||||
var themeName = $button.data('name') || slug;
|
|
||||||
|
|
||||||
console.log('Installing theme via AJAX:', slug);
|
|
||||||
$button.addClass('updating-message').text('Installing...');
|
$button.addClass('updating-message').text('Installing...');
|
||||||
|
console.log('Installing theme using standard WordPress URL:', $button.attr('href'));
|
||||||
// Make sure wp.updates is available
|
// The rest will be handled by WordPress core
|
||||||
if (typeof wp === 'undefined' || typeof wp.updates === 'undefined' || typeof wp.updates.installTheme === 'undefined') {
|
|
||||||
console.error('WordPress updates API not available');
|
|
||||||
$button.removeClass('updating-message').text('Install');
|
|
||||||
alert('WordPress updates API not available. Please try again or install the theme from the Themes page.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the WordPress core updates API for AJAX installation
|
|
||||||
wp.updates.installTheme({
|
|
||||||
slug: slug,
|
|
||||||
// Make sure we pass the correct nonce
|
|
||||||
_ajax_nonce: $button.data('api-nonce') || wpAllstars.updateNonce,
|
|
||||||
success: function(response) {
|
|
||||||
console.log('Theme installed successfully:', response);
|
|
||||||
$button.removeClass('updating-message').addClass('updated-message').text('Installed!');
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
// Replace the button with an activate button
|
|
||||||
var $parent = $button.closest('.theme-actions');
|
|
||||||
$button.remove();
|
|
||||||
|
|
||||||
// Create a proper activation link
|
|
||||||
var activateUrl = '';
|
|
||||||
if (response.activateUrl) {
|
|
||||||
activateUrl = response.activateUrl;
|
|
||||||
} else {
|
|
||||||
var nonce = wp.updates.data.activateNonce || wpAllstars.nonce;
|
|
||||||
activateUrl = 'themes.php?action=activate&stylesheet=' + slug + '&_wpnonce=' + nonce;
|
|
||||||
}
|
|
||||||
|
|
||||||
var adminUrl = wpAllstars.adminUrl || ajaxurl.replace('/admin-ajax.php', '/');
|
|
||||||
var $activateButton = $('<a class="button button-primary activate-now" href="' + adminUrl + activateUrl + '">Activate</a>');
|
|
||||||
$activateButton.attr('data-slug', slug);
|
|
||||||
$activateButton.attr('data-name', themeName);
|
|
||||||
|
|
||||||
$parent.prepend($activateButton);
|
|
||||||
|
|
||||||
// Re-initialize the event handlers
|
|
||||||
initThemeHandlers();
|
|
||||||
}, 1000);
|
|
||||||
},
|
|
||||||
error: function(response) {
|
|
||||||
console.error('Theme installation failed:', response);
|
|
||||||
$button.removeClass('updating-message').text('Install');
|
|
||||||
alert(response.errorMessage || 'Failed to install theme. Please try again.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Activate theme - use standard WordPress behavior
|
// Activate theme - use standard WordPress behavior
|
||||||
|
@ -39,7 +39,14 @@ if (!defined('ABSPATH')) {
|
|||||||
<?php esc_html_e('Activate'); ?>
|
<?php esc_html_e('Activate'); ?>
|
||||||
</a>
|
</a>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<button type="button"
|
<?php
|
||||||
|
// Use the standard WordPress theme installation URL format
|
||||||
|
$install_url = wp_nonce_url(
|
||||||
|
admin_url('update.php?action=install-theme&theme=kadence'),
|
||||||
|
'install-theme_kadence'
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
<a href="<?php echo esc_url($install_url); ?>"
|
||||||
class="button button-primary install-now"
|
class="button button-primary install-now"
|
||||||
data-slug="kadence"
|
data-slug="kadence"
|
||||||
data-name="Kadence"
|
data-name="Kadence"
|
||||||
@ -47,10 +54,11 @@ if (!defined('ABSPATH')) {
|
|||||||
data-nonce="<?php echo esc_attr($nonce); ?>"
|
data-nonce="<?php echo esc_attr($nonce); ?>"
|
||||||
aria-label="<?php esc_attr_e('Install Kadence'); ?>">
|
aria-label="<?php esc_attr_e('Install Kadence'); ?>">
|
||||||
<?php esc_html_e('Install'); ?>
|
<?php esc_html_e('Install'); ?>
|
||||||
</button>
|
</a>
|
||||||
<script>
|
<script>
|
||||||
console.log('Theme installation button initialized with:', {
|
console.log('Theme installation button initialized with:', {
|
||||||
slug: 'kadence',
|
slug: 'kadence',
|
||||||
|
url: '<?php echo esc_js($install_url); ?>',
|
||||||
nonce: '<?php echo esc_js(wp_create_nonce("updates")); ?>'
|
nonce: '<?php echo esc_js(wp_create_nonce("updates")); ?>'
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user