arraypress/wp-user-agent-utils
Composer 安装命令:
composer require arraypress/wp-user-agent-utils
包简介
A lean WordPress utility for browser detection, device recognition, and bot identification
关键字:
README 文档
README
A lean WordPress utility for browser detection, device recognition, and bot identification. Built for e-commerce analytics, responsive design, and conditional functionality with just the features you need.
Features
- 🎯 Focused API - Just 9 essential methods for user agent operations
- 🌐 Browser Detection - Identify Chrome, Firefox, Safari, Edge, and more
- 📱 Device Recognition - Mobile/desktop detection with
wp_is_mobile()fallback - 🤖 Bot Detection - Identify search engines and AI bots (2024/2025)
- 💻 OS Detection - Windows, macOS, iOS, Android, Linux
- 📊 E-commerce Ready - EDD-compatible formatted output
Requirements
- PHP 7.4 or later
- WordPress 5.0 or later
Installation
composer require arraypress/wp-user-agent-utils
Usage
Browser Detection
use ArrayPress\UserAgentUtils\UserAgent; // Get browser name $browser = UserAgent::get_browser(); // Returns: "Chrome", "Firefox", "Safari", "Edge", etc. // Check specific browser if ( UserAgent::is_browser( 'Chrome' ) ) { // Chrome-specific functionality } // Get operating system $os = UserAgent::get_os(); // Returns: "Windows", "macOS", "iOS", "Android", "Linux"
Device Detection
// Check device type (uses wp_is_mobile() when possible) if ( UserAgent::is_mobile() ) { // Mobile device } if ( UserAgent::is_desktop() ) { // Desktop device } // Get device type as string $device = UserAgent::get_device_type(); // Returns: "mobile", "desktop", "bot", or "unknown"
Bot Detection
// Check for bots/crawlers (includes 2024 AI bots) if ( UserAgent::is_bot() ) { // Skip analytics, serve cached content return; }
E-commerce Integration
// Get formatted string for storage (EDD-compatible) $formatted = UserAgent::get_formatted(); // Returns: "Chrome on Windows" or "Safari on iOS" // Store with order data $order_meta = [ 'user_agent' => UserAgent::get_formatted(), 'device_type' => UserAgent::get_device_type(), 'is_mobile' => UserAgent::is_mobile() ];
Common Use Cases
Analytics Tracking
function track_visitor() { // Skip bot traffic if ( UserAgent::is_bot() ) { return; } $visitor_data = [ 'browser' => UserAgent::get_browser(), 'os' => UserAgent::get_os(), 'device' => UserAgent::get_device_type(), 'formatted' => UserAgent::get_formatted() ]; // Log to database update_option( 'visitor_stats', $visitor_data ); } add_action( 'init', 'track_visitor' );
Conditional Asset Loading
function enqueue_device_assets() { // Mobile-specific JavaScript if ( UserAgent::is_mobile() ) { wp_enqueue_script( 'touch-events', 'js/touch.js' ); } // Browser-specific fixes if ( UserAgent::is_browser( 'Safari' ) ) { wp_enqueue_style( 'safari-fixes', 'css/safari.css' ); } } add_action( 'wp_enqueue_scripts', 'enqueue_device_assets' );
SugarCart Integration
function log_order_device_info( $order_id ) { $order = sugarcart_get_order( $order_id ); // Skip bot orders if ( UserAgent::is_bot() ) { $order->add_note( 'Bot order detected' ); return; } // Store device info $order->update_meta( 'browser_info', UserAgent::get_formatted() ); $order->update_meta( 'device_type', UserAgent::get_device_type() ); $order->update_meta( 'is_mobile', UserAgent::is_mobile() ); } add_action( 'sugarcart_order_completed', 'log_order_device_info' );
Bot Filtering
function handle_bot_traffic() { if ( ! UserAgent::is_bot() ) { return; } // Serve cached version for bots if ( $cached = wp_cache_get( 'page_cache' ) ) { echo $cached; exit; } } add_action( 'template_redirect', 'handle_bot_traffic' );
API Reference
| Method | Description | Returns |
|---|---|---|
get() |
Get current user agent string | string |
get_browser() |
Get browser name | ?string |
get_os() |
Get operating system | ?string |
is_mobile() |
Check if mobile device | bool |
is_desktop() |
Check if desktop | bool |
is_bot() |
Check if bot/crawler | bool |
get_device_type() |
Get device as string | string |
get_formatted() |
Get formatted for storage | string |
is_browser( $name ) |
Check specific browser | bool |
Supported Detection
Browsers
- Chrome (+ Mobile, iOS)
- Safari (+ Mobile)
- Firefox (+ iOS)
- Edge
- Opera
- Brave
- Samsung Browser
Operating Systems
- Windows (10, 11)
- macOS
- iOS
- Android
- Linux
Bots (2024/2025)
- Search engines (Google, Bing, DuckDuckGo)
- AI bots (GPTBot, ClaudeBot, ChatGPT)
- Social media (Facebook, Twitter)
- SEO tools (Semrush, Ahrefs)
Why This Library?
- Lean & Focused - Just 9 methods for real use cases
- WordPress Native - Uses
wp_is_mobile()and WP sanitization - E-commerce Ready - EDD-compatible formatting
- Modern Bot Detection - Updated for 2024/2025 AI bots
- No Version Bloat - Removed unreliable version detection
License
GPL-2.0-or-later
Support
arraypress/wp-user-agent-utils 适用场景与选型建议
arraypress/wp-user-agent-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「useragent」 「browser-detection」 「bot-detection」 「mobile-detection」 「arraypress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/wp-user-agent-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/wp-user-agent-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/wp-user-agent-utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Useragent sniffing library for PHP
Useragent sniffing library for PHP
Library to detect the browser and all its info (OS, Platform, ...)
The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.
Wrapper for global function in https://github.com/donatj/PhpUserAgent/
A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-01-17