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>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
96fa58188b
commit
ac333a164c
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Design;
|
||||
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* The area "custom_css": the custom CSS of the active theme, inventory {stylesheet, css}. The theme belongs to the
|
||||
* design_rev, so a theme switch between dry run and confirmation counts as a change. A write replaces the whole text;
|
||||
* verify() insists that WordPress stored exactly what was planned (it would strip markup for accounts without
|
||||
* unfiltered_html), so a changed text rolls the change back instead of going live altered.
|
||||
*/
|
||||
final class CustomCssArea implements DesignArea
|
||||
{
|
||||
/** The reach of every change, named in the dry run like the theme options (ruling W7). */
|
||||
public const SITE_WIDE = 'Eigenes CSS wirkt auf die gesamte Website, auch im Divi-Builder.';
|
||||
|
||||
public function __construct(private CustomCssStore $store)
|
||||
{
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'custom_css';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Eigenes CSS';
|
||||
}
|
||||
|
||||
/** It is Divi's own field "Eigenes CSS" (Theme-Anpassung), so it follows the release of the theme options. */
|
||||
public function feature(): DiviFeature
|
||||
{
|
||||
return DiviFeature::ThemeOptionWrite;
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
// read() asks the custom_css post; WordPress keeps its cache in step with every write.
|
||||
}
|
||||
|
||||
public function raw(): array
|
||||
{
|
||||
return $this->store->read();
|
||||
}
|
||||
|
||||
public function rev(array $raw): string
|
||||
{
|
||||
return Rev::of(((string) ($raw['stylesheet'] ?? '')) . "\0" . ((string) ($raw['css'] ?? '')));
|
||||
}
|
||||
|
||||
/** $mayRemove has no effect: the text is replaced as a whole. */
|
||||
public function write(array $raw, bool $mayRemove): array
|
||||
{
|
||||
$this->store->write((string) ($raw['css'] ?? ''));
|
||||
|
||||
return $this->store->read();
|
||||
}
|
||||
|
||||
public function restore(array $raw): array
|
||||
{
|
||||
return $this->write($raw, true);
|
||||
}
|
||||
|
||||
public function verify(array $expected, array $actual): bool
|
||||
{
|
||||
return (string) ($expected['css'] ?? '') === (string) ($actual['css'] ?? '');
|
||||
}
|
||||
|
||||
public function differences(array $expected, array $actual): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user