comment_author_email_link()
云策文档标注
概述
comment_author_email_link() 函数用于显示当前评论作者的 HTML 电子邮件链接,支持自定义链接文本和前后 HTML 内容。开发者需注意保护电子邮件地址,防止被爬虫捕获。
关键要点
- 函数输出当前评论作者的电子邮件链接,基于 get_comment_author_email_link() 返回结果。
- 参数包括 $link_text(链接文本)、$before(链接前内容)、$after(链接后内容)和 $comment(评论 ID 或 WP_Comment 对象)。
- 安全性考虑:应避免在网站上以原始形式显示电子邮件地址,以保护评论者隐私。
- 自 WordPress 4.6.0 版本起,新增 $comment 参数,允许指定评论。
代码示例
comment_author_email_link( 'Email Comment Author', ' > ', ' < ' );注意事项
使用此函数时,需确保电子邮件地址不被恶意爬虫获取,建议结合反垃圾邮件措施。
原文内容
Displays the HTML email link to the author of the current comment.
Description
Care should be taken to protect the email address and assure that email harvesters do not capture your commenter’s email address. Most assume that their email address will not appear in raw form on the site. Doing so will enable anyone, including those that people don’t want to get the email address and use it for their own means good and bad.
Parameters
$link_textstringoptional-
Text to display instead of the comment author’s email address.
Default empty. $beforestringoptional-
Text or HTML to display before the email link. Default empty.
$afterstringoptional-
Text or HTML to display after the email link. Default empty.
$commentint|WP_Commentoptional-
Comment ID or WP_Comment object. Default is the current comment.
Default:
null
Source
function comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
$link = get_comment_author_email_link( $link_text, $before, $after, $comment );
if ( $link ) {
echo $link;
}
}
Skip to note 2 content
Codex
Default Usage
Email:Displays comment author’s email link as text string Email Comment Author and adds arrows before and after the link to style it.
comment_author_email_link( 'Email Comment Author', ' > ', ' < ' );