From 8b96d106d25a73ba38d95c0741c0b05defbc0111 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:52:25 +0000 Subject: [PATCH] Batch57: Otter Blocks tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch57.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 includes/Extensions/Batch57.php diff --git a/includes/Extensions/Batch57.php b/includes/Extensions/Batch57.php new file mode 100644 index 0000000..743bc33 --- /dev/null +++ b/includes/Extensions/Batch57.php @@ -0,0 +1,43 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch57::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('otter_detect', 'Report whether Otter Blocks is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('otter_list_posts', 'List recent posts that use Otter (themeisle) blocks (id, title, type).', + ['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listPosts')); + } + + public static function detect(array $args): array { + return ['active' => defined('OTTER_BLOCKS_VERSION'), 'version' => defined('OTTER_BLOCKS_VERSION') ? OTTER_BLOCKS_VERSION : null]; + } + + public static function listPosts(array $args): array { + global $wpdb; + $per = max(1, (int) ($args['per_page'] ?? 50)); + $like = '%' . $wpdb->esc_like('wp:themeisle-blocks') . '%'; + $rows = $wpdb->get_results($wpdb->prepare( + "SELECT ID, post_title, post_type FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_content LIKE %s ORDER BY ID DESC LIMIT %d", + $like, $per), ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['ID'], 'title' => $r['post_title'], 'type' => $r['post_type']]; + return ['count' => count($out), 'posts' => $out]; + } +}