Skip to Content

get_browser()

Returns the requested information of the user’s browser (client).

PHP May 3, 2017

Usage

PHP
nebula()->get_browser($info)

Parameters

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

Parameter Notes

$info string can be “full”, “name”, “browser”, “client”, “version”, “engine”, and “type”.

Request or provide clarification »

Additional Notes

This function has the alias get_client().

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

2 Hooks

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_browser"
"nebula_get_browser"
Need a new filter hook? Request one here.

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

PHP
        public function get_browser($info='name'){
            $override = apply_filters('pre_nebula_get_browser', null, $info);
            if ( isset($override) ){return $override;}

            //Hook in here to add custom checks to get_browser() calls
            $additional_checks = apply_filters('nebula_get_browser', false, $info);
            if ( !empty($additional_checks) ){
                return $additional_checks;
            }

            if ( $this->get_option('device_detection') ){
                $client = $this->device->getClient();
                if ( !empty($client) ){
                    switch ( strtolower($info) ){
                        case 'full':
                            return $client['name'] . ' ' . $client['version'];
                        case 'name':
                        case 'browser':
                        case 'client':
                            return $client['name'];
                        case 'version':
                            return $client['version'];
                        case 'engine':
                            return $client['engine'];
                        case 'type':
                            return $client['type'];
                        default:
                            return false;
                    }
                }
            }

            global $is_gecko, $is_IE, $is_opera, $is_safari, $is_chrome;
            switch ( strtolower($info) ){
                case 'full':
                case 'name':
                case 'browser':
                case 'client':
                    if ( $is_IE ){return 'internet explorer';}
                    elseif ( $is_opera ){return 'opera';}
                    elseif ( $is_safari ){return 'safari';}
                    elseif ( $is_chrome ){return 'chrome';}
                    return false;
                case 'engine':
                    if ( $is_gecko ){return 'gecko';}
                    elseif ( $is_safari ){return 'webkit';}
                    elseif ( $is_IE ){return 'trident';}
                    return false;
                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_browser', 'my_custom_get_browser', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_get_browser($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_browser', '__return_false');