Files
WP-LIT-MCP/src/Integrations/Divi/DiviCompatibility.php
T
janniclas.loosenandClaude Opus 5.5 5290a9d81d 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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
2026-09-27 23:07:57 +02:00

104 lines
4.2 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\Divi;
use LIT\MCP\Integrations\Divi\BlockTree\GlobalInstance;
use LIT\MCP\Integrations\Divi\Library\DiviLibraryStore;
use LIT\MCP\Integrations\Divi\Pages\DynamicContentMap;
use LIT\MCP\Integrations\Divi\Schema\DiviModules;
use LIT\MCP\Integrations\Divi\ThemeBuilder\DiviThemeBuilder;
use Throwable;
defined('ABSPATH') || exit;
/**
* Live check of the Divi internals LIT MCP relies on (decisions note §5, E15): classes,
* functions, the library post type and taxonomies, the instance block type. lit-site-status shows
* the failed checks, so a Divi update that moves one of them is visible before a tool reports
* "unsupported".
*/
final class DiviCompatibility
{
/** @param array<string, callable(): bool>|null $checks Label => check; null = defaults(). */
public function __construct(private ?array $checks = null)
{
}
/** @return list<string> Labels of the checks that failed or threw. */
public function problems(): array
{
$problems = [];
foreach ($this->checks ?? self::defaults() as $label => $check) {
try {
$ok = (bool) $check();
} catch (Throwable) {
$ok = false;
}
if (! $ok) {
$problems[] = (string) $label;
}
}
return $problems;
}
/** @return array<string, callable(): bool> */
public static function defaults(): array
{
return [
'ModuleRegistration (Modul-Katalog)' => static fn (): bool => DiviModules::isAvailable(),
'DynamicContentOptions (Dynamic Content)' =>
static fn (): bool => class_exists(DynamicContentMap::REGISTRY),
'et_pb_is_allowed (Divi-Rollen)' => static fn (): bool => function_exists('et_pb_is_allowed'),
'Post-Typ et_pb_layout (Bibliothek)' =>
static fn (): bool => post_type_exists(DiviLibraryStore::POST_TYPE),
'Taxonomien scope, layout_type, module_width (Bibliothek)' =>
static fn (): bool => (new DiviLibraryStore())->missingTaxonomies() === [],
'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'),
'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(
DiviThemeBuilder::postTypes(),
static fn (string $type): bool => ! post_type_exists($type)
) === [],
];
}
/**
* Whether Divi still has the block type of global instances (GlobalInstance::BLOCK): registered
* with WordPress, or in Divi's core module metadata (Divi renders instances itself, BlockParser,
* and does not always register the type with WordPress).
*/
private static function knowsGlobalLayout(): bool
{
if (
class_exists('WP_Block_Type_Registry')
&& \WP_Block_Type_Registry::get_instance()->is_registered(GlobalInstance::BLOCK)
) {
return true;
}
$registration = 'ET\Builder\Packages\ModuleLibrary\ModuleRegistration';
if (! method_exists($registration, 'get_all_core_modules_metadata')) {
return false;
}
foreach ((array) $registration::get_all_core_modules_metadata() as $module) {
if (is_array($module) && ($module['name'] ?? null) === GlobalInstance::BLOCK) {
return true;
}
}
return false;
}
}