Files
WP-LIT-MCP/src/Integrations/Divi/Design/CustomCssRestorePlanner.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

72 lines
2.4 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 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
);
}
}