{"id":19387903,"url":"https://github.com/helloxz/wp-ip-query","last_synced_at":"2026-03-02T17:05:46.031Z","repository":{"id":79888563,"uuid":"59270823","full_name":"helloxz/wp-ip-query","owner":"helloxz","description":"一键查询wordpress访客IP归属地","archived":false,"fork":false,"pushed_at":"2016-05-20T06:46:47.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-07T08:36:33.356Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/helloxz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-20T06:33:57.000Z","updated_at":"2019-02-15T20:51:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"969173ba-6361-4f09-a3e0-610d999b78b5","html_url":"https://github.com/helloxz/wp-ip-query","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloxz%2Fwp-ip-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloxz%2Fwp-ip-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloxz%2Fwp-ip-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloxz%2Fwp-ip-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helloxz","download_url":"https://codeload.github.com/helloxz/wp-ip-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240540548,"owners_count":19817791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T10:11:04.049Z","updated_at":"2025-11-16T17:03:08.237Z","avatar_url":"https://github.com/helloxz.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# wp-ip-query\n一键查询wordpress访客IP归属地\n\nWordPress后台评论功能会记录每一位访客IP地址，但是如果我们希望获取访客IP的具体归属地，虽然可以通过第三方IP查询工具手动输入IP查询，但是这样略显不便，于是小z博客利用淘宝IP接口对WordPress后台进行了略微的改动，使其可以一键查询访客IP的归属地。\n\n### 引入Jquery库，并加载javascript函数\n修改\u003ccode\u003e/wp-admin/admin-footer.php\u003c/code\u003e将下面的代码添加到\u003ccode\u003ebody\u003c/code\u003e之前。\n``` javascript\n\u003cscript src = \"https://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n\tfunction ipquery(ip,num) {\n\tvar ip = ip;\n \n\t$.get('./ip-query.php',{ip:ip},function(data,status){\n\t\t\tvar address = new Function('return' + data)();\n\t\t\tvar guojia = address['data']['country'];\n\t\t\tvar sheng = address['data']['region'];\n\t\t\tvar shi = address['data']['city'];\n\t\t\tvar isp = address['data']['isp'];\n\t\t\tvar ip_add = guojia + ' ' + sheng + ' ' + shi + ' ' + isp;\n\t\t\tnum = '#' + num;\n\t\t\t$(num).html(ip_add);\n\t\t});\n\t}\n\u003c/script\u003e\n```\n\n### 添加ip-query接口查询文件\n将下面的代码另存为:\u003ccode\u003eip-query.php\u003c/code\u003e并上传到\u003ccode\u003e/wp-admin/\u003c/code\u003e目录下。\n``` php\n\u003c?php\n\t$ip = $_GET['ip'];\t\t\t//获取IP\n\t//通过淘宝IP接口查询IP归属地\n\t$get_ipquery = \"http://ip.taobao.com//service/getIpInfo.php?ip=$ip\";\n \n\t//CURL\n\t$ch = curl_init();\n\tcurl_setopt($ch,CURLOPT_URL,$get_ipquery);\n\tcurl_setopt($ch,CURLOPT_RETURNTRANSFER,1);\n\tcurl_setopt($ch,CURLOPT_HEADER,0);\n \n\t$content = curl_exec($ch);\n \n\tcurl_close($ch);\n \n \n\techo $content;\n?\u003e\n```\n\n### 修改wordpress后台功能\n找到\u003ccode\u003ewp-admin/includes/class-wp-comments-list-table.php\u003c/code\u003e这个文件，搜索关键词\u003ccode\u003eget_comment_author_IP\u003c/code\u003e在这句代码：\u003ccode\u003eprintf( '\u003ca href=\"%s\"\u003e%s\u003c/a\u003e', esc_url( $author_ip_url ), $author_ip );\u003c/code\u003e之后添加如下代码：\n``` php\n$num = 'abc'.rand(1000,9999);\n\t\t\t\techo \" | \u003ca href = 'javascript:;' onclick = 'return ipquery(\\\"$author_ip\\\",\\\"$num\\\");'\u003e查询\u003c/a\u003e\";\n\t\t\t\techo \"\u003cdiv id ='$num'\u003e\u003c/div\u003e\";\n```\n\n### 最后的效果\n![](https://nzzv57zo9.qnssl.com/wp-content/uploads/2016/05/ip_query.jpg)\n\n详细说明可以参考我的博客：\u003chttps://www.xiaoz.me/archives/6987\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelloxz%2Fwp-ip-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelloxz%2Fwp-ip-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelloxz%2Fwp-ip-query/lists"}