Batch28: Formidable Forms 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:37:18 +00:00
parent d2a8838406
commit 0b4661505d
+67
View File
@@ -0,0 +1,67 @@
<?php
/**
* Batch 28 — Formidable Forms tools via its static model classes. Net-new, GPL-2.0-or-later. See NOTICE.md.
* Inert unless Formidable (class FrmForm) is active.
*/
namespace AskTamMCP\Extensions;
defined('ABSPATH') || exit;
class Batch28 {
public static function register($registry): void {
if (!class_exists('FrmForm')) 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\\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];
}
}