feat: content schema with registered and sampled meta fields

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-25 22:04:04 +02:00
co-authored by Claude Opus 5.5
parent 261972751f
commit b3f4b7ba65
9 changed files with 600 additions and 0 deletions
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\WordPress\Schema;
/**
* Meta keys actually used by the most recent posts of a type. Keys starting with
* "_" are internal and only shown when another source knows them.
*/
final class SampledMetaSource extends MetaFieldSource
{
private const SAMPLE_POSTS = 50;
private const MAX_KEYS = 200;
public function __construct(private ?\wpdb $db = null)
{
}
public function id(): string
{
return 'sample';
}
public function fieldsFor(string $postType): array
{
$wpdb = $this->db ?? $GLOBALS['wpdb'];
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- only core table names interpolated.
$keys = $wpdb->get_col($wpdb->prepare(
"SELECT DISTINCT pm.meta_key FROM {$wpdb->postmeta} pm
INNER JOIN (
SELECT ID FROM {$wpdb->posts}
WHERE post_type = %s AND post_status NOT IN ('auto-draft', 'trash')
ORDER BY ID DESC LIMIT %d
) recent ON recent.ID = pm.post_id
ORDER BY pm.meta_key LIMIT %d",
$postType,
self::SAMPLE_POSTS,
self::MAX_KEYS
));
$fields = [];
foreach ((array) $keys as $key) {
$key = (string) $key;
if ($key === '' || str_starts_with($key, '_')) {
continue;
}
$fields[] = new FieldDefinition($key, $key, 'unknown', 'sample', FieldDefinition::UNKNOWN);
}
return $fields;
}
}