'key', 'type' => 'text', 'label' => __('Meta key', 'zadex'), 'default' => '', 'dynamicOptions' => true], ]; } public static function is_protected(string $key): bool { if ($key === '' || $key[0] === '_') { return true; } return function_exists('is_protected_meta') && is_protected_meta($key, 'post'); } public function options(string $control, string $search, Context $ctx): array { if ($control !== 'key' || $ctx->post_id <= 0 || !function_exists('get_post_custom_keys')) { return []; } $out = []; foreach ((array) get_post_custom_keys($ctx->post_id) as $key) { if (is_string($key) && !self::is_protected($key)) { $out[] = ['value' => $key, 'label' => $key]; } } return self::filter_options($out, $search); } public function render(array $settings, Context $ctx) { $key = isset($settings['key']) && is_string($settings['key']) ? trim($settings['key']) : ''; if ($ctx->post_id <= 0 || self::is_protected($key)) { return ''; } $value = get_post_meta($ctx->post_id, $key, true); return is_scalar($value) ? $value : self::field_value($value); } }