get_comment_author_email_link

函数
get_comment_author_email_link ( $linktext = '', $before = '', $after = '', $comment = null )
参数
  • (string) $linktext Optional. Text to display instead of the comment author's email address. Default empty.
    Required:
    Default: (empty)
  • (string) $before Optional. Text or HTML to display before the email link. Default empty.
    Required:
    Default: (empty)
  • (string) $after Optional. Text or HTML to display after the email link. Default empty.
    Required:
    Default: (empty)
  • (int|WP_Comment) $comment Optional. Comment ID or WP_Comment object. Default is the current comment.
    Required:
    Default: null
返回值
  • (string) HTML markup for the comment author email link. By default, the email address is obfuscated via the {@see 'comment_email'} filter with antispambot().
定义位置
相关方法
comment_author_email_linkget_comment_author_emailget_comment_author_url_linkget_comment_author_linkcomment_author_email
引入
2.7.0
弃用
-

get_comment_author_email_link: 这个函数返回评论作者的电子邮件地址的HTML链接。它需要一个参数,即$comment_ID,它是你想获取作者电子邮件链接的评论的ID。

返回HTML电子邮件链接给当前评论的作者。

应该注意保护电子邮件地址,并确保电子邮件收集者不会捕获你的评论者的电子邮件地址。大多数人认为他们的电子邮件地址不会以原始形式出现在网站上。这样做将使任何人,包括那些人们不希望得到的电子邮件地址,并为他们自己的手段好和坏使用。

function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
	$comment = get_comment( $comment );

	/**
	 * Filters the comment author's email for display.
	 *
	 * Care should be taken to protect the email address and assure that email
	 * harvesters do not capture your commenter's email address.
	 *
	 * @since 1.2.0
	 * @since 4.1.0 The `$comment` parameter was added.
	 *
	 * @param string     $comment_author_email The comment author's email address.
	 * @param WP_Comment $comment              The comment object.
	 */
	$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );

	if ( ( ! empty( $email ) ) && ( '@' !== $email ) ) {
		$display = ( '' !== $linktext ) ? $linktext : $email;
		$return  = $before;
		$return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
		$return .= $after;
		return $return;
	} else {
		return '';
	}
}

常见问题

FAQs
查看更多 >