要在WordPress评论部分显示评论者的IP地址和操作平台信息,可以通过以下代码实现:// 在评论部分显示评论者的IP地址和操作平台信息 function show_commenter_ip_and...
要在WordPress评论部分显示评论者的IP地址和操作平台信息,可以通过以下代码实现:
// 在评论部分显示评论者的IP地址和操作平台信息
function show_commenter_ip_and_platform($comment_text) {
$comment_id = get_comment_ID();
$comment = get_comment($comment_id);
$commenter_ip = $comment->comment_author_IP;
$commenter_agent = $comment->comment_agent;
$platform = '';
if (preg_match('/Windows/', $commenter_agent)) {
$platform = 'Windows';
} elseif (preg_match('/Mac/', $commenter_agent)) {
$platform = 'Mac';
} elseif (preg_match('/Linux/', $commenter_agent)) {
$platform = 'Linux';
} elseif (preg_match('/iPhone/', $commenter_agent)) {
$platform = 'iPhone';
} elseif (preg_match('/iPad/', $commenter_agent)) {
$platform = 'iPad';
} elseif (preg_match('/Android/', $commenter_agent)) {
$platform = 'Android';
} else {
$platform = 'Unknown';
}
$comment_text .= '<p>IP地址:' . $commenter_ip . '</p>';
$comment_text .= '<p>操作平台:' . $platform . '</p>';
return $comment_text;
}
add_filter('comment_text', 'show_commenter_ip_and_platform');将上述代码添加到主题的functions.php文件中即可。这样,评论部分将会显示评论者的IP地址和操作平台信息。