8b96d106d2
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
44 lines
2.0 KiB
PHP
44 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Batch 57 — Otter Blocks tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
|
* Inert unless Otter Blocks (OTTER_BLOCKS_VERSION) is active. Block-based, so posts are found by block marker.
|
|
*/
|
|
|
|
namespace AskTamMCP\Extensions;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Batch57 {
|
|
|
|
public static function register($registry): void {
|
|
if (!defined('OTTER_BLOCKS_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\\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];
|
|
}
|
|
}
|