Batch47: Divi tools (guarded, net-new)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
2026-10-16 04:50:26 +00:00
parent cf62f10344
commit 205a94d46c
+47
View File
@@ -0,0 +1,47 @@
<?php
/**
* Batch 47 — Divi tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
* Inert unless Divi (ET_CORE_VERSION) is active. Layouts are the 'et_pb_layout' CPT.
*/
namespace AskTamMCP\Extensions;
defined('ABSPATH') || exit;
class Batch47 {
public static function register($registry): void {
if (!defined('ET_CORE_VERSION')) return;
$def = function (string $name, string $desc, array $props, array $required, string $scope, string $method) {
$schema = ['type' => 'object', 'properties' => $props ?: new \stdClass()];
if ($required) $schema['required'] = $required;
return ['name' => $name, 'description' => $desc, 'scope' => $scope,
'handler' => 'AskTamMCP\\Extensions\\Batch47::' . $method, 'inputSchema' => $schema];
};
$registry->register($def('divi_detect', 'Report whether Divi (ET core) is active and its version.', [], [], 'read', 'detect'));
$registry->register($def('divi_list_layouts', 'List saved Divi layouts (id, title) from the Divi Library.',
['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listLayouts'));
$registry->register($def('divi_is_built', 'Report whether the Divi Builder is enabled on a post.',
['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'isBuilt'));
}
public static function detect(array $args): array {
return ['active' => defined('ET_CORE_VERSION'), 'version' => defined('ET_CORE_VERSION') ? ET_CORE_VERSION : null];
}
public static function listLayouts(array $args): array {
$posts = get_posts(['post_type' => 'et_pb_layout', 'post_status' => ['publish', 'draft'],
'numberposts' => (int) ($args['per_page'] ?? 100), 'orderby' => 'title', 'order' => 'ASC']);
$out = [];
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title];
return ['count' => count($out), 'layouts' => $out];
}
public static function isBuilt(array $args): array {
$id = (int) ($args['post_id'] ?? 0);
if (!get_post($id)) throw new \RuntimeException("Post not found: {$id}");
return ['post_id' => $id, 'divi_builder' => get_post_meta($id, '_et_pb_use_builder', true) === 'on'];
}
}