From 5290a9d81d3cd34ded2a01fd602f444d11b90e45 Mon Sep 17 00:00:00 2001 From: Jan-Niclas Loosen Date: Sun, 27 Sep 2026 23:07:57 +0200 Subject: [PATCH] refactor: one site-wide Divi cache clear and one compatibility row (review M-1, M-2) DiviSaver's site-wide scopes and the Theme Builder tools now share DiviThemeBuilder::clearSiteCaches(), which clears the Theme Builder cache even when ET_Core_PageResource is missing. lit-site-status no longer lists et_theme_builder_clear_wp_cache twice: the Theme Builder functions row covers it, and the post-type row uses DiviThemeBuilder::postTypes(). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7 --- src/Integrations/Divi/DiviCompatibility.php | 8 ++------ src/Integrations/Divi/Pages/DiviSaver.php | 11 ++++------- .../Divi/ThemeBuilder/DiviThemeBuilder.php | 15 ++++++++++++--- .../Integrations/Divi/DiviCompatibilityTest.php | 4 +++- .../Divi/ThemeBuilder/DiviThemeBuilderTest.php | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/Integrations/Divi/DiviCompatibility.php b/src/Integrations/Divi/DiviCompatibility.php index 0910d6e..7e57b19 100644 --- a/src/Integrations/Divi/DiviCompatibility.php +++ b/src/Integrations/Divi/DiviCompatibility.php @@ -59,19 +59,15 @@ final class DiviCompatibility 'GlobalLayout::is_global_layout_template (globale Module)' => static fn (): bool => method_exists(DiviLibraryStore::GLOBAL_LAYOUT, 'is_global_layout_template'), 'ET_Core_PageResource (CSS-Cache)' => static fn (): bool => class_exists('ET_Core_PageResource'), - 'et_theme_builder_clear_wp_cache (Theme-Builder-Cache)' => - static fn (): bool => function_exists('et_theme_builder_clear_wp_cache'), 'Block-Typ divi/global-layout (Instanzen globaler Module)' => static fn (): bool => self::knowsGlobalLayout(), 'Taxonomien layout_category, layout_tag (Bibliothek)' => static fn (): bool => taxonomy_exists('layout_category') && taxonomy_exists('layout_tag'), + // Includes et_theme_builder_clear_wp_cache (Theme Builder cache of every site-wide clear, review M-2). 'Theme Builder: Funktionen et_theme_builder_* und et_()' => static fn (): bool => (new DiviThemeBuilder())->missing() === [], 'Theme Builder: Post-Typen et_template und Layouts' => static fn (): bool => array_filter( - array_merge( - [DiviThemeBuilder::THEME_BUILDER, DiviThemeBuilder::TEMPLATE], - array_values(DiviThemeBuilder::LAYOUT_TYPES) - ), + DiviThemeBuilder::postTypes(), static fn (string $type): bool => ! post_type_exists($type) ) === [], ]; diff --git a/src/Integrations/Divi/Pages/DiviSaver.php b/src/Integrations/Divi/Pages/DiviSaver.php index 1707f5e..35eb777 100644 --- a/src/Integrations/Divi/Pages/DiviSaver.php +++ b/src/Integrations/Divi/Pages/DiviSaver.php @@ -8,6 +8,7 @@ use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\FollowUp; use LIT\MCP\Abilities\Rollback; use LIT\MCP\Abilities\WriteFailed; +use LIT\MCP\Integrations\Divi\ThemeBuilder\DiviThemeBuilder; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\RevisionPoint; use RuntimeException; @@ -106,16 +107,12 @@ class DiviSaver } FollowUp::run( static function () use ($postId, $scope): void { - if (! class_exists('ET_Core_PageResource')) { - return; + if (class_exists('ET_Core_PageResource')) { + \ET_Core_PageResource::remove_static_resources($postId, 'all', true); } - \ET_Core_PageResource::remove_static_resources($postId, 'all', true); // A global library entry is part of every page that shows it (spec §5.6 step 5). if ($scope->clearsSiteCss()) { - \ET_Core_PageResource::remove_static_resources('all', 'all', true); - if (function_exists('et_theme_builder_clear_wp_cache')) { - et_theme_builder_clear_wp_cache('all'); - } + DiviThemeBuilder::clearSiteCaches(); } }, 'divi static css', diff --git a/src/Integrations/Divi/ThemeBuilder/DiviThemeBuilder.php b/src/Integrations/Divi/ThemeBuilder/DiviThemeBuilder.php index aa9eede..11e7f31 100644 --- a/src/Integrations/Divi/ThemeBuilder/DiviThemeBuilder.php +++ b/src/Integrations/Divi/ThemeBuilder/DiviThemeBuilder.php @@ -341,12 +341,21 @@ class DiviThemeBuilder /** Divi's Theme Builder cache and every static CSS file (spec §5.6 step 5; api.php:249-254). */ public function clearCaches(): void { - if (function_exists('et_theme_builder_clear_wp_cache')) { - et_theme_builder_clear_wp_cache('all'); - } + self::clearSiteCaches(); + } + + /** + * The site-wide clear shared by the Theme Builder tools and DiviSaver's site-wide scopes (review M-1): every + * static CSS file and Divi's Theme Builder cache, each when Divi provides it. + */ + public static function clearSiteCaches(): void + { if (class_exists('ET_Core_PageResource')) { \ET_Core_PageResource::remove_static_resources('all', 'all', true); } + if (function_exists('et_theme_builder_clear_wp_cache')) { + et_theme_builder_clear_wp_cache('all'); + } } /** diff --git a/tests/Unit/Integrations/Divi/DiviCompatibilityTest.php b/tests/Unit/Integrations/Divi/DiviCompatibilityTest.php index 6d2183a..85960c8 100644 --- a/tests/Unit/Integrations/Divi/DiviCompatibilityTest.php +++ b/tests/Unit/Integrations/Divi/DiviCompatibilityTest.php @@ -34,7 +34,6 @@ final class DiviCompatibilityTest extends TestCase 'Taxonomien scope, layout_type, module_width (Bibliothek)', 'GlobalLayout::is_global_layout_template (globale Module)', 'ET_Core_PageResource (CSS-Cache)', - 'et_theme_builder_clear_wp_cache (Theme-Builder-Cache)', 'Block-Typ divi/global-layout (Instanzen globaler Module)', 'Taxonomien layout_category, layout_tag (Bibliothek)', 'Theme Builder: Funktionen et_theme_builder_* und et_()', @@ -44,10 +43,13 @@ final class DiviCompatibilityTest extends TestCase ); } + /** Review M-2: et_theme_builder_clear_wp_cache is one of DiviThemeBuilder::FUNCTIONS – reported once. */ public function testChecksTheThemeBuilderInternals(): void { $labels = array_keys(DiviCompatibility::defaults()); + self::assertNotContains('et_theme_builder_clear_wp_cache (Theme-Builder-Cache)', $labels); + self::assertContains('Theme Builder: Funktionen et_theme_builder_* und et_()', $labels); self::assertContains('Theme Builder: Post-Typen et_template und Layouts', $labels); } diff --git a/tests/Unit/Integrations/Divi/ThemeBuilder/DiviThemeBuilderTest.php b/tests/Unit/Integrations/Divi/ThemeBuilder/DiviThemeBuilderTest.php index 6c2048e..1a3bfc6 100644 --- a/tests/Unit/Integrations/Divi/ThemeBuilder/DiviThemeBuilderTest.php +++ b/tests/Unit/Integrations/Divi/ThemeBuilder/DiviThemeBuilderTest.php @@ -35,6 +35,21 @@ final class DiviThemeBuilderTest extends TestCase ); } + /** Review M-1: one site-wide clear – every static CSS file and the Theme Builder cache. */ + public function testClearCachesClearsTheSiteWideCaches(): void + { + \ET_Core_PageResource::$removed = []; + $cleared = []; + Functions\when('et_theme_builder_clear_wp_cache')->alias(static function (string $what) use (&$cleared): void { + $cleared[] = $what; + }); + + (new DiviThemeBuilder())->clearCaches(); + + self::assertSame([['all', 'all', true]], \ET_Core_PageResource::$removed); + self::assertSame(['all'], $cleared); + } + /** Audit L4: a template is listed when any Theme Builder post's _et_template row names it. */ public function testIsListedAnywhereAsksEveryThemeBuilderPost(): void {