refactor: auto-discover Extensions/Batch*.php via glob loader (guarded); no per-batch main-file edits
This commit is contained in:
+19
-4
@@ -33,10 +33,25 @@ spl_autoload_register(function (string $class): void {
|
|||||||
if (file_exists($file)) require_once $file;
|
if (file_exists($file)) require_once $file;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tool batches merged from the elementor-mcp / wordpress-mcp parity program.
|
/**
|
||||||
// Each batch registers net-new tools through the asktam_mcp_register_tools hook,
|
* Tool-batch loader — part of the elementor-mcp / wordpress-mcp parity program.
|
||||||
// so core files stay untouched. See includes/Extensions/ and NOTICE.md.
|
* Auto-discovers includes/Extensions/Batch*.php and lets each self-register its
|
||||||
add_action('asktam_mcp_register_tools', ['AskTamMCP\Extensions\Batch1', 'register']);
|
* net-new tools through the asktam_mcp_register_tools hook. Each batch is isolated
|
||||||
|
* in try/catch so a single faulty batch can never break tool registration.
|
||||||
|
* Adding a batch = drop a BatchN.php file; no edit to this file is needed.
|
||||||
|
*/
|
||||||
|
add_action('asktam_mcp_register_tools', function ($registry): void {
|
||||||
|
foreach (glob(ASKTAM_MCP_DIR . 'includes/Extensions/Batch*.php') ?: [] as $f) {
|
||||||
|
$cls = 'AskTamMCP\\Extensions\\' . basename($f, '.php');
|
||||||
|
if (class_exists($cls) && method_exists($cls, 'register')) {
|
||||||
|
try {
|
||||||
|
$cls::register($registry);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
error_log('[AskTamMCP] batch ' . basename($f) . ' register failed: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
|
||||||
add_action('plugins_loaded', function (): void {
|
add_action('plugins_loaded', function (): void {
|
||||||
AskTamMCP\Core\Plugin::instance()->boot();
|
AskTamMCP\Core\Plugin::instance()->boot();
|
||||||
|
|||||||
Reference in New Issue
Block a user