_wp_credits_add_profile_link()
云策文档标注
概述
_wp_credits_add_profile_link() 是一个 WordPress 内部函数,用于生成贡献者 WordPress.org 个人资料页面的链接。它通过引用修改显示名称参数,并利用 esc_html() 进行 HTML 转义。
关键要点
- 函数名:_wp_credits_add_profile_link(),在 WordPress 3.2.0 版本引入。
- 参数:接受三个必需参数:$display_name(显示名称,引用传递)、$username(用户名)、$profiles(个人资料页面 URL)。
- 功能:将 $display_name 包装在带有个人资料链接的 HTML 锚标签中,并使用 esc_html() 确保安全性。
- 相关函数:涉及 esc_html() 用于 HTML 转义,esc_url() 用于 URL 清理。
代码示例
function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
$display_name = '<a href="' . esc_url( $profiles ) . '">' . esc_html( $display_name ) . '</a>';
}注意事项
- 此函数是内部函数,通常用于 WordPress 核心的贡献者列表生成,不建议在插件或主题中直接调用。
- 参数 $display_name 通过引用传递,调用后其值会被修改为包含链接的 HTML 字符串。
- 确保传入的 $profiles 参数是有效的 URL,函数内部使用 esc_url() 进行清理。
原文内容
Retrieves the link to a contributor’s WordPress.org profile page.
Parameters
$display_namestringrequired-
The contributor’s display name (passed by reference).
$usernamestringrequired-
The contributor’s username.
$profilesstringrequired-
URL to the contributor’s WordPress.org profile page.
Source
function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
$display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
}
Changelog
| Version | Description |
|---|---|
| 3.2.0 | Introduced. |