函数文档

comment_author_IP()

💡 云策文档标注

概述

comment_author_IP() 是一个 WordPress 模板标签,用于直接输出当前评论作者的 IP 地址。它基于 get_comment_author_IP() 函数,并自动进行 HTML 转义以确保安全性。

关键要点

  • 功能:显示指定评论作者的 IP 地址,默认处理当前评论。
  • 参数:$comment_id(可选),可接受整数评论 ID 或 WP_Comment 对象,默认值为 0 表示当前评论。
  • 安全性:使用 esc_html() 对输出进行 HTML 转义,防止 XSS 攻击。
  • 版本变化:从 WordPress 4.4.0 开始,$comment_id 参数支持 WP_Comment 对象。

代码示例

function comment_author_IP( $comment_id = 0 ) {
    echo esc_html( get_comment_author_IP( $comment_id ) );
}

📄 原文内容

Displays the IP address of the author of the current comment.

Parameters

$comment_idint|WP_Commentoptional
WP_Comment or the ID of the comment for which to print the author’s IP address.
Default current comment.

Source

function comment_author_IP( $comment_id = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	echo esc_html( get_comment_author_IP( $comment_id ) );
}

Changelog

Version Description
4.4.0 Added the ability for $comment_id to also accept a WP_Comment object.
0.71 Introduced.

User Contributed Notes