From 5542cc342bf8db51bf46edd1921042efd866e5b9 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:46:49 +0000 Subject: [PATCH] Batch43: ACF tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch43.php | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 includes/Extensions/Batch43.php diff --git a/includes/Extensions/Batch43.php b/includes/Extensions/Batch43.php new file mode 100644 index 0000000..6ed1c45 --- /dev/null +++ b/includes/Extensions/Batch43.php @@ -0,0 +1,64 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch43::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('acf_detect', 'Report whether Advanced Custom Fields is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('acf_list_field_groups', 'List ACF field groups (key, title, active).', [], [], 'read', 'listGroups')); + $registry->register($def('acf_get_group_fields', 'List the fields of one ACF field group (name, label, type).', + ['group_key' => ['type' => 'string']], ['group_key'], 'read', 'getGroupFields')); + $registry->register($def('acf_get_field_value', 'Read one ACF field value for a given post. field = field name or key.', + ['post_id' => ['type' => 'integer'], 'field' => ['type' => 'string']], ['post_id', 'field'], 'read', 'getFieldValue')); + } + + public static function detect(array $args): array { + $v = function_exists('acf_get_setting') ? acf_get_setting('version') : (defined('ACF_VERSION') ? ACF_VERSION : null); + return ['active' => class_exists('ACF'), 'version' => $v]; + } + + public static function listGroups(array $args): array { + if (!function_exists('acf_get_field_groups')) return ['supported' => false, 'note' => 'acf_get_field_groups unavailable.', 'groups' => []]; + $groups = acf_get_field_groups(); + $out = []; + foreach ((array) $groups as $g) { + $out[] = ['key' => $g['key'] ?? '', 'title' => $g['title'] ?? '', 'active' => !empty($g['active'])]; + } + return ['count' => count($out), 'groups' => $out]; + } + + public static function getGroupFields(array $args): array { + if (!function_exists('acf_get_fields')) throw new \RuntimeException('acf_get_fields unavailable.'); + $key = (string) ($args['group_key'] ?? ''); + $fields = acf_get_fields($key); + $out = []; + foreach ((array) $fields as $f) { + $out[] = ['name' => $f['name'] ?? '', 'label' => $f['label'] ?? '', 'type' => $f['type'] ?? '', 'key' => $f['key'] ?? '']; + } + return ['group_key' => $key, 'count' => count($out), 'fields' => $out]; + } + + public static function getFieldValue(array $args): array { + if (!function_exists('get_field')) throw new \RuntimeException('get_field unavailable.'); + $id = (int) ($args['post_id'] ?? 0); + $field = (string) ($args['field'] ?? ''); + $val = get_field($field, $id); + return ['post_id' => $id, 'field' => $field, 'value' => $val]; + } +}