钩子文档

rest_response_link_curies

💡 云策文档标注

概述

rest_response_link_curies 是一个 WordPress REST API 过滤器,用于注册额外的 CURIEs(紧凑 URI),以缩短关系 URI 并提高自定义关系的可用性。

关键要点

  • CURIEs 允许使用缩短版本的关系 URI,类似于 XML 命名空间,格式为 {name}:{rel}。
  • 注册 CURIE 需指定名称和 URI 模板,自动将完整 URI 关系转换为缩短形式。
  • 此过滤器可能影响向后兼容性,因为某些客户端可能无法正确解析缩短的关系。

代码示例

$additional = apply_filters( 'rest_response_link_curies', array() );

注意事项

添加新 CURIE 时需谨慎,因为不完善的客户端可能无法正确处理缩短的关系,可能导致兼容性问题。


📄 原文内容

Filters extra CURIEs available on REST API responses.

Description

CURIEs allow a shortened version of URI relations. This allows a more usable form for custom relations than using the full URI. These work similarly to how XML namespaces work.

Registered CURIES need to specify a name and URI template. This will automatically transform URI relations into their shortened version.
The shortened relation follows the format {name}:{rel}. {rel} in the URI template will be replaced with the {rel} part of the shortened relation.

For example, a CURIE with name example and URI template https://w.org/{rel} would transform a https://w.org/term relation into example:term.

Well-behaved clients should expand and normalize these back to their full URI relation, however some naive clients may not resolve these correctly, so adding new CURIEs may break backward compatibility.

Parameters

$additionalarray
Additional CURIEs to register with the REST API.

Source

$additional = apply_filters( 'rest_response_link_curies', array() );

Changelog

Version Description
4.5.0 Introduced.