From 5dde44c2c7bbb85780cf6add4fc097e37e976d50 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:48:39 +0000 Subject: [PATCH] Batch44: Rank Math SEO tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch44.php | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 includes/Extensions/Batch44.php diff --git a/includes/Extensions/Batch44.php b/includes/Extensions/Batch44.php new file mode 100644 index 0000000..0fef58d --- /dev/null +++ b/includes/Extensions/Batch44.php @@ -0,0 +1,73 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch44::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('rankmath_detect', 'Report whether Rank Math is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('rankmath_get_meta', 'Get Rank Math SEO meta for a post: title, description, focus keyword, canonical, robots.', + ['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'getMeta')); + $registry->register($def('rankmath_update_meta', 'Update Rank Math SEO meta for a post. Any of: title, description, focus_keyword, canonical.', + ['post_id' => ['type' => 'integer'], 'title' => ['type' => 'string'], 'description' => ['type' => 'string'], + 'focus_keyword' => ['type' => 'string'], 'canonical' => ['type' => 'string']], ['post_id'], 'write', 'updateMeta')); + $registry->register($def('rankmath_bulk_audit', 'Audit recent posts for missing Rank Math title/description/focus keyword.', + ['post_type' => ['type' => 'string', 'default' => 'post'], 'per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'bulkAudit')); + } + + public static function detect(array $args): array { + return ['active' => defined('RANK_MATH_VERSION'), 'version' => defined('RANK_MATH_VERSION') ? RANK_MATH_VERSION : null]; + } + + public static function getMeta(array $args): array { + $id = (int) ($args['post_id'] ?? 0); + if (!get_post($id)) throw new \RuntimeException("Post not found: {$id}"); + return ['post_id' => $id, + 'title' => get_post_meta($id, 'rank_math_title', true), + 'description' => get_post_meta($id, 'rank_math_description', true), + 'focus_keyword' => get_post_meta($id, 'rank_math_focus_keyword', true), + 'canonical' => get_post_meta($id, 'rank_math_canonical_url', true), + 'robots' => get_post_meta($id, 'rank_math_robots', true)]; + } + + public static function updateMeta(array $args): array { + $id = (int) ($args['post_id'] ?? 0); + if (!get_post($id)) throw new \RuntimeException("Post not found: {$id}"); + $map = ['title' => 'rank_math_title', 'description' => 'rank_math_description', + 'focus_keyword' => 'rank_math_focus_keyword', 'canonical' => 'rank_math_canonical_url']; + $updated = []; + foreach ($map as $arg => $meta) { + if (array_key_exists($arg, $args)) { update_post_meta($id, $meta, (string) $args[$arg]); $updated[] = $arg; } + } + return ['post_id' => $id, 'updated' => $updated]; + } + + public static function bulkAudit(array $args): array { + $pt = (string) ($args['post_type'] ?? 'post'); + $posts = get_posts(['post_type' => $pt, 'post_status' => 'publish', 'numberposts' => (int) ($args['per_page'] ?? 50)]); + $issues = []; + foreach ($posts as $p) { + $miss = []; + if (!get_post_meta($p->ID, 'rank_math_title', true)) $miss[] = 'title'; + if (!get_post_meta($p->ID, 'rank_math_description', true)) $miss[] = 'description'; + if (!get_post_meta($p->ID, 'rank_math_focus_keyword', true)) $miss[] = 'focus_keyword'; + if ($miss) $issues[] = ['id' => $p->ID, 'title' => $p->post_title, 'missing' => $miss]; + } + return ['post_type' => $pt, 'checked' => count($posts), 'offenders' => count($issues), 'issues' => $issues]; + } +}