Skip to Content

get_device()

Get the requested information of the user’s device.

PHP May 3, 2017

Usage

PHP
nebula()->get_device($info)

Parameters

$info
(Optional) (String) The data to return
Default: model

Parameter Notes

$info string can include “full”, “brand”, “make”, “model”, “version”, “name”, “type”, “formfactor”, and variants of those.

Request or provide clarification »

Additional Notes

Note: This function requires the Device Detection Nebula option to be enabled or only basic detection happens with WordPress core.

Source File

Located in /libs/Utilities/Device.php on line 164.

1 Hook

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Filters
"pre_nebula_get_device"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

PHP
        public function get_device($info='model'){
            $override = apply_filters('pre_nebula_get_device', null, $info);
            if ( isset($override) ){return $override;}

            if ( $this->get_option('device_detection') ){
                $info = str_replace(' ', '', $info);
                switch ( strtolower($info) ){
                    case 'full':
                        $brand_name = $this->device->getBrandName();
                        $model = $this->device->getModel();
                        if ( !empty($brand_name) && !empty($model) ){
                            return $brand_name . ' ' . $model;
                        }
                        return false;
                    case 'brand':
                    case 'brandname':
                    case 'make':
                        return $this->device->getBrandName();
                    case 'model':
                    case 'version':
                    case 'name':
                        return $this->device->getModel();
                    case 'type':
                        return $this->device->getDeviceName();
                    case 'formfactor':
                        if ( $this->is_mobile() ){
                            return 'mobile';
                        } elseif ( $this->is_tablet() ){
                            return 'tablet';
                        }
                        return 'desktop';
                    default:
                        return false;
                }
            }

            global $is_iphone;
            $info = str_replace(' ', '', $info);
            switch ( strtolower($info) ){
                case 'brand':
                case 'brandname':
                case 'make':
                case 'model':
                case 'name':
                case 'type':
                    if ( $is_iphone ){
                        return 'iphone';
                    }
                    break;
                case 'formfactor':
                    if ( wp_is_mobile() || $is_iphone ){
                        return 'mobile';
                    }
                    return 'desktop';
                default:
                    return false;
            }
        }

Override

To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

PHP
add_filter('pre_nebula_get_device', 'my_custom_get_device', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_get_device($null, $info){ //$null is required, but can be ignored
    //Write your own code here

    return true; //Return true to prevent the original function from running afterwords
}

You can completely disable this PHP function with a single line actions:

PHP
 add_filter('pre_nebula_get_device', '__return_false');