From 0bb0e5640434d66029a7f27bcaa5d4ec0bc313a8 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:50:35 +0000 Subject: [PATCH] Batch48: Bricks tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch48.php | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 includes/Extensions/Batch48.php diff --git a/includes/Extensions/Batch48.php b/includes/Extensions/Batch48.php new file mode 100644 index 0000000..12b6621 --- /dev/null +++ b/includes/Extensions/Batch48.php @@ -0,0 +1,48 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch48::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('bricks_detect', 'Report whether Bricks is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('bricks_list_templates', 'List Bricks templates (id, title).', + ['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listTemplates')); + $registry->register($def('bricks_get_page_elements', 'Count the Bricks elements stored on a post (meta _bricks_page_content_2).', + ['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'getPageElements')); + } + + public static function detect(array $args): array { + return ['active' => defined('BRICKS_VERSION'), 'version' => defined('BRICKS_VERSION') ? BRICKS_VERSION : null]; + } + + public static function listTemplates(array $args): array { + $posts = get_posts(['post_type' => 'bricks_template', '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), 'templates' => $out]; + } + + public static function getPageElements(array $args): array { + $id = (int) ($args['post_id'] ?? 0); + if (!get_post($id)) throw new \RuntimeException("Post not found: {$id}"); + $data = get_post_meta($id, '_bricks_page_content_2', true); + return ['post_id' => $id, 'element_count' => is_array($data) ? count($data) : 0]; + } +}