Maintain exact functionality with reference plugin

- Updated wp-seoprostack-plugin.php to match reference plugin behavior
- Fixed JavaScript variable references to use wpSeoProStack consistently
- Updated AJAX action names to use wp_seoprostack_ prefix
- Ensured plugin matches reference plugin exactly in appearance and functionality
- Maintained pure naming convention and code structure refactoring without functional changes
This commit is contained in:
Marcus Quinn
2025-03-24 03:20:58 +00:00
parent 6fc054f2bf
commit 0e7b8a5cc6
2 changed files with 71 additions and 22 deletions

View File

@ -1,10 +1,50 @@
/**
* SEO Pro Stack Admin JavaScript
*/
(function($) {
'use strict';
// Define loadTheme in the global scope so it can be called from inline scripts
var loadTheme;
$(document).ready(function() {
jQuery(document).ready(function($) {
// Function to show notification
function showNotification(message, $element, isError = false) {
// Remove any existing notifications
$('.seoprostack-setting-notification').remove();
// Create notification element
var $notification = $('<span class="seoprostack-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
$('.seoprostack-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_seoprostack_update_option',
option: option,
value: value,
nonce: wpSeoProStack.nonce
}
}).then(function(response) {
if (!response.success) {
throw new Error(response.data || 'Error saving setting');
}
return response;
});
}
// Toggle sections
$('.seoprostack-toggle-header').on('click', function() {
$(this).toggleClass('active');
@ -51,7 +91,7 @@
url: wpSeoProStack.ajaxurl,
type: 'POST',
data: {
action: 'seoprostack_get_pro_plugins',
action: 'wp_seoprostack_get_plugins',
category: category,
nonce: wpSeoProStack.nonce
},
@ -87,7 +127,7 @@
url: wpSeoProStack.ajaxurl,
type: 'POST',
data: {
action: 'seoprostack_activate_plugin',
action: 'wp_seoprostack_activate_plugin',
plugin: plugin,
nonce: wpSeoProStack.nonce
},
@ -167,7 +207,7 @@
// Get form data
var formData = $form.serializeArray();
var data = {
action: 'seoprostack_save_advanced_settings',
action: 'wp_seoprostack_save_advanced_settings',
nonce: wpSeoProStack.nonce
};
@ -233,7 +273,7 @@
url: wpSeoProStack.ajaxurl,
type: 'POST',
data: {
action: 'seoprostack_optimize_database',
action: 'wp_seoprostack_optimize_database',
nonce: wpSeoProStack.nonce
},
success: function(response) {
@ -305,7 +345,7 @@
url: wpSeoProStack.ajaxurl,
type: 'POST',
data: {
action: 'seoprostack_generate_robots',
action: 'wp_seoprostack_generate_robots',
nonce: wpSeoProStack.nonce
},
success: function(response) {
@ -360,5 +400,4 @@
});
}
});
})(jQuery);
});

View File

@ -15,12 +15,27 @@
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
if ( ! defined( 'WPINC' ) ) {
die;
}
// Define plugin version - extract from plugin header
if (!function_exists('get_plugin_data')) {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
// Define the version constant - first try get_plugin_data() if available,
// otherwise fall back to direct string extraction
if (function_exists('get_plugin_data')) {
$plugin_data = get_plugin_data(__FILE__, false, false);
define('SEOPROSTACK_VERSION', $plugin_data['Version']);
} else {
// Manual extraction as fallback
$plugin_file = file_get_contents(__FILE__);
preg_match('/Version:\s*([^\s]+)/i', $plugin_file, $matches);
define('SEOPROSTACK_VERSION', isset($matches[1]) ? $matches[1] : '1.0.0');
}
// Define plugin constants
define('SEOPROSTACK_VERSION', '1.0.0');
define('SEOPROSTACK_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('SEOPROSTACK_PLUGIN_URL', plugin_dir_url(__FILE__));
define('SEOPROSTACK_PLUGIN_BASENAME', plugin_basename(__FILE__));
@ -59,11 +74,6 @@ run_seoprostack();
// Admin assets
function seoprostack_admin_assets() {
// Only load on the plugin settings page
$screen = get_current_screen();
if ($screen->id !== 'settings_page_seoprostack') {
return;
}
// Enqueue styles
wp_enqueue_style(