From c01eeb5fe88cc98495c46a5f827b0a658c489d65 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:42:12 +0000 Subject: [PATCH] Batch33: LifterLMS tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch33.php | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 includes/Extensions/Batch33.php diff --git a/includes/Extensions/Batch33.php b/includes/Extensions/Batch33.php new file mode 100644 index 0000000..18cd194 --- /dev/null +++ b/includes/Extensions/Batch33.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\\Batch33::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('llms_detect', 'Report whether LifterLMS is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('llms_list_courses', 'List LifterLMS courses (id, title, status).', + ['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listCourses')); + $registry->register($def('llms_get_course', 'Get one LifterLMS course: title and price.', + ['course_id' => ['type' => 'integer']], ['course_id'], 'read', 'getCourse')); + $registry->register($def('llms_list_memberships', 'List LifterLMS memberships (id, title).', + ['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listMemberships')); + } + + public static function detect(array $args): array { + return ['active' => defined('LLMS_VERSION'), 'version' => defined('LLMS_VERSION') ? LLMS_VERSION : null]; + } + + public static function listCourses(array $args): array { + $posts = get_posts(['post_type' => 'course', 'post_status' => ['publish', 'draft'], + 'numberposts' => (int) ($args['per_page'] ?? 50), 'orderby' => 'title', 'order' => 'ASC']); + $out = []; + foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title, 'status' => $p->post_status]; + return ['count' => count($out), 'courses' => $out]; + } + + public static function getCourse(array $args): array { + $id = (int) ($args['course_id'] ?? 0); + $p = get_post($id); + if (!$p || $p->post_type !== 'course') throw new \RuntimeException("LifterLMS course not found: {$id}"); + $price = null; + if (function_exists('llms_get_post')) { + $c = llms_get_post($id); + if (is_object($c) && method_exists($c, 'get_price')) $price = $c->get_price(); + } + if ($price === null) $price = get_post_meta($id, '_llms_price', true); + return ['id' => $id, 'title' => $p->post_title, 'status' => $p->post_status, 'price' => $price]; + } + + public static function listMemberships(array $args): array { + $posts = get_posts(['post_type' => 'llms_membership', 'post_status' => ['publish', 'draft'], + 'numberposts' => (int) ($args['per_page'] ?? 50), 'orderby' => 'title', 'order' => 'ASC']); + $out = []; + foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title]; + return ['count' => count($out), 'memberships' => $out]; + } +}