Skip to Content
Menu

is_browser()

Compare the user’s browser version.

PHP April 1, 2021

Usage

PHP
nebula()->is_browser($browser, $version, $comparison)

Parameters

$browser
(Required) (String) The browser name
Default: None

Request or provide clarification »

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

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

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

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

    PHP
            public function is_browser($browser=null){
                $override = apply_filters('pre_nebula_is_browser', null, $browser);
                if ( isset($override) ){return $override;}
    
                //This only checks browser name
                if ( $this->get_browser() == strtolower($browser) ){
                    return true;
                }
    
                //Check User Agent Client Hints
                if ( isset($_SERVER['HTTP_SEC_CH_UA']) ){ //if Sec-CH-UA-Platform client hint
                    $ch_ua = strtolower($_SERVER['HTTP_SEC_CH_UA']);
    
                    if ( str_contains($ch_ua, strtolower($browser)) ){
                        return true;
                    }
                }
    
                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_is_browser', 'my_custom_is_browser', 10, 2); //The last integer must be 1 more than the actual parameters
    function my_custom_is_browser($null, $browser){ //$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_is_browser', '__return_false');