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:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\WordPress\Schema;
|
||||
|
||||
/**
|
||||
* Fields registered with register_meta()/register_post_meta().
|
||||
*/
|
||||
final class RegisteredMetaSource extends MetaFieldSource
|
||||
{
|
||||
private const TYPES = ['string', 'boolean', 'integer', 'number', 'array', 'object'];
|
||||
|
||||
public function id(): string
|
||||
{
|
||||
return 'meta';
|
||||
}
|
||||
|
||||
public function fieldsFor(string $postType): array
|
||||
{
|
||||
$keys = array_merge(get_registered_meta_keys('post', ''), get_registered_meta_keys('post', $postType));
|
||||
$fields = [];
|
||||
foreach ($keys as $key => $args) {
|
||||
$key = (string) $key;
|
||||
$args = is_array($args) ? $args : [];
|
||||
$type = (string) ($args['type'] ?? 'string');
|
||||
$readonly = is_protected_meta($key, 'post') && empty($args['show_in_rest']);
|
||||
|
||||
$fields[] = new FieldDefinition(
|
||||
$key,
|
||||
$key,
|
||||
in_array($type, self::TYPES, true) ? $type : 'unknown',
|
||||
'meta',
|
||||
$readonly ? FieldDefinition::READONLY : FieldDefinition::WRITABLE,
|
||||
false,
|
||||
! (bool) ($args['single'] ?? false),
|
||||
null,
|
||||
null,
|
||||
(string) ($args['description'] ?? '')
|
||||
);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user