From 799331e6a1f790b7c2d5a668b9d8c9ce234ead97 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:37:42 +0000 Subject: [PATCH] Batch29: Forminator tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch29.php | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 includes/Extensions/Batch29.php diff --git a/includes/Extensions/Batch29.php b/includes/Extensions/Batch29.php new file mode 100644 index 0000000..2fb2346 --- /dev/null +++ b/includes/Extensions/Batch29.php @@ -0,0 +1,77 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch29::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('forminator_detect', 'Report whether Forminator is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('forminator_list_forms', 'List Forminator forms (id, name).', + ['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listForms')); + $registry->register($def('forminator_get_form', 'Get one Forminator form: name plus field count.', + ['form_id' => ['type' => 'integer']], ['form_id'], 'read', 'getForm')); + $registry->register($def('forminator_list_entries', 'Count and list recent entries for a Forminator form (id, date).', + ['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('Forminator_API'), 'version' => defined('FORMINATOR_VERSION') ? FORMINATOR_VERSION : null]; + } + + private static function formName($f): string { + if (is_object($f)) { + if (isset($f->settings['formName'])) return (string) $f->settings['formName']; + if (method_exists($f, 'get_name')) return (string) $f->get_name(); + if (isset($f->name)) return (string) $f->name; + } + return ''; + } + + public static function listForms(array $args): array { + $per = max(1, (int) ($args['per_page'] ?? 100)); + $forms = \Forminator_API::get_forms(null, 1, $per); + $out = []; + foreach ((array) $forms as $f) { + $id = is_object($f) ? ($f->id ?? null) : null; + $out[] = ['id' => $id, 'name' => self::formName($f)]; + } + return ['count' => count($out), 'forms' => $out]; + } + + public static function getForm(array $args): array { + $id = (int) ($args['form_id'] ?? 0); + $f = \Forminator_API::get_form($id); + if (empty($f) || is_wp_error($f)) throw new \RuntimeException("Forminator form not found: {$id}"); + $fields = is_object($f) && method_exists($f, 'get_fields') ? $f->get_fields() : []; + return ['id' => $id, 'name' => self::formName($f), 'field_count' => is_array($fields) ? count($fields) : 0]; + } + + public static function listEntries(array $args): array { + $fid = (int) ($args['form_id'] ?? 0); + $per = max(1, (int) ($args['per_page'] ?? 25)); + $total = method_exists('Forminator_API', 'count_entries') ? (int) \Forminator_API::count_entries($fid) : null; + $out = []; + if (method_exists('Forminator_API', 'get_entries')) { + $entries = \Forminator_API::get_entries($fid); + foreach (array_slice((array) $entries, 0, $per) as $e) { + $out[] = ['id' => is_object($e) ? ($e->entry_id ?? null) : null, 'date' => is_object($e) ? ($e->date_created_sql ?? '') : '']; + } + } + return ['form_id' => $fid, 'total' => $total, 'count' => count($out), 'entries' => $out]; + } +}