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>
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?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());
|
||
}
|
||
}
|
||
}
|