函数文档

self_link()

💡 云策文档标注

概述

self_link() 函数用于以 XSS 安全的方式输出当前显示 feed 的链接。它通过应用过滤器并转义 URL 来确保安全性。

关键要点

  • self_link() 输出当前 feed 的链接,适用于 Atom 自引用元素。
  • 使用 esc_url() 和 apply_filters() 来防止 XSS 攻击并允许自定义链接。
  • 相关函数包括 get_self_link()、esc_url() 和 apply_filters()。

代码示例

function self_link() {
    /**
     * Filters the current feed URL.
     *
     * @since 3.6.0
     *
     * @see set_url_scheme()
     * @see wp_unslash()
     *
     * @param string $feed_link The link for the feed with set URL scheme.
     */
    echo esc_url( apply_filters( 'self_link', get_self_link() ) );
}

注意事项

  • 此函数从 WordPress 2.5.0 版本开始引入。
  • 输出前会应用 'self_link' 过滤器,允许开发者修改链接。

📄 原文内容

Displays the link for the currently displayed feed in a XSS safe way.

Description

Generate a correct link for the atom:self element.

Source

function self_link() {
	/**
	 * Filters the current feed URL.
	 *
	 * @since 3.6.0
	 *
	 * @see set_url_scheme()
	 * @see wp_unslash()
	 *
	 * @param string $feed_link The link for the feed with set URL scheme.
	 */
	echo esc_url( apply_filters( 'self_link', get_self_link() ) );
}

Hooks

apply_filters( ‘self_link’, string $feed_link )

Filters the current feed URL.

Changelog

Version Description
2.5.0 Introduced.