An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# User Agent for WP Bones

[![Latest Stable Version](https://poser.pugx.org/wpbones/useragent/v/stable?style=for-the-badge)](https://packagist.org/packages/wpbones/useragent)  
[![Latest Unstable Version](https://poser.pugx.org/wpbones/useragent/v/unstable?style=for-the-badge)](https://packagist.org/packages/wpbones/useragent)  
[![Total Downloads](https://poser.pugx.org/wpbones/useragent/downloads?style=for-the-badge)](https://packagist.org/packages/wpbones/useragent)  
[![License](https://poser.pugx.org/wpbones/useragent/license?style=for-the-badge)](https://packagist.org/packages/wpbones/useragent)  
[![Monthly Downloads](https://poser.pugx.org/wpbones/useragent/d/monthly?style=for-the-badge)](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')
// [...]
```