cf62f10344
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
72 lines
3.9 KiB
PHP
72 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* Batch 46 — SEOPress tools (post-meta based). Net-new, GPL-2.0-or-later. See NOTICE.md.
|
|
* Inert unless SEOPress (SEOPRESS_VERSION) is active.
|
|
*/
|
|
|
|
namespace AskTamMCP\Extensions;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Batch46 {
|
|
|
|
public static function register($registry): void {
|
|
if (!defined('SEOPRESS_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\\Batch46::' . $method, 'inputSchema' => $schema];
|
|
};
|
|
|
|
$registry->register($def('seopress_detect', 'Report whether SEOPress is active and its version.', [], [], 'read', 'detect'));
|
|
$registry->register($def('seopress_get_meta', 'Get SEOPress SEO meta for a post: title, description, target keyword, canonical.',
|
|
['post_id' => ['type' => 'integer']], ['post_id'], 'read', 'getMeta'));
|
|
$registry->register($def('seopress_update_meta', 'Update SEOPress SEO meta for a post. Any of: title, description, target_keyword, canonical.',
|
|
['post_id' => ['type' => 'integer'], 'title' => ['type' => 'string'], 'description' => ['type' => 'string'],
|
|
'target_keyword' => ['type' => 'string'], 'canonical' => ['type' => 'string']], ['post_id'], 'write', 'updateMeta'));
|
|
$registry->register($def('seopress_bulk_audit', 'Audit recent posts for missing SEOPress title/description.',
|
|
['post_type' => ['type' => 'string', 'default' => 'post'], 'per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'bulkAudit'));
|
|
}
|
|
|
|
public static function detect(array $args): array {
|
|
return ['active' => defined('SEOPRESS_VERSION'), 'version' => defined('SEOPRESS_VERSION') ? SEOPRESS_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, '_seopress_titles_title', true),
|
|
'description' => get_post_meta($id, '_seopress_titles_desc', true),
|
|
'target_keyword' => get_post_meta($id, '_seopress_analysis_target_kw', true),
|
|
'canonical' => get_post_meta($id, '_seopress_robots_canonical', 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' => '_seopress_titles_title', 'description' => '_seopress_titles_desc',
|
|
'target_keyword' => '_seopress_analysis_target_kw', 'canonical' => '_seopress_robots_canonical'];
|
|
$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, '_seopress_titles_title', true)) $miss[] = 'title';
|
|
if (!get_post_meta($p->ID, '_seopress_titles_desc', true)) $miss[] = 'description';
|
|
if ($miss) $issues[] = ['id' => $p->ID, 'title' => $p->post_title, 'missing' => $miss];
|
|
}
|
|
return ['post_type' => $pt, 'checked' => count($posts), 'offenders' => count($issues), 'issues' => $issues];
|
|
}
|
|
}
|