Batch38: FunnelKit 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:
2026-10-16 04:44:49 +00:00
parent e99c21318f
commit 37ce29d667
+50
View File
@@ -0,0 +1,50 @@
<?php
/**
* Batch 38 — FunnelKit (Funnel Builder) tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
* Inert unless FunnelKit (WFFN_VERSION) is active. Defensive about its storage (CPT or custom tables).
*/
namespace AskTamMCP\Extensions;
defined('ABSPATH') || exit;
class Batch38 {
public static function register($registry): void {
if (!defined('WFFN_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\\Batch38::' . $method, 'inputSchema' => $schema];
};
$registry->register($def('funnelkit_detect', 'Report whether FunnelKit (Funnel Builder) is active and its version.', [], [], 'read', 'detect'));
$registry->register($def('funnelkit_list_funnels', 'List FunnelKit funnels (id, title). Reads the funnels table or CPT, whichever this install uses.',
['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listFunnels'));
}
public static function detect(array $args): array {
return ['active' => defined('WFFN_VERSION'), 'version' => defined('WFFN_VERSION') ? WFFN_VERSION : null];
}
public static function listFunnels(array $args): array {
global $wpdb;
$per = max(1, (int) ($args['per_page'] ?? 50));
$t = $wpdb->prefix . 'wffn_funnels';
if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t)) === $t) {
$rows = $wpdb->get_results($wpdb->prepare("SELECT id, title FROM {$t} ORDER BY id DESC LIMIT %d", $per), ARRAY_A);
$out = [];
foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'title' => $r['title']];
return ['supported' => true, 'source' => 'table', 'count' => count($out), 'funnels' => $out];
}
if (post_type_exists('wffn_funnel')) {
$posts = get_posts(['post_type' => 'wffn_funnel', 'post_status' => 'any', 'numberposts' => $per, 'orderby' => 'date', 'order' => 'DESC']);
$out = [];
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title];
return ['supported' => true, 'source' => 'cpt', 'count' => count($out), 'funnels' => $out];
}
return ['supported' => false, 'note' => 'FunnelKit funnels storage not found on this install.', 'funnels' => []];
}
}