前言
获取评论用户IP属地依赖wordpress保存的ip地址,然后利用接口获取该用户所在地区!非常简单,看看效果图!
效果图
操作步骤
将下方代码添加到functions.php文件里(/zibll/functions.php)
//获取地址
function xypro_user_ip($user_ip){
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://v2.ikimg.cn/API/IP/api.php?domian=".$user_ip,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
),
));
$url = curl_exec($ch);
$a = json_decode($url,true);
curl_close($ch);
$dizhi = $a['country'];
$dizhi = mb_substr($dizhi, 0, 3, 'utf-8');
return $dizhi;
//获取结束
}
- 这里需要到zib-comments-list.php修改(在zibll/inc/functions),先搜索$replyText_html跳到第二个,然后粘贴下方的代码覆盖它即可!
-
没有回复内容