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