Batch50: Beaver Builder tools (guarded, net-new)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Batch 50 — Beaver Builder tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
||||||
|
* Inert unless Beaver Builder (FL_BUILDER_VERSION) is active. Templates are the 'fl-builder-template' CPT.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace AskTamMCP\Extensions;
|
||||||
|
|
||||||
|
defined('ABSPATH') || exit;
|
||||||
|
|
||||||
|
class Batch50 {
|
||||||
|
|
||||||
|
public static function register($registry): void {
|
||||||
|
if (!defined('FL_BUILDER_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\\Batch50::' . $method, 'inputSchema' => $schema];
|
||||||
|
};
|
||||||
|
|
||||||
|
$registry->register($def('bb_detect', 'Report whether Beaver Builder is active and its version.', [], [], 'read', 'detect'));
|
||||||
|
$registry->register($def('bb_list_templates', 'List Beaver Builder saved templates (id, title).',
|
||||||
|
['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listTemplates'));
|
||||||
|
$registry->register($def('bb_is_built', 'Report whether Beaver Builder is enabled on a post.',
|
||||||
|
['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'isBuilt'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function detect(array $args): array {
|
||||||
|
return ['active' => defined('FL_BUILDER_VERSION'), 'version' => defined('FL_BUILDER_VERSION') ? FL_BUILDER_VERSION : null];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listTemplates(array $args): array {
|
||||||
|
$posts = get_posts(['post_type' => 'fl-builder-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, 'beaver_built' => (bool) get_post_meta($id, '_fl_builder_enabled', true)];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user