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>
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Support;
|
|
|
|
use Closure;
|
|
use LIT\MCP\Integrations\Divi\Design\CustomCssStore;
|
|
use RuntimeException;
|
|
|
|
/** The custom CSS of one theme in memory; $store can alter what is kept (like kses) or refuse a write. */
|
|
final class FakeCustomCssStore extends CustomCssStore
|
|
{
|
|
/** @var list<string> Every text written, in order. */
|
|
public array $writes = [];
|
|
|
|
/** @param (Closure(string): string)|null $keep What the store really keeps of a written text. */
|
|
public function __construct(
|
|
public string $css = '.a { color: red; }',
|
|
public string $stylesheet = 'Divi',
|
|
private ?Closure $keep = null,
|
|
private bool $refuse = false
|
|
) {
|
|
}
|
|
|
|
public function read(): array
|
|
{
|
|
return ['stylesheet' => $this->stylesheet, 'css' => $this->css];
|
|
}
|
|
|
|
public function write(string $css): void
|
|
{
|
|
if ($this->refuse) {
|
|
throw new RuntimeException('refused');
|
|
}
|
|
$this->writes[] = $css;
|
|
$this->css = $this->keep === null ? $css : ($this->keep)($css);
|
|
}
|
|
}
|