diff --git a/includes/Extensions/Batch40.php b/includes/Extensions/Batch40.php new file mode 100644 index 0000000..cf51f34 --- /dev/null +++ b/includes/Extensions/Batch40.php @@ -0,0 +1,53 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch40::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('polylang_detect', 'Report whether Polylang is active, its version, and the default language.', [], [], 'read', 'detect')); + $registry->register($def('polylang_list_languages', 'List Polylang languages (slug) and the default.', [], [], 'read', 'listLanguages')); + $registry->register($def('polylang_get_post_language', 'Get the language slug of a post.', + ['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'getPostLanguage')); + $registry->register($def('polylang_get_translations', 'Get the translation post ids of a post, keyed by language slug.', + ['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'getTranslations')); + } + + public static function detect(array $args): array { + return ['active' => defined('POLYLANG_VERSION'), 'version' => defined('POLYLANG_VERSION') ? POLYLANG_VERSION : null, + 'default' => function_exists('pll_default_language') ? pll_default_language() : null]; + } + + public static function listLanguages(array $args): array { + $langs = function_exists('pll_languages_list') ? pll_languages_list() : []; + return ['count' => count((array) $langs), 'languages' => array_values((array) $langs), + 'default' => function_exists('pll_default_language') ? pll_default_language() : null]; + } + + public static function getPostLanguage(array $args): array { + $id = (int) ($args['post_id'] ?? 0); + $lang = function_exists('pll_get_post_language') ? pll_get_post_language($id) : null; + return ['post_id' => $id, 'language' => $lang]; + } + + public static function getTranslations(array $args): array { + $id = (int) ($args['post_id'] ?? 0); + $tr = function_exists('pll_get_post_translations') ? pll_get_post_translations($id) : []; + return ['post_id' => $id, 'translations' => (array) $tr]; + } +}