PHPackages                             arraypress/wp-user-agent-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-user-agent-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-user-agent-utils
==============================

A lean WordPress utility for browser detection, device recognition, and bot identification

07PHP

Since Jan 17Pushed 5mo agoCompare

[ Source](https://github.com/arraypress/wp-user-agent-utils)[ Packagist](https://packagist.org/packages/arraypress/wp-user-agent-utils)[ RSS](/packages/arraypress-wp-user-agent-utils/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress UserAgent Utilities
=============================

[](#wordpress-useragent-utilities)

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
--------

[](#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
------------

[](#requirements)

- PHP 7.4 or later
- WordPress 5.0 or later

Installation
------------

[](#installation)

```
composer require arraypress/wp-user-agent-utils
```

Usage
-----

[](#usage)

### Browser Detection

[](#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

[](#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

[](#bot-detection)

```
// Check for bots/crawlers (includes 2024 AI bots)
if ( UserAgent::is_bot() ) {
    // Skip analytics, serve cached content
    return;
}
```

### E-commerce Integration

[](#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
----------------

[](#common-use-cases)

### Analytics Tracking

[](#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

[](#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

[](#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

[](#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
-------------

[](#api-reference)

MethodDescriptionReturns`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
-------------------

[](#supported-detection)

### Browsers

[](#browsers)

- Chrome (+ Mobile, iOS)
- Safari (+ Mobile)
- Firefox (+ iOS)
- Edge
- Opera
- Brave
- Samsung Browser

### Operating Systems

[](#operating-systems)

- Windows (10, 11)
- macOS
- iOS
- Android
- Linux

### Bots (2024/2025)

[](#bots-20242025)

- Search engines (Google, Bing, DuckDuckGo)
- AI bots (GPTBot, ClaudeBot, ChatGPT)
- Social media (Facebook, Twitter)
- SEO tools (Semrush, Ahrefs)

Why This Library?
-----------------

[](#why-this-library)

- **Lean &amp; 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
-------

[](#license)

GPL-2.0-or-later

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/wp-utils-useragent)
- [Issue Tracker](https://github.com/arraypress/wp-utils-useragent/issues)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance48

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (11 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-user-agent-utils/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-user-agent-utils/health.svg)](https://phpackages.com/packages/arraypress-wp-user-agent-utils)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
