Files
WP-LIT-MCP/src/Integrations/Divi/Design/CustomCssStore.php
T
Jan-Niclas LoosenandClaude Sonnet 5.5 ac333a164c feat(css): globales CSS bearbeiten (lit/divi-custom-css-get und -update)
WordPress „Zusätzliches CSS“ (in Divi „Eigenes CSS“) über die Design-Pipeline: Probelauf mit Zeilen-Diff,
design_rev, Bestätigung, Snapshot, Rollback und Wiederherstellen (Bereich custom_css). Der Guard lehnt </style,
<script, expression(, javascript: und neue @import ab und warnt bei fremden Hosts; nur Neues zählt, Bestehendes
blockiert keine Änderung. Erfordert edit_css und die Divi-Rolle Theme-Anpassung.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 16:36:16 +01:00

38 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\Divi\Design;
use RuntimeException;
defined('ABSPATH') || exit;
/**
* The site-wide custom CSS of the active theme: WordPress' "Zusätzliches CSS", a custom_css post per theme. Divi 5's
* field "Eigenes CSS" writes the same post (themes/Divi/epanel/core_functions.php), so this is the one place. Not
* final so the area and the abilities can be tested with a mock.
*/
class CustomCssStore
{
/**
* @return array{stylesheet: string, css: string} The stored text – not wp_get_custom_css(), which plugins filter.
*/
public function read(): array
{
$stylesheet = get_stylesheet();
$post = wp_get_custom_css_post($stylesheet);
return ['stylesheet' => $stylesheet, 'css' => $post === null ? '' : (string) $post->post_content];
}
/** @throws RuntimeException When WordPress refuses to store the CSS. */
public function write(string $css): void
{
$saved = wp_update_custom_css_post($css, ['stylesheet' => get_stylesheet()]);
if (is_wp_error($saved)) {
throw new RuntimeException($saved->get_error_message());
}
}
}