钩子文档

clean_url

💡 云策文档标注

概述

clean_url 是一个 WordPress 过滤器,用于对清理和转义后的 URL 字符串进行过滤,以便输出。它允许开发者修改 URL 的清理过程,支持不同的上下文参数。

关键要点

  • 过滤器名称:clean_url
  • 参数:$good_protocol_url(清理后的 URL)、$original_url(原始 URL)、$_context(上下文,如 'display')
  • 用途:在 URL 清理和转义后应用自定义过滤逻辑
  • 相关函数:esc_url() 用于检查和清理 URL
  • 引入版本:WordPress 2.3.0

注意事项

上下文参数 $_context 的可能值列表不完整,已知包括 'display' 和 'db',但官方文档未提供完整列表,esc_url() 也存在类似情况。


📄 原文内容

Filters a string cleaned and escaped for output as a URL.

Parameters

$good_protocol_urlstring
The cleaned URL to be returned.
$original_urlstring
The URL prior to cleaning.
$_contextstring
If 'display', replace ampersands and single quotes only.

Source

return apply_filters( 'clean_url', $good_protocol_url, $original_url, $_context );

Changelog

Version Description
2.3.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    It seems to be hard to find a complete list of the possible contexts; as far as I could determine, besides the ‘display’ context, there is also the ‘db’ context (which has its own set of encapsulating functions), but I couldn’t find a reference to the full list of contexts.

    (The same comment applies to esc_url() too, of course; only ‘display’ is mentioned there as well.)