Files
WP-LIT-MCP/src/Integrations/WordPress/Schema/RegisteredMetaSource.php
T
Jan-Niclas LoosenandClaude Opus 5.5 234fd1edac fix(security): Pods-Meta nur lesbar, wenn Pods aktiv, aber nicht nutzbar
Ist Pods aktiv, seine API aber nicht nutzbar, melden gesampelte und registrierte Meta-Schlüssel READONLY statt schreibbar. Sonst würden Pods-Felder (auch über Pods' register_meta-Integration) an Pods vorbei geschrieben.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 11:30:05 +01:00

53 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\WordPress\Schema;
defined('ABSPATH') || exit;
/**
* Fields registered with register_meta()/register_post_meta().
*/
final class RegisteredMetaSource extends MetaFieldSource
{
private const TYPES = ['string', 'boolean', 'integer', 'number', 'array', 'object'];
/** @param bool $readOnly Report every key as READONLY (Pods is active but cannot be used to write its keys). */
public function __construct(private bool $readOnly = false)
{
}
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 = $this->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;
}
}