Rename plugin to wp-seoprostack-plugin, update file structure

This commit is contained in:
Marcus Quinn
2025-03-24 02:48:06 +00:00
parent 18b0a2c246
commit aee3cb91e2
35 changed files with 5455 additions and 655 deletions

View File

@ -0,0 +1,132 @@
<?php
/**
* The Advanced Settings AJAX handler.
*
* @package SEO_Pro_Stack
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
}
/**
* The Advanced Settings AJAX handler.
*/
class SEOProStack_AJAX_Advanced {
/**
* Initialize the AJAX handlers.
*/
public function init() {
add_action('wp_ajax_seoprostack_save_advanced_settings', array($this, 'save_advanced_settings'));
add_action('wp_ajax_seoprostack_optimize_database', array($this, 'optimize_database'));
}
/**
* Save advanced settings.
*/
public function save_advanced_settings() {
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
}
// Check capabilities
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => 'You do not have permission to change settings'));
}
// Get settings
$settings = array(
'disable_emojis' => isset($_POST['disable_emojis']) ? sanitize_text_field($_POST['disable_emojis']) : 'no',
'disable_embeds' => isset($_POST['disable_embeds']) ? sanitize_text_field($_POST['disable_embeds']) : 'no',
'remove_query_strings' => isset($_POST['remove_query_strings']) ? sanitize_text_field($_POST['remove_query_strings']) : 'no',
'disable_xmlrpc' => isset($_POST['disable_xmlrpc']) ? sanitize_text_field($_POST['disable_xmlrpc']) : 'no',
'remove_shortlink' => isset($_POST['remove_shortlink']) ? sanitize_text_field($_POST['remove_shortlink']) : 'no',
'remove_rsd_link' => isset($_POST['remove_rsd_link']) ? sanitize_text_field($_POST['remove_rsd_link']) : 'no',
'remove_wlwmanifest_link' => isset($_POST['remove_wlwmanifest_link']) ? sanitize_text_field($_POST['remove_wlwmanifest_link']) : 'no',
'disable_self_pingbacks' => isset($_POST['disable_self_pingbacks']) ? sanitize_text_field($_POST['disable_self_pingbacks']) : 'no',
'disable_feed_links' => isset($_POST['disable_feed_links']) ? sanitize_text_field($_POST['disable_feed_links']) : 'no',
'remove_rest_api_links' => isset($_POST['remove_rest_api_links']) ? sanitize_text_field($_POST['remove_rest_api_links']) : 'no',
'minify_html' => isset($_POST['minify_html']) ? sanitize_text_field($_POST['minify_html']) : 'no',
'minify_css' => isset($_POST['minify_css']) ? sanitize_text_field($_POST['minify_css']) : 'no',
'minify_js' => isset($_POST['minify_js']) ? sanitize_text_field($_POST['minify_js']) : 'no'
);
// Save settings
update_option('seoprostack_advanced_settings', $settings);
// Flush rewrite rules if necessary
if (isset($settings['disable_feed_links']) && $settings['disable_feed_links'] === 'yes') {
flush_rewrite_rules();
}
// Send response
wp_send_json_success(array('message' => 'Settings saved successfully'));
}
/**
* Optimize database.
*/
public function optimize_database() {
global $wpdb;
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
}
// Check capabilities
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => 'You do not have permission to optimize database'));
}
// Tables to optimize
$tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'");
$optimized = 0;
$failed = 0;
foreach ($tables as $table) {
$result = $wpdb->query("OPTIMIZE TABLE $table");
if ($result === false) {
$failed++;
} else {
$optimized++;
}
}
// Delete post revisions
$deleted_revisions = $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
// Delete auto drafts
$deleted_drafts = $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
// Delete trashed posts
$deleted_trash = $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'trash'");
// Delete spam comments
$deleted_spam = $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
// Delete trashed comments
$deleted_trash_comments = $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
// Delete expired transients
$deleted_transients = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_%' AND option_name NOT LIKE '_transient_timeout_%'");
// Send response
wp_send_json_success(array(
'message' => sprintf(
'Database optimization complete. %d tables optimized, %d revisions deleted, %d auto-drafts deleted, %d trash posts deleted, %d spam comments deleted, %d trash comments deleted, %d expired transients deleted.',
$optimized,
$deleted_revisions ? $deleted_revisions : 0,
$deleted_drafts ? $deleted_drafts : 0,
$deleted_trash ? $deleted_trash : 0,
$deleted_spam ? $deleted_spam : 0,
$deleted_trash_comments ? $deleted_trash_comments : 0,
$deleted_transients ? $deleted_transients : 0
)
));
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* AJAX handler for plugin-related functionality.
*
* @package SEO_Pro_Stack
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
}
/**
* AJAX handler for plugins.
*/
class SEOProStack_AJAX_Plugins {
/**
* Get list of installed plugins.
*/
public function get_plugins() {
// Check nonce
if (!check_ajax_referer('seoprostack-nonce', 'nonce', false)) {
wp_send_json_error('Invalid security token sent.');
return;
}
// Check permissions
if (!current_user_can('manage_options')) {
wp_send_json_error('You do not have permission to view plugins.');
return;
}
$installed_plugins = get_plugins();
$active_plugins = get_option('active_plugins');
$plugin_list = array();
// Create the plugins array
foreach ($installed_plugins as $path => $plugin) {
// Skip the SEO Pro Stack plugin
if (strpos($path, 'wp-seoprostack-plugin') !== false) {
continue;
}
$is_active = in_array($path, $active_plugins);
$plugin_slug = explode('/', $path)[0];
$plugin_list[] = array(
'name' => $plugin['Name'],
'slug' => $plugin_slug,
'version' => $plugin['Version'],
'active' => $is_active,
'path' => $path
);
}
// Sort plugins alphabetically
usort($plugin_list, function ($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
wp_send_json_success($plugin_list);
}
}

View File

@ -0,0 +1,194 @@
<?php
/**
* The Pro Plugins AJAX handler.
*
* @package SEO_Pro_Stack
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
}
/**
* The Pro Plugins AJAX handler.
*/
class SEOProStack_AJAX_Pro_Plugins {
/**
* Initialize the AJAX handlers.
*/
public function init() {
add_action('wp_ajax_seoprostack_get_pro_plugins', array($this, 'get_pro_plugins'));
add_action('wp_ajax_seoprostack_activate_plugin', array($this, 'activate_plugin'));
}
/**
* Get the list of pro plugins.
*/
public function get_pro_plugins() {
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
}
// Get category filter
$category = isset($_POST['category']) ? sanitize_text_field($_POST['category']) : 'all';
// Plugin data
$plugins = $this->get_plugin_data($category);
// Send response
wp_send_json_success(array('plugins' => $plugins));
}
/**
* Activate a plugin.
*/
public function activate_plugin() {
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
}
// Check capabilities
if (!current_user_can('activate_plugins')) {
wp_send_json_error(array('message' => 'You do not have permission to activate plugins'));
}
// Get plugin path
if (!isset($_POST['plugin'])) {
wp_send_json_error(array('message' => 'No plugin specified'));
}
$plugin = sanitize_text_field($_POST['plugin']);
// Activate the plugin
$result = activate_plugin($plugin);
if (is_wp_error($result)) {
wp_send_json_error(array('message' => $result->get_error_message()));
} else {
wp_send_json_success(array('message' => 'Plugin activated successfully'));
}
}
/**
* Get the plugin data based on category.
*
* @param string $category The plugin category.
* @return array The plugin data.
*/
private function get_plugin_data($category) {
$plugins = array(
array(
'name' => 'Rank Math SEO',
'version' => '1.0.123',
'description' => 'The most advanced SEO plugin for WordPress that helps you optimize your website for search engines.',
'url' => 'https://rankmath.com/',
'status' => 'not-installed',
'active' => false,
'path' => 'rank-math-seo/rank-math.php',
'category' => 'seo'
),
array(
'name' => 'WP Rocket',
'version' => '3.14.4',
'description' => 'The best WordPress caching plugin to speed up your website in a few clicks.',
'url' => 'https://wp-rocket.me/',
'status' => 'not-installed',
'active' => false,
'path' => 'wp-rocket/wp-rocket.php',
'category' => 'performance'
),
array(
'name' => 'MonsterInsights',
'version' => '8.14.0',
'description' => 'The best Google Analytics plugin for WordPress that connects your website with Google Analytics.',
'url' => 'https://www.monsterinsights.com/',
'status' => 'not-installed',
'active' => false,
'path' => 'google-analytics-for-wordpress/googleanalytics.php',
'category' => 'analytics'
),
array(
'name' => 'Yoast SEO',
'version' => '21.2',
'description' => 'The first true all-in-one SEO solution for WordPress, including on-page content analysis, XML sitemaps and much more.',
'url' => 'https://yoast.com/wordpress/plugins/seo/',
'status' => 'not-installed',
'active' => false,
'path' => 'wordpress-seo/wp-seo.php',
'category' => 'seo'
),
array(
'name' => 'WP Cloudflare Super Page Cache',
'version' => '4.7.0',
'description' => 'Speed up your website by implementing full page caching using Cloudflare.',
'url' => 'https://wordpress.org/plugins/wp-cloudflare-page-cache/',
'status' => 'not-installed',
'active' => false,
'path' => 'wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php',
'category' => 'performance'
),
array(
'name' => 'ExactMetrics',
'version' => '7.14.1',
'description' => 'Google Analytics Dashboard for WordPress. See how visitors find and use your website.',
'url' => 'https://www.exactmetrics.com/',
'status' => 'not-installed',
'active' => false,
'path' => 'google-analytics-dashboard-for-wp/gadwp.php',
'category' => 'analytics'
),
array(
'name' => 'SEOPress',
'version' => '7.2.2',
'description' => 'Boost your SEO with SEOPress, a simple, fast and powerful WordPress SEO plugin.',
'url' => 'https://www.seopress.org/',
'status' => 'not-installed',
'active' => false,
'path' => 'wp-seopress/seopress.php',
'category' => 'seo'
),
array(
'name' => 'WP-Optimize',
'version' => '3.2.19',
'description' => 'A comprehensive plugin with database clean-up, image compression and page caching features.',
'url' => 'https://getwpo.com/',
'status' => 'not-installed',
'active' => false,
'path' => 'wp-optimize/wp-optimize.php',
'category' => 'performance'
),
array(
'name' => 'Fathom Analytics',
'version' => '3.2.1',
'description' => 'Simple, privacy-focused website analytics that doesn\'t compromise visitor privacy.',
'url' => 'https://usefathom.com/',
'status' => 'not-installed',
'active' => false,
'path' => 'fathom-analytics-wordpress-plugin/fathom-analytics.php',
'category' => 'analytics'
)
);
// Update plugin status (check if installed and active)
foreach ($plugins as $key => $plugin) {
if (file_exists(WP_PLUGIN_DIR . '/' . $plugin['path'])) {
$plugins[$key]['status'] = 'installed';
$plugins[$key]['active'] = is_plugin_active($plugin['path']);
}
}
// Filter by category if needed
if ($category !== 'all') {
$plugins = array_filter($plugins, function($plugin) use ($category) {
return $plugin['category'] === $category;
});
}
return array_values($plugins);
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* AJAX handler for settings functionality.
*
* @package SEO_Pro_Stack
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
}
/**
* AJAX handler for settings.
*/
class SEOProStack_AJAX_Settings {
/**
* Initialize the class
*/
public function __construct() {
add_action('wp_ajax_seoprostack_update_option', array($this, 'update_option'));
add_action('wp_ajax_seoprostack_get_options', array($this, 'get_options'));
}
/**
* Update a plugin option via AJAX.
*/
public function update_option() {
// Check nonce
if (!check_ajax_referer('seoprostack-nonce', 'nonce', false)) {
wp_send_json_error(array(
'message' => 'Invalid security token sent.'
));
return;
}
// Check permissions
if (!current_user_can('manage_options')) {
wp_send_json_error(array(
'message' => 'You do not have permission to update settings.'
));
return;
}
// Get option data
$option_group = isset($_POST['option_group']) ? sanitize_text_field($_POST['option_group']) : '';
$option_name = isset($_POST['option_name']) ? sanitize_text_field($_POST['option_name']) : '';
$option_value = isset($_POST['option_value']) ? sanitize_text_field($_POST['option_value']) : '';
if (empty($option_group) || empty($option_name)) {
wp_send_json_error(array(
'message' => 'Missing required parameters.'
));
return;
}
// Get current option values
$options = get_option($option_group, array());
// Update value
$options[$option_name] = $option_value;
// Save updated options
$result = update_option($option_group, $options);
if ($result) {
wp_send_json_success(array(
'message' => 'Option updated successfully',
'option_group' => $option_group,
'option_name' => $option_name,
'option_value' => $option_value
));
} else {
wp_send_json_error(array(
'message' => 'Failed to update option or no changes were made.'
));
}
}
/**
* Get plugin options via AJAX.
*/
public function get_options() {
// Check nonce
if (!check_ajax_referer('seoprostack-nonce', 'nonce', false)) {
wp_send_json_error(array(
'message' => 'Invalid security token sent.'
));
return;
}
// Check permissions
if (!current_user_can('manage_options')) {
wp_send_json_error(array(
'message' => 'You do not have permission to retrieve settings.'
));
return;
}
// Get option group
$option_group = isset($_POST['option_group']) ? sanitize_text_field($_POST['option_group']) : '';
if (empty($option_group)) {
wp_send_json_error(array(
'message' => 'Missing required parameters.'
));
return;
}
// Get options
$options = get_option($option_group, array());
wp_send_json_success(array(
'options' => $options
));
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* AJAX handler for theme-related functionality.
*
* @package SEO_Pro_Stack
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
}
/**
* AJAX handler for themes.
*/
class SEOProStack_AJAX_Themes {
/**
* Get list of available themes.
*/
public function get_themes() {
// Check nonce
if (!check_ajax_referer('seoprostack-nonce', 'nonce', false)) {
wp_send_json_error('Invalid security token sent.');
return;
}
// Check permissions
if (!current_user_can('manage_options')) {
wp_send_json_error('You do not have permission to view themes.');
return;
}
$themes = wp_get_themes();
$current_theme = wp_get_theme();
$theme_list = array();
foreach ($themes as $theme_slug => $theme_obj) {
$theme_list[] = array(
'name' => $theme_obj->get('Name'),
'version' => $theme_obj->get('Version'),
'description' => $theme_obj->get('Description'),
'author' => $theme_obj->get('Author'),
'slug' => $theme_slug,
'active' => ($current_theme->get_stylesheet() === $theme_slug),
'screenshot' => $theme_obj->get_screenshot(),
);
}
// Sort themes - active first, then alphabetically
usort($theme_list, function ($a, $b) {
if ($a['active'] && !$b['active']) return -1;
if (!$a['active'] && $b['active']) return 1;
return strcasecmp($a['name'], $b['name']);
});
wp_send_json_success($theme_list);
}
/**
* Activate a theme.
*/
public function activate_theme() {
// Check nonce
if (!check_ajax_referer('seoprostack-nonce', 'nonce', false)) {
wp_send_json_error('Invalid security token sent.');
return;
}
// Check permissions
if (!current_user_can('switch_themes')) {
wp_send_json_error('You do not have permission to switch themes.');
return;
}
$theme_slug = sanitize_text_field($_POST['theme']);
// Check if theme exists
$themes = wp_get_themes();
if (!isset($themes[$theme_slug])) {
wp_send_json_error('Theme does not exist.');
return;
}
// Activate theme
switch_theme($theme_slug);
wp_send_json_success(array(
'message' => sprintf('Theme "%s" has been activated.', $themes[$theme_slug]->get('Name')),
));
}
}

View File

@ -0,0 +1,77 @@
<?php
/**
* The Tools AJAX handler.
*
* @package SEO_Pro_Stack
* @subpackage SEO_Pro_Stack/Admin/Settings/AJAX
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
exit;
}
/**
* The Tools AJAX handler.
*/
class SEOProStack_AJAX_Tools {
/**
* Initialize the AJAX handlers.
*/
public function init() {
add_action('wp_ajax_seoprostack_generate_robots', array($this, 'generate_robots'));
}
/**
* Generate robots.txt file content.
*/
public function generate_robots() {
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'seoprostack_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
}
// Check capabilities
if (!current_user_can('manage_options')) {
wp_send_json_error(array('message' => 'You do not have permission to generate robots.txt'));
}
// Generate robots.txt content
$site_url = get_home_url();
$parsed_url = parse_url($site_url);
$host = $parsed_url['host'];
$content = "# SEO Pro Stack generated robots.txt\n";
$content .= "# Generated on: " . date('Y-m-d H:i:s') . "\n\n";
$content .= "User-agent: *\n";
// Disallow WordPress admin
$content .= "Disallow: /wp-admin/\n";
// Allow assets and ajax
$content .= "Allow: /wp-admin/admin-ajax.php\n";
$content .= "Allow: /wp-includes/*.js\n";
$content .= "Allow: /wp-includes/*.css\n";
$content .= "Allow: /wp-content/uploads/\n";
// Disallow common WordPress files and directories
$content .= "Disallow: /wp-includes/\n";
$content .= "Disallow: /readme.html\n";
$content .= "Disallow: /license.txt\n";
$content .= "Disallow: /xmlrpc.php\n";
$content .= "Disallow: /wp-json/\n";
// Add sitemap if Yoast SEO or other SEO plugin is active
if (function_exists('wpseo_init') || defined('AIOSEO_VERSION') || defined('RANK_MATH_VERSION')) {
$content .= "\n# XML Sitemap\n";
$content .= "Sitemap: " . trailingslashit($site_url) . "sitemap_index.xml\n";
}
// Send response
wp_send_json_success(array(
'message' => 'Robots.txt content generated successfully.',
'content' => $content
));
}
}