logo
0
0
WeChat Login

WP-UserAgent

Contributors: obaby
Donate Link: https://oba.by
Tags: useragent, user-agent, user agent, web, browser, web browser, operating system, platform, os, mac, apple, windows, win, linux, phone
Requires at least: 2.0
Tested up to: 6.3
Stable tag: 16.06.99

IP 查询方式(归属地)

插件支持四种 IP 查询方式,可在 设置 → WP-UserAgent 中选择:

方式说明
IP2Location使用 IP2Location 数据库(需将 BIN 文件放入 show-useragent/ip2location_db/db/),依赖 Composer
CZDB使用纯真 CZDB 数据库(需授权与 db 文件放入 show-useragent/czdb/db/),依赖 Composer
ip2region使用 ip2region xdb(仅内置 ip2reginapi,不依赖 Composer)。需将 xdb 文件放入 show-useragent/ip2region_db/,文件名:ip2region_v4.xdbip2region_v6.xdb
纯真QQWRY使用 qqwry_api(qqwry.dat + ipv6wry.db),无需 Composer。数据文件放入 show-useragent/qqwry_api/ipdata/

选择 ip2region纯真QQWRY 时不会加载 vendor/autoload.php。若选择 IP2Location 或 CZDB 时 vendor 加载失败,插件会自动回退为 ip2region 模式,避免站点白屏。

Description

WP-UserAgent is a simple plugin that allows you to display details about a computer's operating system or web browser that your visitors comment from.

It uses the comment->agent property to access the User-Agent string. Through a series of regular expressions, this plugin is able to detect the operating system and browser which can be integrated in comments or placed in custom places through your template(s).

I'm adding new web browsers and operating systems frequently, as well as updating and optimizing the source code. Your feedback is very important, new features have been added by request, so if there's something you would like to see in WP-UserAgent, leave a comment, and I'll see what I can do.

WP-UserAgent was written with Geany - http://www.geany.org/
Images created with The Gimp - http://www.gimp.org/

注意:

  • 使用 CZDB 时:若更新替换纯真数据库,请同步更新 show-useragent/ip2c-text.php 中的 $key = 'n2pf2+PrE1y9I55MjdpLpg==';
  • 使用 ip2region 时:将 xdb 文件放入 show-useragent/ip2region_db/ip2region_v4.xdbip2region_v6.xdb),无需 Composer。

Installation

  1. Upload the "wp-useragent" folder to /wp-contents/plugins/

  2. Login to your WordPress Admin menu, go to Plugins, and activate it.

  3. In your WordPress Admin menu, you will find a new menu under Settings called WP-UserAgent. There you can choose the displayed icons size, and select where to display the plugin. There are three options for displaying the plugin:

    • Before the comment text. User's WebBrowser and OS will be displayed before comment text.

    • After the comment text. User's WebBrowser and OS will be displayed after comment text.

    • Custom (Advanced). You can specify the location using the wpua_custom_output() function inside the comments loop in your template (Generally in comments.php).

      Example:

      <?php foreach ($comments as $comment) : ?> <cite><?php comment_author_link() ?></cite> <?php wpua_custom_output(); ?> says: <?php comment_text() ?>

    CAUTION: If you select "Custom" and don't use <?php wpua_custom_output(); ?> in your template, you won't get the information displayed.

Other options include the text to use when displaying the user's web browser and operating system as well as whether or not to show the full User-Agent string.

Frequently Asked Questions

Why is my Web Browser or Operating System not detected?

The most likely answer is that your web browser is not using an identifiable user agent string. If your web browser isn't providing the Browser name or Operating System name in the user agent, then this plugin can't detect. If you think you've found an error with this plugin, please reach out to me in the Support section or leave a comment on the plugin homepage.

Why doesn't this plugin support Nationality flags or IP2Geolocation?

This is a commonly requested feature which I'm currently looking into. At this point in time I do not have an ETA on if/when that functionality will be available.

How can I help?

You can help in a number of ways:

  1. If you find a browser that's not being detected or a bug/issue, report it!
  2. Speak another language? Help me translate this plugin!

If you have any other questions, please don't hesitate to ask me! The easiest way to ask me a question, comment or suggest something is to post it in the comments on the plugin homepage.

Screenshots

Screenshots and live examples are also available at the plugin home page.

  1. Example of web browser and operating system detection displayed by WP-UserAgent
  2. Screenshot of the plugin's Settings page

