Rename plugin to wp-seoprostack-plugin, update file structure
This commit is contained in:
364
admin/js/seoprostack-admin.js
Normal file
364
admin/js/seoprostack-admin.js
Normal file
@ -0,0 +1,364 @@
|
||||
/**
|
||||
* SEO Pro Stack Admin JavaScript
|
||||
*/
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
// Toggle sections
|
||||
$('.seoprostack-toggle-header').on('click', function() {
|
||||
$(this).toggleClass('active');
|
||||
$(this).next('.seoprostack-toggle-settings').slideToggle(300);
|
||||
});
|
||||
|
||||
// Tabs functionality (if not using WP default tabs)
|
||||
$('.seoprostack-tab-nav a').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var targetTab = $(this).attr('href').substring(1);
|
||||
|
||||
// Update active tab
|
||||
$('.seoprostack-tab-nav a').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
|
||||
// Show target tab content
|
||||
$('.seoprostack-tab-content').hide();
|
||||
$('#' + targetTab).show();
|
||||
|
||||
// Update URL without refreshing
|
||||
if (history.pushState) {
|
||||
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?page=seoprostack&tab=' + targetTab;
|
||||
window.history.pushState({path: newUrl}, '', newUrl);
|
||||
}
|
||||
});
|
||||
|
||||
// Pro Plugins Tab
|
||||
if ($('#pro-plugins').length) {
|
||||
// Category filter
|
||||
$('.seoprostack-category-filter a').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var category = $(this).data('category');
|
||||
|
||||
// Update active filter
|
||||
$('.seoprostack-category-filter a').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
|
||||
// Show loading
|
||||
$('#seoprostack-plugins-grid').addClass('loading');
|
||||
|
||||
// Load plugins
|
||||
$.ajax({
|
||||
url: seoProStack.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'seoprostack_get_pro_plugins',
|
||||
category: category,
|
||||
nonce: seoProStack.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
$('#seoprostack-plugins-grid').removeClass('loading');
|
||||
|
||||
if (response.success) {
|
||||
renderPlugins(response.data.plugins);
|
||||
} else {
|
||||
$('#seoprostack-plugins-grid').html('<div class="seoprostack-notice seoprostack-notice-error">' + response.data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#seoprostack-plugins-grid').removeClass('loading');
|
||||
$('#seoprostack-plugins-grid').html('<div class="seoprostack-notice seoprostack-notice-error">Error connecting to server</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Activate plugin
|
||||
$(document).on('click', '.seoprostack-activate-plugin', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $button = $(this);
|
||||
var plugin = $button.data('plugin');
|
||||
var $card = $button.closest('.seoprostack-plugin-card');
|
||||
|
||||
// Show loading
|
||||
$button.prop('disabled', true).text('Activating...');
|
||||
|
||||
// Send activation request
|
||||
$.ajax({
|
||||
url: seoProStack.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'seoprostack_activate_plugin',
|
||||
plugin: plugin,
|
||||
nonce: seoProStack.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
// Update UI
|
||||
$button.text('Activated').addClass('button-disabled');
|
||||
$card.find('.plugin-status').removeClass('not-installed installed').addClass('active').text('Active');
|
||||
} else {
|
||||
$button.prop('disabled', false).text('Activate');
|
||||
alert(response.data.message);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$button.prop('disabled', false).text('Activate');
|
||||
alert('Error connecting to server');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Render plugins
|
||||
function renderPlugins(plugins) {
|
||||
var html = '';
|
||||
|
||||
if (plugins.length === 0) {
|
||||
html = '<div class="seoprostack-notice seoprostack-notice-info">No plugins found in this category</div>';
|
||||
} else {
|
||||
plugins.forEach(function(plugin) {
|
||||
var statusClass = plugin.active ? 'active' : (plugin.status === 'installed' ? 'installed' : 'not-installed');
|
||||
var statusText = plugin.active ? 'Active' : (plugin.status === 'installed' ? 'Installed' : 'Not Installed');
|
||||
var buttonText = plugin.active ? 'Activated' : 'Activate';
|
||||
var buttonDisabled = plugin.active ? ' button-disabled' : '';
|
||||
|
||||
html += '<div class="seoprostack-plugin-card">';
|
||||
html += '<div class="seoprostack-plugin-card-header">';
|
||||
html += '<span class="plugin-status ' + statusClass + '">' + statusText + '</span>';
|
||||
html += '</div>';
|
||||
html += '<div class="seoprostack-plugin-card-content">';
|
||||
html += '<h3>' + plugin.name + ' <span class="version">v' + plugin.version + '</span></h3>';
|
||||
html += '<p>' + plugin.description + '</p>';
|
||||
html += '<div class="seoprostack-plugin-card-footer">';
|
||||
html += '<a href="' + plugin.url + '" class="button button-secondary" target="_blank">View Details</a>';
|
||||
|
||||
if (!plugin.active) {
|
||||
html += '<button class="button button-primary seoprostack-activate-plugin' + buttonDisabled + '" data-plugin="' + plugin.path + '">' + buttonText + '</button>';
|
||||
} else {
|
||||
html += '<button class="button button-primary' + buttonDisabled + '">' + buttonText + '</button>';
|
||||
}
|
||||
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
});
|
||||
}
|
||||
|
||||
$('#seoprostack-plugins-grid').html(html);
|
||||
}
|
||||
|
||||
// Load initial plugins
|
||||
$('.seoprostack-category-filter a.active').trigger('click');
|
||||
}
|
||||
|
||||
// Advanced Tab Form
|
||||
if ($('#seoprostack-advanced-settings-form').length) {
|
||||
$('#seoprostack-advanced-settings-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $form = $(this);
|
||||
var $button = $('#seoprostack-save-advanced-settings');
|
||||
var $spinner = $button.next('.spinner');
|
||||
var $response = $('#advanced-settings-response');
|
||||
|
||||
// Show loading
|
||||
$button.prop('disabled', true);
|
||||
$spinner.css('visibility', 'visible');
|
||||
|
||||
// Get form data
|
||||
var formData = $form.serializeArray();
|
||||
var data = {
|
||||
action: 'seoprostack_save_advanced_settings',
|
||||
nonce: seoProStack.nonce
|
||||
};
|
||||
|
||||
// Convert form data to proper format
|
||||
$.each(formData, function(i, field) {
|
||||
data[field.name] = field.value;
|
||||
});
|
||||
|
||||
// Add checkbox fields that might not be in formData
|
||||
$form.find('input[type="checkbox"]').each(function() {
|
||||
var name = $(this).attr('name');
|
||||
if (data[name] === undefined) {
|
||||
data[name] = 'no';
|
||||
}
|
||||
});
|
||||
|
||||
// Send AJAX request
|
||||
$.post(seoProStack.ajaxurl, data, function(response) {
|
||||
// Hide loading
|
||||
$button.prop('disabled', false);
|
||||
$spinner.css('visibility', 'hidden');
|
||||
|
||||
// Show response
|
||||
if (response.success) {
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-success">' + response.data.message + '</div>');
|
||||
} else {
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-error">' + response.data.message + '</div>');
|
||||
}
|
||||
|
||||
// Hide response after delay
|
||||
setTimeout(function() {
|
||||
$response.find('.seoprostack-notice').fadeOut(500, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 3000);
|
||||
}).fail(function() {
|
||||
// Hide loading
|
||||
$button.prop('disabled', false);
|
||||
$spinner.css('visibility', 'hidden');
|
||||
|
||||
// Show error
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-error">Error connecting to server</div>');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Tools Tab
|
||||
if ($('#tools').length) {
|
||||
// Database Optimization
|
||||
$('#seoprostack-optimize-db').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $button = $(this);
|
||||
var $spinner = $button.next('.spinner');
|
||||
var $response = $('#db-optimize-response');
|
||||
|
||||
// Show loading
|
||||
$button.prop('disabled', true);
|
||||
$spinner.css('visibility', 'visible');
|
||||
|
||||
// Send AJAX request
|
||||
$.ajax({
|
||||
url: seoProStack.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'seoprostack_optimize_database',
|
||||
nonce: seoProStack.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
// Hide loading
|
||||
$button.prop('disabled', false);
|
||||
$spinner.css('visibility', 'hidden');
|
||||
|
||||
// Show response
|
||||
if (response.success) {
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-success">' + response.data.message + '</div>');
|
||||
|
||||
// Update stats if provided
|
||||
if (response.data.stats) {
|
||||
updateDbStats(response.data.stats);
|
||||
}
|
||||
} else {
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-error">' + response.data.message + '</div>');
|
||||
}
|
||||
|
||||
// Hide response after delay
|
||||
setTimeout(function() {
|
||||
$response.find('.seoprostack-notice').fadeOut(500, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
},
|
||||
error: function() {
|
||||
// Hide loading
|
||||
$button.prop('disabled', false);
|
||||
$spinner.css('visibility', 'hidden');
|
||||
|
||||
// Show error
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-error">Error connecting to server</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Function to update database stats
|
||||
function updateDbStats(stats) {
|
||||
if (stats.total_cleaned) {
|
||||
$('#db-total-cleaned').text(stats.total_cleaned);
|
||||
}
|
||||
if (stats.db_size_before) {
|
||||
$('#db-size-before').text(stats.db_size_before);
|
||||
}
|
||||
if (stats.db_size_after) {
|
||||
$('#db-size-after').text(stats.db_size_after);
|
||||
}
|
||||
if (stats.savings_percentage) {
|
||||
$('#db-savings').text(stats.savings_percentage + '%');
|
||||
}
|
||||
}
|
||||
|
||||
// Generate Robots.txt
|
||||
$('#seoprostack-generate-robots').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $button = $(this);
|
||||
var $spinner = $button.next('.spinner');
|
||||
var $response = $('#robots-response');
|
||||
var $content = $('#robots-content');
|
||||
|
||||
// Show loading
|
||||
$button.prop('disabled', true);
|
||||
$spinner.css('visibility', 'visible');
|
||||
|
||||
// Send AJAX request
|
||||
$.ajax({
|
||||
url: seoProStack.ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'seoprostack_generate_robots',
|
||||
nonce: seoProStack.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
// Hide loading
|
||||
$button.prop('disabled', false);
|
||||
$spinner.css('visibility', 'hidden');
|
||||
|
||||
// Show response
|
||||
if (response.success) {
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-success">' + response.data.message + '</div>');
|
||||
|
||||
// Display robots.txt content
|
||||
if (response.data.content) {
|
||||
$content.val(response.data.content);
|
||||
$content.closest('.seoprostack-setting-row').show();
|
||||
}
|
||||
} else {
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-error">' + response.data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
// Hide loading
|
||||
$button.prop('disabled', false);
|
||||
$spinner.css('visibility', 'hidden');
|
||||
|
||||
// Show error
|
||||
$response.html('<div class="seoprostack-notice seoprostack-notice-error">Error connecting to server</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Copy to Clipboard Functionality
|
||||
$('.seoprostack-copy-to-clipboard').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var targetId = $(this).data('target');
|
||||
var $target = $('#' + targetId);
|
||||
var $button = $(this);
|
||||
var originalText = $button.text();
|
||||
|
||||
// Copy to clipboard
|
||||
$target.select();
|
||||
document.execCommand('copy');
|
||||
|
||||
// Update button text
|
||||
$button.text('Copied!');
|
||||
|
||||
// Reset button text
|
||||
setTimeout(function() {
|
||||
$button.text(originalText);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
@ -1,327 +0,0 @@
|
||||
// Define loadTheme in the global scope so it can be called from inline scripts
|
||||
var loadTheme;
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
// Function to show notification
|
||||
function showNotification(message, $element, isError = false) {
|
||||
// Remove any existing notifications
|
||||
$('.wp-setting-notification').remove();
|
||||
|
||||
// Create notification element
|
||||
var $notification = $('<span class="wp-setting-notification' + (isError ? ' error' : '') + '">' + message + '</span>');
|
||||
|
||||
// If element is provided, show notification next to it
|
||||
if ($element && $element.length) {
|
||||
$element.after($notification);
|
||||
} else {
|
||||
// Fallback to header if no element provided
|
||||
$('.wp-allstars-header h1').after($notification);
|
||||
}
|
||||
|
||||
// Fade out after delay
|
||||
setTimeout(function() {
|
||||
$notification.fadeOut(300, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// Handle option updates
|
||||
function updateOption(option, value) {
|
||||
return $.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_allstars_update_option',
|
||||
option: option,
|
||||
value: value,
|
||||
nonce: wpAllstars.nonce
|
||||
}
|
||||
}).then(function(response) {
|
||||
if (!response.success) {
|
||||
throw new Error(response.data || 'Error saving setting');
|
||||
}
|
||||
return response;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Handle toggle switch clicks
|
||||
$('.wp-toggle-switch').on('click', function(e) {
|
||||
e.stopPropagation();
|
||||
var $checkbox = $(this).find('input[type="checkbox"]');
|
||||
var isChecked = $checkbox.is(':checked');
|
||||
$checkbox.prop('checked', !isChecked).trigger('change');
|
||||
});
|
||||
|
||||
|
||||
// Prevent label clicks from toggling the checkbox directly
|
||||
$('.wp-setting-label, .wp-allstars-toggle-left label').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
|
||||
// Handle checkbox changes
|
||||
$('.wp-toggle-switch input[type="checkbox"]').on('change', function(e) {
|
||||
e.stopPropagation();
|
||||
var $input = $(this);
|
||||
var option = $input.attr('name');
|
||||
var value = $input.is(':checked') ? 1 : 0;
|
||||
var $label = $input.closest('.wp-setting-left, .wp-allstars-toggle-left').find('label');
|
||||
|
||||
updateOption(option, value)
|
||||
.then(function() {
|
||||
showNotification('Saved', $label);
|
||||
})
|
||||
.catch(function() {
|
||||
showNotification('Error saving settings', $label, true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Handle text input changes
|
||||
$('.wp-allstars-setting-row input[type="text"], .wp-allstars-setting-row input[type="number"], .wp-allstars-setting-row textarea').on('change', function() {
|
||||
var $input = $(this);
|
||||
var option = $input.attr('name');
|
||||
var value = $input.val();
|
||||
var $label = $input.closest('.wp-allstars-setting-row').find('label').first();
|
||||
|
||||
updateOption(option, value)
|
||||
.then(function() {
|
||||
showNotification('Saved', $label);
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.error('Error:', error);
|
||||
showNotification('Error saving setting', $label, true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Toggle expandable panels
|
||||
$('.wp-allstars-toggle-header').on('click', function(e) {
|
||||
if (!$(e.target).closest('.wp-toggle-switch').length &&
|
||||
!$(e.target).closest('label').length) {
|
||||
var $settings = $(this).closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
|
||||
var isExpanded = $(this).attr('aria-expanded') === 'true';
|
||||
|
||||
$(this).attr('aria-expanded', !isExpanded);
|
||||
$settings.slideToggle(200);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Set initial panel states
|
||||
$('.wp-allstars-toggle-header').each(function() {
|
||||
var $settings = $(this).closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
|
||||
var isExpanded = $(this).attr('aria-expanded') === 'true';
|
||||
|
||||
if (!isExpanded) {
|
||||
$settings.hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Remove JavaScript-based tab switching - let the native WordPress tab links work
|
||||
|
||||
// Plugin category filters
|
||||
if ($('#wpa-plugin-filters').length) {
|
||||
$('#wpa-plugin-filters a').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var category = $(this).data('category');
|
||||
|
||||
// Update active filter
|
||||
$('#wpa-plugin-filters a').removeClass('current');
|
||||
$(this).addClass('current');
|
||||
|
||||
// Load plugins for the selected category
|
||||
loadPlugins(category);
|
||||
});
|
||||
|
||||
|
||||
// Load initial plugins if we're on the recommended tab
|
||||
if ($('#recommended').is(':visible') && $('#wpa-plugin-list').is(':empty')) {
|
||||
loadPlugins('minimal');
|
||||
}
|
||||
}
|
||||
|
||||
// Load theme tab content if we're on the theme tab
|
||||
if ($('#theme').is(':visible') && $('#wpa-theme-list').length && $('#wpa-theme-list').is(':empty')) {
|
||||
loadTheme();
|
||||
}
|
||||
|
||||
// Function to load plugins
|
||||
function loadPlugins(category) {
|
||||
var $container = $('#wpa-plugin-list');
|
||||
var $loadingOverlay = $('<div class="wp-allstars-loading-overlay"><span class="spinner is-active"></span></div>');
|
||||
|
||||
// Show loading overlay
|
||||
$container.css('position', 'relative').append($loadingOverlay);
|
||||
|
||||
// Clear existing plugins
|
||||
$container.empty().append($loadingOverlay);
|
||||
|
||||
// AJAX request to get plugins
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wp_allstars_get_plugins',
|
||||
category: category,
|
||||
_wpnonce: wpAllstars.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
// Remove loading overlay
|
||||
$loadingOverlay.remove();
|
||||
|
||||
if (response.success) {
|
||||
// Append plugins HTML
|
||||
$container.html(response.data);
|
||||
|
||||
// Initialize plugin action buttons
|
||||
initPluginActions();
|
||||
|
||||
// Individual plugin card spinners have been removed
|
||||
} else {
|
||||
// Show error message
|
||||
$container.html('<div class="notice notice-error"><p>' + response.data + '</p></div>');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Remove loading overlay
|
||||
$loadingOverlay.remove();
|
||||
|
||||
// Show error message
|
||||
$container.html('<div class="notice notice-error"><p>Failed to load plugins. Please try again. Error: ' + error + '</p></div>');
|
||||
console.error('AJAX Error:', xhr.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Theme handlers are initialized directly from the inline script
|
||||
// We don't need a separate loadTheme function anymore
|
||||
|
||||
// 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();
|
||||
var $button = $(this);
|
||||
var slug = $button.data('slug');
|
||||
|
||||
$button.addClass('updating-message').text('Installing...');
|
||||
|
||||
wp.updates.installPlugin({
|
||||
slug: slug,
|
||||
success: function(response) {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Installed!');
|
||||
setTimeout(function() {
|
||||
// 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) {
|
||||
$button.removeClass('updating-message').text('Install Now');
|
||||
alert(response.errorMessage);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Update plugin
|
||||
$('.plugin-card .update-now').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var $button = $(this);
|
||||
var slug = $button.data('slug');
|
||||
|
||||
$button.addClass('updating-message').text('Updating...');
|
||||
|
||||
wp.updates.updatePlugin({
|
||||
slug: slug,
|
||||
success: function() {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Updated!');
|
||||
setTimeout(function() {
|
||||
$button.removeClass('update-now updated-message')
|
||||
.addClass('button-disabled')
|
||||
.text('Active');
|
||||
}, 1000);
|
||||
},
|
||||
error: function(response) {
|
||||
$button.removeClass('updating-message').text('Update Now');
|
||||
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...');
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: 'html',
|
||||
success: function() {
|
||||
$button.removeClass('updating-message').addClass('updated-message').text('Activated!');
|
||||
setTimeout(function() {
|
||||
// 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() {
|
||||
$button.removeClass('updating-message').text('Activate');
|
||||
alert('Failed to activate plugin. Please try again or activate from the Plugins page.');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize theme handlers
|
||||
function initThemeHandlers() {
|
||||
console.log('Initializing theme handlers');
|
||||
// Remove any existing event handlers to prevent duplicates
|
||||
$('.theme-actions .install-now').off('click');
|
||||
$('.theme-actions .activate-now').off('click');
|
||||
|
||||
// Install theme - use standard WordPress behavior
|
||||
$('.theme-actions .install-now').on('click', function(e) {
|
||||
// We're not preventing default here - let the standard WordPress installer handle it
|
||||
// Just add the updating message
|
||||
var $button = $(this);
|
||||
var slug = $button.data('slug');
|
||||
$button.addClass('updating-message').text('Installing...');
|
||||
console.log('Installing theme using standard WordPress URL:', $button.attr('href'));
|
||||
// The rest will be handled by WordPress core
|
||||
});
|
||||
|
||||
// Activate theme - use standard WordPress behavior
|
||||
$('.theme-actions .activate-now').on('click', function(e) {
|
||||
// We're not preventing default here - let the standard WordPress activation handle it
|
||||
// Just add the updating message
|
||||
var $button = $(this);
|
||||
var slug = $button.data('slug');
|
||||
$button.addClass('updating-message').text('Activating...');
|
||||
console.log('Activating theme using standard WordPress URL:', $button.attr('href'));
|
||||
// The rest will be handled by WordPress core
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user