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,38 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\WordPress\Schema;
/**
* Shared read/write via the post meta API.
*/
abstract class MetaFieldSource implements FieldSource
{
public function read(int $postId, FieldDefinition $field): mixed
{
return get_post_meta($postId, $field->key, ! $field->multiple);
}
public function write(int $postId, string $postType, array $values, array $definitions): void
{
foreach ($values as $key => $value) {
$key = (string) $key;
if ($value === null) {
delete_post_meta($postId, $key);
continue;
}
$field = $definitions[$key] ?? null;
if ($field !== null && $field->multiple && is_array($value) && array_is_list($value)) {
delete_post_meta($postId, $key);
foreach ($value as $item) {
add_post_meta($postId, $key, wp_slash($item));
}
continue;
}
update_post_meta($postId, $key, wp_slash($value));
}
}
}