函数文档

rest_output_rsd()

💡 云策文档标注

概述

rest_output_rsd() 函数用于将 REST API URL 输出到 WordPress RSD 端点。它通过 get_rest_url() 获取 API 根 URL,并在非空时生成 XML 输出。

关键要点

  • 函数 rest_output_rsd() 在 WordPress 4.4.0 版本引入,位于 wp-includes/rest-api.php 文件中。
  • 它调用 get_rest_url() 获取 REST API 根 URL,如果为空则直接返回,否则输出包含 API URL 的 XML 标签。
  • 相关函数包括 get_rest_url() 用于获取 REST 端点 URL,esc_url() 用于 URL 清理和验证。

📄 原文内容

Adds the REST API URL to the WP RSD endpoint.

Description

See also

Source

function rest_output_rsd() {
$api_root = get_rest_url();

if ( empty( $api_root ) ) {
return;
}
?>
<api name="WP-API" blogID="1" preferred="false" apiLink="<?php echo esc_url( $api_root ); ?>" />
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api.php#L1024">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api.php#L1024-L1033">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/get_rest_url/">get_rest_url()</a><code>wp-includes/rest-api.php

Retrieves the URL to a REST endpoint on a site.

esc_url()wp-includes/formatting.php

Checks and cleans a URL.

Changelog

Version Description
4.4.0 Introduced.