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,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Design;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* The site-wide custom CSS of the active theme: WordPress' "Zusätzliches CSS", a custom_css post per theme. Divi 5's
|
||||
* field "Eigenes CSS" writes the same post (themes/Divi/epanel/core_functions.php), so this is the one place. Not
|
||||
* final so the area and the abilities can be tested with a mock.
|
||||
*/
|
||||
class CustomCssStore
|
||||
{
|
||||
/**
|
||||
* @return array{stylesheet: string, css: string} The stored text – not wp_get_custom_css(), which plugins filter.
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
$stylesheet = get_stylesheet();
|
||||
$post = wp_get_custom_css_post($stylesheet);
|
||||
|
||||
return ['stylesheet' => $stylesheet, 'css' => $post === null ? '' : (string) $post->post_content];
|
||||
}
|
||||
|
||||
/** @throws RuntimeException When WordPress refuses to store the CSS. */
|
||||
public function write(string $css): void
|
||||
{
|
||||
$saved = wp_update_custom_css_post($css, ['stylesheet' => get_stylesheet()]);
|
||||
if (is_wp_error($saved)) {
|
||||
throw new RuntimeException($saved->get_error_message());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user