'Invalid security token']); return; } try { // Get the homepage URL $home_url = home_url(); // Make a request to the frontend $response = wp_remote_get($home_url, [ 'timeout' => 30, 'sslverify' => !maxi_is_localhost(), 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' ]); if (is_wp_error($response)) { wp_send_json_error(['message' => 'Failed to fetch frontend']); return; } $html = wp_remote_retrieve_body($response); // Parse HTML to find assets $css_files = []; $js_files = []; // Use DOMDocument to parse HTML $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); libxml_clear_errors(); // Get all CSS files $links = $dom->getElementsByTagName('link'); foreach ($links as $link) { if ($link->getAttribute('rel') === 'stylesheet') { $css_files[] = $link->getAttribute('href'); } } // Get all JS files $scripts = $dom->getElementsByTagName('script'); foreach ($scripts as $script) { $src = $script->getAttribute('src'); if ($src) { $js_files[] = $src; } } // Clean up URLs $css_files = array_values(array_filter(array_unique($css_files))); $js_files = array_values(array_filter(array_unique($js_files))); wp_send_json_success([ 'css' => $css_files ?: [__('No CSS files found', 'maxi-blocks')], 'js' => $js_files ?: [__('No JavaScript files found', 'maxi-blocks')] ]); } catch (Exception $e) { wp_send_json_error(['message' => 'Internal error']); } }