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,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')),
));
}
}