02e2db3b56
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
48 lines
2.4 KiB
PHP
48 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Batch 55 — Blocksy (Companion) tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
|
* Inert unless Blocksy Companion is active. NOTE: the companion plugin does not define
|
|
* BLOCKSY_COMPANION_VERSION; BLOCKSY_PATH / BLOCKSY_PLUGIN_BASE are defined whenever it
|
|
* loads, so we gate on either (verified live on mainwp 2026-10-16).
|
|
* Content blocks are the 'ct_content_block' CPT.
|
|
*/
|
|
|
|
namespace AskTamMCP\Extensions;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Batch55 {
|
|
|
|
public static function register($registry): void {
|
|
if (!defined('BLOCKSY_COMPANION_VERSION') && !defined('BLOCKSY_PATH')) 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\\Batch55::' . $method, 'inputSchema' => $schema];
|
|
};
|
|
|
|
$registry->register($def('blocksy_detect', 'Report whether Blocksy Companion is active and its version.', [], [], 'read', 'detect'));
|
|
$registry->register($def('blocksy_list_content_blocks', 'List Blocksy content blocks / hooks (id, title).',
|
|
['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listContentBlocks'));
|
|
}
|
|
|
|
public static function detect(array $args): array {
|
|
$active = defined('BLOCKSY_COMPANION_VERSION') || defined('BLOCKSY_PATH');
|
|
$ver = defined('BLOCKSY_COMPANION_VERSION') ? BLOCKSY_COMPANION_VERSION : (defined('BLOCKSY_VERSION') ? BLOCKSY_VERSION : null);
|
|
return ['active' => $active, 'version' => $ver];
|
|
}
|
|
|
|
public static function listContentBlocks(array $args): array {
|
|
if (!post_type_exists('ct_content_block')) {
|
|
return ['supported' => false, 'note' => 'ct_content_block post type not registered.', 'blocks' => []];
|
|
}
|
|
$posts = get_posts(['post_type' => 'ct_content_block', '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 ['supported' => true, 'count' => count($out), 'blocks' => $out];
|
|
}
|
|
}
|