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,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Design;
|
||||
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Restores a snapshot of the custom CSS: the whole text of that moment replaces the current one. A snapshot belongs to
|
||||
* one theme – with another theme active it is refused, since it would land in the other theme's CSS. The text is not
|
||||
* run through CustomCssGuard: it is what the site had before (or what an earlier, checked change wrote), and a way
|
||||
* back must not be blocked by what was there already. Rights and Divi features are those of the update.
|
||||
*/
|
||||
final class CustomCssRestorePlanner implements RestorePlanner
|
||||
{
|
||||
public function __construct(private CustomCssStore $store, private ThemeOptionsAdapter $options)
|
||||
{
|
||||
}
|
||||
|
||||
public function area(): string
|
||||
{
|
||||
return 'custom_css';
|
||||
}
|
||||
|
||||
public function designArea(): DesignArea
|
||||
{
|
||||
return new CustomCssArea($this->store);
|
||||
}
|
||||
|
||||
public function rights(): ?WP_Error
|
||||
{
|
||||
return DesignRights::customCss($this->options);
|
||||
}
|
||||
|
||||
public function features(): array
|
||||
{
|
||||
return [DiviFeature::ThemeOptionRead, DiviFeature::ThemeOptionWrite];
|
||||
}
|
||||
|
||||
public function plan(array $current, array $snapshot, string $snapshotId): DesignPlan|WP_Error
|
||||
{
|
||||
$stylesheet = (string) ($current['stylesheet'] ?? '');
|
||||
if ((string) ($snapshot['stylesheet'] ?? '') !== $stylesheet) {
|
||||
return Errors::invalidInput(
|
||||
sprintf(
|
||||
'Der Snapshot gehört zum Theme „%s“, aktiv ist „%s“; nichts wurde gespeichert.',
|
||||
(string) ($snapshot['stylesheet'] ?? '?'),
|
||||
$stylesheet
|
||||
),
|
||||
['snapshot' => 'Das passende Theme aktivieren oder einen Snapshot dieses Themes wählen.']
|
||||
);
|
||||
}
|
||||
|
||||
$before = (string) ($current['css'] ?? '');
|
||||
$after = (string) ($snapshot['css'] ?? '');
|
||||
|
||||
return new DesignPlan(
|
||||
['stylesheet' => $stylesheet, 'css' => $after],
|
||||
CustomCssDiff::between($before, $after),
|
||||
sprintf('Snapshot %s wiederherstellen – %s', $snapshotId, CustomCssDiff::summary($before, $after)),
|
||||
null,
|
||||
$before === $after ? [] : [CustomCssArea::SITE_WIDE],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user