feat: ThemeOptionsRestorePlanner – Snapshot theme_options ersetzt die Whitelist, nennt zurückgesetzte Optionen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
449ec5c33f
commit
2e3b740260
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Design;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Restores a snapshot of the theme options (rulings W6, W11): the snapshot replaces the whole whitelist – keys it
|
||||
* lacks are deleted and return to Divi's default (ThemeOptionDiff "reset" rows, named in a warning). The rights and
|
||||
* Divi features are those of lit/divi-theme-options-update.
|
||||
*/
|
||||
final class ThemeOptionsRestorePlanner implements RestorePlanner
|
||||
{
|
||||
private const RESET = 'Theme-Optionen, die im Snapshot nicht gesetzt sind, kehren zum Divi-Standard zurück (%s).';
|
||||
|
||||
public function __construct(private DesignSystemWriter $writer, private ThemeOptionsAdapter $options)
|
||||
{
|
||||
}
|
||||
|
||||
public function area(): string
|
||||
{
|
||||
return 'theme_options';
|
||||
}
|
||||
|
||||
public function designArea(): DesignArea
|
||||
{
|
||||
return new ThemeOptionsArea($this->options);
|
||||
}
|
||||
|
||||
public function rights(): ?WP_Error
|
||||
{
|
||||
return DesignRights::themeOptions($this->writer, $this->options);
|
||||
}
|
||||
|
||||
/** Like lit/divi-theme-options-update: reads et_divi (ThemeOptionRead), writes it (ThemeOptionWrite). */
|
||||
public function features(): array
|
||||
{
|
||||
return [DiviFeature::ThemeOptionRead, DiviFeature::ThemeOptionWrite];
|
||||
}
|
||||
|
||||
public function plan(array $current, array $snapshot, string $snapshotId): DesignPlan|WP_Error
|
||||
{
|
||||
// A stored false is "not set" (W3), as in lit/divi-theme-options-update: no noise rows for it.
|
||||
$after = ThemeOptionBook::fromDivi($snapshot)->withoutFalse();
|
||||
$diff = ThemeOptionDiff::between(ThemeOptionBook::fromDivi($current)->withoutFalse(), $after);
|
||||
$reset = [];
|
||||
foreach ($diff as $row) {
|
||||
if ($row['action'] === 'reset') {
|
||||
$reset[] = '„' . $row['label'] . '“';
|
||||
}
|
||||
}
|
||||
$warnings = $diff === [] ? [] : [ThemeOptionsArea::SITE_WIDE];
|
||||
if ($reset !== []) {
|
||||
$warnings[] = sprintf(self::RESET, implode(', ', $reset));
|
||||
}
|
||||
|
||||
return new DesignPlan(
|
||||
$after->data(),
|
||||
$diff,
|
||||
sprintf('Snapshot %s wiederherstellen – %s', $snapshotId, ThemeOptionDiff::summary($diff)),
|
||||
null,
|
||||
$warnings,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user