Batch39: Mailchimp for WordPress tools (guarded, net-new)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
2026-10-16 04:44:59 +00:00
parent 37ce29d667
commit cb0d284747
+48
View File
@@ -0,0 +1,48 @@
<?php
/**
* Batch 39 — Mailchimp for WordPress (mc4wp) tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
* Inert unless mc4wp (MC4WP_VERSION) is active. Forms are the 'mc4wp-form' CPT.
*/
namespace AskTamMCP\Extensions;
defined('ABSPATH') || exit;
class Batch39 {
public static function register($registry): void {
if (!defined('MC4WP_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\\Batch39::' . $method, 'inputSchema' => $schema];
};
$registry->register($def('mc4wp_detect', 'Report whether Mailchimp for WordPress is active and its version.', [], [], 'read', 'detect'));
$registry->register($def('mc4wp_list_forms', 'List Mailchimp for WP forms (id, title).',
['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listForms'));
$registry->register($def('mc4wp_get_form', 'Get one mc4wp form: title plus its raw form markup.',
['form_id' => ['type' => 'integer']], ['form_id'], 'read', 'getForm'));
}
public static function detect(array $args): array {
return ['active' => defined('MC4WP_VERSION'), 'version' => defined('MC4WP_VERSION') ? MC4WP_VERSION : null];
}
public static function listForms(array $args): array {
$posts = get_posts(['post_type' => 'mc4wp-form', '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), 'forms' => $out];
}
public static function getForm(array $args): array {
$id = (int) ($args['form_id'] ?? 0);
$p = get_post($id);
if (!$p || $p->post_type !== 'mc4wp-form') throw new \RuntimeException("mc4wp form not found: {$id}");
return ['id' => $id, 'title' => $p->post_title, 'markup' => (string) $p->post_content];
}
}