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>
53 lines
1.5 KiB
PHP
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;
|
|
}
|
|
}
|