Skip to Content
Menu

get_os()

Get the user’s Operating System.

PHP April 1, 2021

Usage

PHP
nebula()->get_os($info)

Parameters

$info
(Optional) (String) What data to return
Default: "full"

Parameter Notes

$info can be “full”, “name”, or “version”.

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

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

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

    PHP
            public function get_os($info='name'){
                $override = apply_filters('pre_nebula_get_os', null, $info);
                if ( isset($override) ){return $override;}
    
                //Check User Agent Client Hints
                if ( isset($_SERVER['HTTP_SEC_CH_UA_PLATFORM']) ){ //if Sec-CH-UA-Platform client hint
                    return str_replace(array('"', '\\'), '', $_SERVER['HTTP_SEC_CH_UA_PLATFORM']); //Strip quotes and escapes Ex: \"macOS\"
                }
    
                global $is_iphone;
                switch ( strtolower($info) ){
                    case 'full':
                    case 'name':
                        if ( $is_iphone ){
                            return 'ios';
                        }
                        break;
                    default:
                        return '';
                }
    
                return '';
            }
    

    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_os', 'my_custom_get_os', 10, 2); //The last integer must be 1 more than the actual parameters
    function my_custom_get_os($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_os', '__return_false');