Features

  • Detects most web browsers and popular operative systems (if you find one missing, please let me know!)
  • Shows web browser and operating system icons, names, and a link to their homepages (this will be customizable in future versions).
  • Shows web browser and operating system in the Admin comments management page (unless you're using "custom" option).
  • Customizable, has its own Options Page where you can change the size of the web browser and operating system icons, where you want it to be displayed, and a few other options.
  • Option to only display web browser and operating system info in Admin section
  • Updated frequently to further extend web browser and operating system detection as well as source code improvements.
  • Published under GPLv3

Some of you may compare this to another well-known plugin named browsersniff. WP-UserAgent is a heavily modified and improved version of UserAgent-Spy, with several improvements over browsersniff also:

  • Easy standard installation, just upload to wp-plugins and activate it.
  • Customizable options.
  • No basic knowledge of PHP or editing WordPress templates required.
  • Published under GPLv3.

Changelog

v16.06.99

  • 版本号更新至 16.06.99
  • 新增 纯真QQWRY IP 查询方式(qqwry_api:qqwry.dat / ipv6wry.db),无需 Composer
  • 新增 显示协议类型 选项:在国旗与国家文本后、IP 地址前显示 IPv4/IPv6 图标(img/ipv4.png、ipv6.png)
  • QQWRY(IPv4/IpLocation、IPv6/ipdbv6)与 ip2region(xdb)返回完整字段,支持国旗与完整归属地显示
  • 图标样式统一:IP 版本图标与 IP 地址图标使用与浏览器/系统图标相同的 vertical-align 等样式

v16.03.55 (2026-02-07)

  • ip2region 仅使用 ip2reginapi(xdb):不再依赖 Composer 的 zoujingli/ip2region,选择 ip2region 时不加载 vendor,避免服务器上缺失或大小写导致的致命错误
  • IP 查询方式:设置页可选 IP2Location、CZDB、ip2region;ip2region 需将 xdb 文件放入 show-useragent/ip2region_db/(ip2region_v4.xdb、ip2region_v6.xdb)
  • vendor 加载失败时自动回退:若选择 IP2Location 或 CZDB 时 vendor/autoload 加载失败(如未执行 composer update),自动切换为 ip2region 模式,避免整站白屏
  • composer.json:移除 zoujingli/ip2region 依赖;使用 IP2Location 或 CZDB 时请在 show-useragent 目录执行 composer update 后部署
  • 文档:README 增加 IP 查询方式说明与 ip2region 数据库路径

v16.01.01

  • 集成 IP2Location PHP 模块支持
  • 添加 IP 查询方式选择选项(可在插件设置中选择 IP2Location 或 CZDB)
  • 支持从 WordPress 后台设置页面选择 IP 查询方式
  • 实现自动回退机制:如果 IP2Location 模块未安装,自动使用 CZDB 作为备用
  • 优化 IP 查询代码,支持双语国家名称(中文/英文)
  • 添加 getCountryCodeFromIP() 函数,可直接从 IP 获取国家代码
  • 添加中国省份和城市名称翻译功能:当 IP 地址属于中国时,自动将省份(regionName)和城市(cityName)从英文翻译为中文
  • 包含所有34个省级行政区和200+个主要城市的中英文对照表
  • 更新版本号至 16.01.01

v15.01.01

  • 替换本地IP归属地查询数据库为纯真CZDB格式
  • 替换IPv6归属地查询,替换为本地数据库,去掉查询服务器配置功能
  • 鉴于纯真数据库需要授权码,需要去 https://cz88.com/geo-public 获取授权密钥以及数据库文件
  • 密钥配置文件,ip2c-text.php $key = 'n2pf2******************pg==';
  • 数据库下载之后放入 show-useragent\czdb\db 目录下,文件名分别为: cz88_public_v4.czdb cz88_public_v6.czdb

v13.01.01

  • 替换本地ip2country查询逻辑,改成接口查询
  • 增加ip转国家地址配置功能
  • IPv6模式下,地址显示从Unknow改为未知地址
  • 可用查询服务器:
    1. http://43.156.122.199:8080/getIpInfo?addr=114.114.1.1 配置路径填写:http://43.156.122.199:8080/getIpInfo?addr=
    2. https://api.country.is/162.245.238.69 配置路径填写:https://api.country.is/
  • 说明:https请求需要配置php https模块,否则会失败,如果失败请使用我提供的免费接口,或者参考这个项目自己部署查询服务:https://github.com/realchandan/Ip-geo-API

v12.02.01

  • 替换部分国旗图标为svg
  • 使用24像素图片替换16像素图片(限制图片尺寸)
  • 更新了部分os下的图标(原有的16*16像素的图标太落伍了,不清晰)
  • 更新了IP地址的图标

v1.1.8

  • Fixed WP Hook bug introduced by upgrade to WP 5.5+

v1.1.7

  • Added Microsoft Edge browser detection

v1.1.6

  • Fix detection of UC Browser (props: kissshot)

v1.1.5

  • Fix for comments not appearing when replying via admin comments section (props: ebteb)

v1.1.4

  • Fix incorrect/missing image for Android WebView (props: kissshot)

v1.1.3

  • Added MIUI Browser detection (props: Shensven)

v1.1.2

  • Fixed QQ Browser detection (props: Shensven)

v1.1.1

  • Added detection for WebView for Android (based on Chromium)
  • Added detection for Min Browser

v1.1.0

  • Added detection for Chrome on iOS
  • Minor fix: Adjust live preview as user types into input fields (as opposed to when the user changes focus out of the text field)

v1.0.12

  • Added option to adjust how version numbers are shown: Full (previous appearance, ex. 'Opera 10.52'), Simple (ex. 'Opera 10'), off (ex. 'Opera')
  • Cleaned up web browser version parsing (simplified pretty dramatically)
  • Cleaned up os/device version parsing and architecture parsing (x64)

v1.0.11

  • Added text domain to enable user contributed language translations (popular request: all options and text for this plugin should now be translatable)!
  • Added quick button/link to translation page (hopefully this encourages more people to contribute!)
  • Ran all the png images through optimization again minimize bandwidth usage (minor filesize improvements on 11 icons)
  • Added plugin icon for a little more flair
  • Added frequently asked questions/answers to readme
  • Added screenshot assets

v1.0.10

  • Fix issue with custom output layout (Support Forum)
  • Updated Windows icons with higher resolution and more accurate replacements

v1.0.9

  • Fix Windows Phone 8.1 detection (Support Forum)
  • Fixed Compatibility for the wpDiscuz plugin - WordPress Comments (Support Thread)
  • WP-UserAgent output is now wrapped by a div with classname "wp-useragent". This should make it much easier for those of you wishing to apply your own CSS to adjust the appearance on your site.
  • Improved settings page with cleaner layout and improved comment preview section.
  • Simplified some option descriptions.
  • Reset default options button now available.
  • Quick links at the top of the page for Plugin Homepage, Support, Changelog.
  • Removed get_currentuserinfo() call which was deprecated in Wordpress 4.5+
  • Refactored codebase to simplify maintaince of this plugin, general cleanup and reduced duplicate code.
  • DEPRECATED custom output function 'useragent_output_custom()'. Please use 'wpua_custom_output()' instead.
  • Added extra layer of security for escaping user input
  • Updated database schema and migrate settings automatically
  • Updated plugin options to disable autoloading (removes unnecessary memory usage)
  • Added database cleanup on uninstall

v1.0.8

  • Added option to display User Agent information in comments only in the Admin Section

v1.0.7

  • Added detection for Microsoft Edge, Seznam.cz, Coc Coc, Google Search App, WebPositive, Vivaldi, luakit, wOSBrowser, Puffin, NetFront Life, Ninesky, Palm WebPro browsers.
  • Optimized/reduced filesize of 31 images
  • Added detection for Windows Phone 10
  • Updated Windows 10 detection
  • Cleaned up syntax

v1.0.6

  • Fixed XSS security vulnerability

v1.0.5

  • Added height and width attributes to icons to fix an issue with 'Simple Lazyload' (props: Yu)

v1.0.4

  • Fixed error detecting Links browser version.
  • Fixed an error detecting x64 versions of Windows.
  • Added detection for Nintendo 3DS device, Microsoft Xbox, Xbox 360, Xbox One
  • Added detection for Windows 10
  • Added detection for 3DS Browser, ANT Fresco, Aviator, Baidu Spark, Espial TV Browser, IceDragon, Kinza, LG Web Browser, MxNitro, Polarity, Rambler browser, Roccat browser, Superbird, Tesla Car Browser, Waterfox, Web Explorer, YRC Weblink

v1.0.3

  • Fixed detection of IE11 (props: G's)
  • Fixed detection of Windows 8.1 (props: JayXon)
  • Fixed detection of Opera 14 for Android and Opera 15+ for Desktop (props: Rafae)
  • Fixed an issue with Ubuntu version detection.
  • Added detection for Amigo, Coast, CoRom, DPlus, ONE Browser, Otter, Perk, PS4 Web Browser and Ubuntu Web Browser.
  • Added detection for PlayStation 4, Ubuntu Touch (Mobile and Tablet).

v1.0.2

  • Fixed incorrect Rekonq browser icon.
  • Added detection for Nintendo Wii U.
  • Added detection for Nintendo Browser.
  • Fixed missing IE10 icons (props: Ray)

v1.0.1

  • Added detection for D+ browser, Internet Explorer 10, Amazon Silk, QQbrowser, Yandex.Browser, Beamrise.
  • Added detection for x64 version of Windows Server 2003.
  • Added detection for the Playstation Vita.

v1.0.0

  • Added detection for Barca, SubStream, SlimBoat, zBrowser, Ryouko browsers.
  • Fixed Chrome detection on Android (props: JayXon)
  • Refactored code for easier maintenance.
  • Release v1.0.0!!!! (w00t!)

TO-DO

  • Replace png icons with svg for crisp scalable vector graphics
  • Update settings page implementation to remove deprecated unregistered options warning.
  • Investigate adding IP Geolocation/Nationality flags (popular request)
  • New web browsers, devices and operating systems are always welcome.

Upgrade Notice

v1.1.8

  • Fixed WP Hook bug introduced by upgrade to WP 5.5+

About

加强版评论UA显示插件,支持显示国家以及当前用户归属地以及IP地址。

Language
PHP100%
HTML0%