"); // Show loading overlay $container.css("position", "relative").append($loadingOverlay); // AJAX request to get themes $.ajax({ url: ajaxurl, type: "POST", data: { action: "wp_allstars_get_themes", _wpnonce: wpAllstars.nonce }, success: function(response) { $loadingOverlay.remove(); if (response.success) { $container.html(response.data); // Initialize theme action buttons if (typeof initThemeHandlers === "function") { initThemeHandlers(); } } else { $container.html("

" + response.data + "

"); } }, error: function(xhr, status, error) { $loadingOverlay.remove(); $container.html("

Failed to load themes. Please try again. Error: " + error + "

"); console.error("AJAX Error:", xhr.responseText); } }); } // Initialize theme handlers window.initThemeHandlers = function() { // Activate theme $(".activate-now").click(function(e) { e.preventDefault(); var $button = $(this); var slug = $button.data("slug"); var name = $button.data("name"); var nonce = $button.data("nonce"); $button.text("Activating...").addClass("updating-message").attr("disabled", true); $.ajax({ url: ajaxurl, type: "POST", data: { action: "wp_allstars_activate_theme", theme: slug, _wpnonce: nonce }, success: function(response) { if (response.success) { $button.removeClass("updating-message").addClass("updated-message").text("Activated"); setTimeout(function() { window.location.reload(); }, 1000); } else { $button.removeClass("updating-message").text("Error"); alert("Error: " + response.data); } }, error: function(xhr, status, error) { $button.removeClass("updating-message").text("Error"); alert("Error: " + error); } }); }); }; }); '; } /** * Display the theme tab content */ public static function display_tab_content() { ?>

Loading theme data...

'kadence', 'fields' => array( 'sections' => false, 'description' => true, 'rating' => true, 'ratings' => false, 'downloaded' => true, 'download_link' => true, 'last_updated' => true, 'homepage' => true, 'tags' => false, 'screenshot_url' => true, 'version' => true, 'requires' => true, 'requires_php' => true, 'active_installs' => true, 'author' => true, 'preview_url' => true, ) )); // Cache the result if successful if (!is_wp_error($theme_data)) { self::set_cached_theme($theme_data); } } else { error_log('WP ALLSTARS: Using cached theme data'); } if (is_wp_error($theme_data)) { error_log('WP ALLSTARS Theme API Error: ' . $theme_data->get_error_message()); wp_send_json_error('Theme API Error: ' . $theme_data->get_error_message()); return; } error_log('WP ALLSTARS: Successfully fetched theme data'); // Format author data $author = ''; if (is_string($theme_data->author)) { $author = $theme_data->author; } elseif (is_array($theme_data->author)) { $author = isset($theme_data->author['display_name']) ? $theme_data->author['display_name'] : ''; } error_log('WP ALLSTARS: Theme data retrieved, generating HTML'); // Generate custom HTML for the theme using our template partial ob_start(); include(plugin_dir_path(dirname(__FILE__)) . 'partials/theme-panel.php'); $html = ob_get_clean(); if (empty($html)) { error_log('WP ALLSTARS: Empty HTML generated'); wp_send_json_error('Failed to generate theme display'); return; } error_log('WP ALLSTARS: Successfully generated theme display, HTML length: ' . strlen($html)); wp_send_json_success($html); exit; // Ensure we exit after sending the JSON response } catch (Exception $e) { error_log('WP ALLSTARS Theme loading exception: ' . $e->getMessage()); error_log('WP ALLSTARS Theme loading exception trace: ' . $e->getTraceAsString()); wp_send_json_error('Theme loading error: ' . $e->getMessage()); } catch (Error $e) { error_log('WP ALLSTARS Theme loading error: ' . $e->getMessage()); error_log('WP ALLSTARS Theme loading error trace: ' . $e->getTraceAsString()); wp_send_json_error('Theme loading error: ' . $e->getMessage()); } } /** * AJAX handler for theme activation */ public static function activate_theme() { // Debug information error_log('Theme activation AJAX request received: ' . print_r($_POST, true)); // Check nonce with the correct action name if (!check_ajax_referer('wp-allstars-nonce', '_wpnonce', false)) { error_log('Theme activation failed: Invalid nonce'); wp_send_json_error('Invalid security token sent.'); return; } if (!current_user_can('switch_themes')) { error_log('Theme activation failed: Permission denied'); wp_send_json_error('Permission denied'); return; } $theme = isset($_POST['theme']) ? sanitize_text_field($_POST['theme']) : ''; if (empty($theme)) { error_log('Theme activation failed: No theme specified'); wp_send_json_error('No theme specified'); return; } // Get the theme object $theme_obj = wp_get_theme($theme); if (!$theme_obj->exists()) { error_log('Theme activation failed: Theme does not exist - ' . $theme); wp_send_json_error('Theme does not exist'); return; } // Set the new theme switch_theme($theme); error_log('Theme activation success - ' . $theme); wp_send_json_success(); } }