TB layouts load through ThemeBuilderAccess (P12), live layouts (attached + enabled, Q8) need a dry run and confirm (Q9) and get the shared restore point of VisibleEdits, extracted from GlobalEdits (Q2: backup when revisions are off, P9 refusals, P14 naming). divi/post-content only in body layouts (F22), also for nested stored nodes. SaveScope::ThemeBuilderLayout sets Divi flags and clears site CSS + TB cache. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
58 lines
2.3 KiB
PHP
58 lines
2.3 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Writes tests/Fixtures/divi/metadata-sample.json: Divi's own module metadata (name, title,
|
||
* category, children, attribute settings) and default attributes for the modules the unit
|
||
* tests use, so ModuleCatalog is tested against real Divi data without WordPress.
|
||
* Usage (DDEV, WordPress root): wp eval-file wp-content/plugins/WP-LIT-MCP/tests/Integration/divi-metadata-fixture.php
|
||
* No `declare(strict_types=1);` – wp eval-file runs the file through eval().
|
||
*/
|
||
|
||
defined('WP_CLI') && WP_CLI || exit;
|
||
|
||
use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
|
||
|
||
if (! class_exists(ModuleRegistration::class)) {
|
||
WP_CLI::error('Divi 5 is not active.');
|
||
}
|
||
|
||
$wanted = [
|
||
'section', 'row', 'column', 'text', 'heading', 'button', 'image', 'blurb', 'code', 'accordion',
|
||
'accordion-item', 'fullwidth-header', 'group', 'contact-form', 'contact-field', 'post-content',
|
||
];
|
||
$all = ModuleRegistration::get_all_core_modules_metadata();
|
||
$metadata = [];
|
||
$defaults = [];
|
||
foreach ($wanted as $key) {
|
||
$module = $all[$key] ?? null;
|
||
if (! is_array($module)) {
|
||
WP_CLI::error('Missing module ' . $key);
|
||
}
|
||
|
||
$attributes = [];
|
||
foreach ((array) ($module['attributes'] ?? []) as $attrName => $definition) {
|
||
$attributes[$attrName] = ['settings' => $definition['settings'] ?? []];
|
||
}
|
||
|
||
$metadata[] = array_filter([
|
||
'name' => $module['name'],
|
||
'title' => $module['title'] ?? '',
|
||
'category' => $module['category'] ?? '',
|
||
'childrenName' => $module['childrenName'] ?? null,
|
||
'childModuleName' => $module['childModuleName'] ?? null,
|
||
'appearance' => $module['appearance'] ?? null,
|
||
'attributes' => $attributes,
|
||
], static fn ($value): bool => $value !== null);
|
||
$defaults[$module['name']] = ModuleRegistration::get_default_attrs($module['name'], 'default');
|
||
}
|
||
|
||
$file = dirname(__DIR__) . '/Fixtures/divi/metadata-sample.json';
|
||
$json = wp_json_encode(
|
||
['divi' => ET_BUILDER_PRODUCT_VERSION, 'metadata' => $metadata, 'defaults' => $defaults],
|
||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
|
||
);
|
||
if (! is_string($json) || file_put_contents($file, $json . "\n") === false) {
|
||
WP_CLI::error('Cannot write ' . $file);
|
||
}
|
||
WP_CLI::success(sprintf('metadata-sample.json: %d modules, %d bytes', count($metadata), strlen($json)));
|