'object', 'properties' => $props ?: new \stdClass()]; if ($required) $schema['required'] = $required; return ['name' => $name, 'description' => $desc, 'scope' => $scope, 'handler' => 'AskTamMCP\\Extensions\\Batch25::' . $method, 'inputSchema' => $schema]; }; $registry->register($def('fluentform_detect', 'Report whether Fluent Forms is active and its version.', [], [], 'read', 'detect')); $registry->register($def('fluentform_list_forms', 'List Fluent Forms (id, title, status, entry count).', ['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listForms')); $registry->register($def('fluentform_get_form', 'Get one Fluent Form: title, status, and the number of fields in its layout.', ['form_id' => ['type' => 'integer']], ['form_id'], 'read', 'getForm')); $registry->register($def('fluentform_list_entries', 'List submissions for a Fluent Form (newest first): id, status, 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' => defined('FLUENTFORM_VERSION'), 'version' => defined('FLUENTFORM_VERSION') ? FLUENTFORM_VERSION : null]; } public static function listForms(array $args): array { global $wpdb; $t = $wpdb->prefix . 'fluentform_forms'; $s = $wpdb->prefix . 'fluentform_submissions'; $per = max(1, (int) ($args['per_page'] ?? 100)); $rows = $wpdb->get_results($wpdb->prepare("SELECT id, title, status FROM {$t} ORDER BY id DESC LIMIT %d", $per), ARRAY_A); $out = []; foreach ((array) $rows as $r) { $c = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$s} WHERE form_id = %d", $r['id'])); $out[] = ['id' => (int) $r['id'], 'title' => $r['title'], 'status' => $r['status'], 'entries' => $c]; } return ['count' => count($out), 'forms' => $out]; } public static function getForm(array $args): array { global $wpdb; $t = $wpdb->prefix . 'fluentform_forms'; $id = (int) ($args['form_id'] ?? 0); $r = $wpdb->get_row($wpdb->prepare("SELECT id, title, status, form_fields FROM {$t} WHERE id = %d", $id), ARRAY_A); if (!$r) throw new \RuntimeException("Fluent form not found: {$id}"); $fields = json_decode((string) $r['form_fields'], true); $n = 0; if (is_array($fields) && isset($fields['fields']) && is_array($fields['fields'])) $n = count($fields['fields']); return ['id' => (int) $r['id'], 'title' => $r['title'], 'status' => $r['status'], 'field_count' => $n]; } public static function listEntries(array $args): array { global $wpdb; $s = $wpdb->prefix . 'fluentform_submissions'; $fid = (int) ($args['form_id'] ?? 0); $per = max(1, (int) ($args['per_page'] ?? 25)); $rows = $wpdb->get_results($wpdb->prepare("SELECT id, form_id, status, created_at FROM {$s} 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'], 'status' => $r['status'], 'created_at' => $r['created_at']]; return ['form_id' => $fid, 'count' => count($out), 'entries' => $out]; } }