From 0b4661505d719f29c3767a9a8a17ada0774c9387 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:37:18 +0000 Subject: [PATCH] Batch28: Formidable Forms tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch28.php | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 includes/Extensions/Batch28.php diff --git a/includes/Extensions/Batch28.php b/includes/Extensions/Batch28.php new file mode 100644 index 0000000..09891c1 --- /dev/null +++ b/includes/Extensions/Batch28.php @@ -0,0 +1,67 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch28::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('frm_detect', 'Report whether Formidable Forms is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('frm_list_forms', 'List Formidable forms (id, name, key).', [], [], 'read', 'listForms')); + $registry->register($def('frm_get_form', 'Get one Formidable form: name plus its fields (id, name, type).', + ['form_id' => ['type' => 'integer']], ['form_id'], 'read', 'getForm')); + $registry->register($def('frm_list_entries', 'List entries for a Formidable form (newest first): id, created_at.', + ['form_id' => ['type' => 'integer'], 'per_page' => ['type' => 'integer', 'default' => 25]], ['form_id'], 'read', 'listEntries')); + } + + public static function detect(array $args): array { + return ['active' => class_exists('FrmForm'), 'version' => defined('FrmAppHelper::plugin_version') ? null : (class_exists('FrmAppHelper') && method_exists('FrmAppHelper', 'plugin_version') ? \FrmAppHelper::plugin_version() : null)]; + } + + public static function listForms(array $args): array { + $forms = \FrmForm::getAll(['is_template' => 0, 'status' => 'published'], 'name'); + $out = []; + foreach ((array) $forms as $f) { + $out[] = ['id' => (int) ($f->id ?? 0), 'name' => $f->name ?? '', 'key' => $f->form_key ?? '']; + } + return ['count' => count($out), 'forms' => $out]; + } + + public static function getForm(array $args): array { + $id = (int) ($args['form_id'] ?? 0); + $form = \FrmForm::getOne($id); + if (!$form) throw new \RuntimeException("Formidable form not found: {$id}"); + $fields = []; + if (class_exists('FrmField')) { + foreach ((array) \FrmField::get_all_for_form($id) as $fld) { + $fields[] = ['id' => (int) ($fld->id ?? 0), 'name' => $fld->name ?? '', 'type' => $fld->type ?? '']; + } + } + return ['id' => $id, 'name' => $form->name ?? '', 'fields' => $fields]; + } + + public static function listEntries(array $args): array { + global $wpdb; + $t = $wpdb->prefix . 'frm_items'; + $fid = (int) ($args['form_id'] ?? 0); + $per = max(1, (int) ($args['per_page'] ?? 25)); + $rows = $wpdb->get_results($wpdb->prepare("SELECT id, created_at FROM {$t} WHERE form_id = %d ORDER BY id DESC LIMIT %d", $fid, $per), ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'created_at' => $r['created_at']]; + return ['form_id' => $fid, 'count' => count($out), 'entries' => $out]; + } +}