b1cb7560fb
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
49 lines
2.2 KiB
PHP
49 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Batch 41 — TranslatePress tools (reads its settings option). Net-new, GPL-2.0-or-later. See NOTICE.md.
|
|
* Inert unless TranslatePress (TRP_PLUGIN_VERSION) is active.
|
|
*/
|
|
|
|
namespace AskTamMCP\Extensions;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Batch41 {
|
|
|
|
public static function register($registry): void {
|
|
if (!defined('TRP_PLUGIN_VERSION')) return;
|
|
|
|
$def = function (string $name, string $desc, array $props, array $required, string $scope, string $method) {
|
|
$schema = ['type' => 'object', 'properties' => $props ?: new \stdClass()];
|
|
if ($required) $schema['required'] = $required;
|
|
return ['name' => $name, 'description' => $desc, 'scope' => $scope,
|
|
'handler' => 'AskTamMCP\\Extensions\\Batch41::' . $method, 'inputSchema' => $schema];
|
|
};
|
|
|
|
$registry->register($def('trp_detect', 'Report whether TranslatePress is active and its version.', [], [], 'read', 'detect'));
|
|
$registry->register($def('trp_list_languages', 'List TranslatePress languages: default and translation language codes.', [], [], 'read', 'listLanguages'));
|
|
$registry->register($def('trp_settings', 'Read TranslatePress key settings (languages, default, translation editor options).', [], [], 'read', 'settings'));
|
|
}
|
|
|
|
public static function detect(array $args): array {
|
|
return ['active' => defined('TRP_PLUGIN_VERSION'), 'version' => defined('TRP_PLUGIN_VERSION') ? TRP_PLUGIN_VERSION : null];
|
|
}
|
|
|
|
public static function listLanguages(array $args): array {
|
|
$s = get_option('trp_settings', []);
|
|
if (!is_array($s)) $s = [];
|
|
return ['default' => $s['default-language'] ?? null, 'languages' => $s['translation-languages'] ?? [],
|
|
'publish_languages' => $s['publish-languages'] ?? []];
|
|
}
|
|
|
|
public static function settings(array $args): array {
|
|
$s = get_option('trp_settings', []);
|
|
if (!is_array($s)) $s = [];
|
|
$keys = ['default-language', 'translation-languages', 'publish-languages', 'native_or_english_name',
|
|
'force-language-to-custom-links', 'url-slugs', 'trp-ls-floater'];
|
|
$out = [];
|
|
foreach ($keys as $k) if (isset($s[$k])) $out[$k] = $s[$k];
|
|
return ['settings' => $out];
|
|
}
|
|
}
|