Files
advanced-mcp-plugin/includes/Extensions/Batch51.php
T

48 lines
2.3 KiB
PHP

<?php
/**
* Batch 51 — Breakdance tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
* Inert unless Breakdance (__BREAKDANCE_VERSION) is active. Templates are the 'breakdance_template' CPT.
*/
namespace AskTamMCP\Extensions;
defined('ABSPATH') || exit;
class Batch51 {
public static function register($registry): void {
if (!defined('__BREAKDANCE_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\\Batch51::' . $method, 'inputSchema' => $schema];
};
$registry->register($def('breakdance_detect', 'Report whether Breakdance is active and its version.', [], [], 'read', 'detect'));
$registry->register($def('breakdance_list_templates', 'List Breakdance templates (id, title).',
['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listTemplates'));
$registry->register($def('breakdance_is_built', 'Report whether Breakdance content is stored on a post.',
['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'isBuilt'));
}
public static function detect(array $args): array {
return ['active' => defined('__BREAKDANCE_VERSION'), 'version' => defined('__BREAKDANCE_VERSION') ? constant('__BREAKDANCE_VERSION') : null];
}
public static function listTemplates(array $args): array {
$posts = get_posts(['post_type' => 'breakdance_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 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, 'breakdance_built' => (bool) get_post_meta($id, '_breakdance_data', true)];
}
}