https://github.com/wpbones/useragent
An useful version of mobile detect library for wpbones
https://github.com/wpbones/useragent
Last synced: about 2 months ago
JSON representation
An useful version of mobile detect library for wpbones
- Host: GitHub
- URL: https://github.com/wpbones/useragent
- Owner: wpbones
- License: bsd-2-clause
- Created: 2019-01-31T15:45:31.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-05-27T05:47:51.000Z (11 months ago)
- Last Synced: 2026-01-15T22:20:45.549Z (3 months ago)
- Language: PHP
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# User Agent for WP Bones
[](https://packagist.org/packages/wpbones/useragent)
[](https://packagist.org/packages/wpbones/useragent)
[](https://packagist.org/packages/wpbones/useragent)
[](https://packagist.org/packages/wpbones/useragent)
[](https://packagist.org/packages/wpbones/useragent)
An useful wrapper for [Mobile Detect](https://github.com/serbanghita/Mobile-Detect) to detect mobile devices for WP Bones.
## Requirements
This package works with a WordPress plugin written with [WP Bones framework library](https://github.com/wpbones/WPBones).
## Installation
You can install third party packages by using:
```sh copy
php bones require wpbones/useragent
```
I advise to use this command instead of `composer require` because doing this an automatic renaming will done.
You can use composer to install this package:
```sh copy
composer require wpbones/useragent
```
You may also to add `"wpbones/useragent": "^1.0"` in the `composer.json` file of your plugin:
```json copy filename="composer.json" {4}
"require": {
"php": ">=7.4",
"wpbones/wpbones": "~0.8",
"wpbones/useragent": "~1.0"
},
```
and run
```sh copy
composer install
```
## How to
You will be able to use `wpbones_user_agent()` function to get an instance of Mobile Detect.
```php copy
if(wpbones_user_agent()->isMobile()) {
echo "You're by Mobile";
} else {
echo "You're by Desktop";
}
```
### Sample
```php copy
// Basic detection.
wpbones_user_agent()->isMobile();
wpbones_user_agent()->isTablet();
// Magic methods.
wpbones_user_agent()->isIphone();
wpbones_user_agent()->isSamsung();
// [...]
// Alternative to magic methods.
wpbones_user_agent()->is('iphone');
// Find the version of component.
wpbones_user_agent()->version('Android');
```
You may also
```php copy
// Any mobile device (phones or tablets).
if ( wpbones_user_agent()->isMobile() ) {
}
// Any tablet device.
if( wpbones_user_agent()->isTablet() ){
}
// Exclude tablets.
if( wpbones_user_agent()->isMobile() && !wpbones_user_agent()->isTablet() ){
}
// Check for a specific platform with the help of the magic methods:
if( wpbones_user_agent()->isiOS() ){
}
if( wpbones_user_agent()->isAndroidOS() ){
}
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
wpbones_user_agent()->is('Chrome')
wpbones_user_agent()->is('iOS')
wpbones_user_agent()->is('UCBrowser')
wpbones_user_agent()->is('Opera')
// [...]
```