show_in_rest) { return self::$cache[$type] = []; } rest_get_server(); $controller = $object->get_rest_controller(); if (!$controller) { return self::$cache[$type] = []; } $properties = $controller->get_item_schema()['properties']['meta']['properties'] ?? []; $registered = array_merge(get_registered_meta_keys('post'), get_registered_meta_keys('post', $type)); $result = []; ksort($registered); foreach ($registered as $key => $value) { if (empty($value['show_in_rest'])) { continue; } $name = is_array($value['show_in_rest']) ? ($value['show_in_rest']['name'] ?? $key) : $key; if (preg_match('/(?:^|[_-])(password|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|nonce|author[_-]?email|user[_-]?email)(?:$|[_-])/i', $name)) { continue; } if (!isset($properties[$name]) || !in_array('view', $properties[$name]['context'] ?? ['view', 'edit'], true)) { continue; } $result[$name] = ['key' => $key, 'schema' => $properties[$name]]; } return self::$cache[$type] = $result; } public static function schema(string $type): array { $properties = []; foreach (self::fields($type) as $name => $value) { $properties[$name] = $value['schema']; } return ['type' => 'object', 'properties' => (object) $properties]; } public static function schemas(): array { $result = []; foreach (Chat4U_Content::types() as $type) { $result[$type] = self::schema($type); } return $result; } public static function record(int $id, string $type): array { $fields = self::fields($type); if (!$fields) { return []; } $object = get_post_type_object($type); $namespace = $object->rest_namespace ?: 'wp/v2'; $base = $object->rest_base ?: $type; $url = add_query_arg(['context' => 'view', '_fields' => 'id,meta'], get_rest_url(null, $namespace . '/' . $base . '/' . $id)); $present = []; foreach ($fields as $name => $value) { if (metadata_exists('post', $id, $value['key'])) { $present[] = $name; } } return ['public_meta_url' => $url, 'public_meta_schema' => self::schema($type), 'public_meta_present' => $present]; } }