diff --git a/includes/Extensions/Batch26.php b/includes/Extensions/Batch26.php new file mode 100644 index 0000000..40cf6ed --- /dev/null +++ b/includes/Extensions/Batch26.php @@ -0,0 +1,66 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch26::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('wpforms_detect', 'Report whether WPForms is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('wpforms_list_forms', 'List WPForms forms (id, title).', + ['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listForms')); + $registry->register($def('wpforms_get_form', 'Get one WPForms form: title plus the number of fields in its config.', + ['form_id' => ['type' => 'integer']], ['form_id'], 'read', 'getForm')); + $registry->register($def('wpforms_list_entries', 'List entries for a WPForms form (newest first). Requires WPForms Pro.', + ['form_id' => ['type' => 'integer'], 'per_page' => ['type' => 'integer', 'default' => 25]], ['form_id'], 'read', 'listEntries')); + } + + public static function detect(array $args): array { + return ['active' => defined('WPFORMS_VERSION'), 'version' => defined('WPFORMS_VERSION') ? WPFORMS_VERSION : null]; + } + + public static function listForms(array $args): array { + $posts = get_posts(['post_type' => 'wpforms', 'post_status' => 'publish', + 'numberposts' => (int) ($args['per_page'] ?? 100), 'orderby' => 'title', 'order' => 'ASC']); + $out = []; + foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title]; + return ['count' => count($out), 'forms' => $out]; + } + + public static function getForm(array $args): array { + $id = (int) ($args['form_id'] ?? 0); + $p = get_post($id); + if (!$p || $p->post_type !== 'wpforms') throw new \RuntimeException("WPForms form not found: {$id}"); + $cfg = json_decode((string) $p->post_content, true); + $n = (is_array($cfg) && isset($cfg['fields']) && is_array($cfg['fields'])) ? count($cfg['fields']) : 0; + return ['id' => $id, 'title' => $p->post_title, 'field_count' => $n]; + } + + public static function listEntries(array $args): array { + global $wpdb; + $t = $wpdb->prefix . 'wpforms_entries'; + if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t)) !== $t) { + return ['supported' => false, 'note' => 'Entry storage requires WPForms Pro.', 'entries' => []]; + } + $fid = (int) ($args['form_id'] ?? 0); + $per = max(1, (int) ($args['per_page'] ?? 25)); + $rows = $wpdb->get_results($wpdb->prepare("SELECT entry_id, form_id, status, date FROM {$t} WHERE form_id = %d ORDER BY entry_id DESC LIMIT %d", $fid, $per), ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['entry_id'], 'status' => $r['status'], 'date' => $r['date']]; + return ['supported' => true, 'form_id' => $fid, 'count' => count($out), 'entries' => $out]; + } +}