Skip to Content

is_desktop()

Check if the user’s device is a desktop computer.

PHP May 30, 2017

Usage

PHP
nebula()->is_desktop()

Parameters

This function does not accept any parameters. Is this incorrect?

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

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

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

PHP
        public function is_desktop(){
            $override = apply_filters('pre_nebula_is_desktop', null);
            if ( isset($override) ){return $override;}

            if ( $this->get_option('device_detection') ){
                if ( isset($this->device) && $this->device->isDesktop() ){
                    return true;
                }
            }

            if ( !wp_is_mobile() ){ //This does a basic check for mobile or tablet devices.
                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_desktop', 'my_custom_is_desktop'); 
function my_custom_is_desktop(){ 
    //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_desktop', '__return_false');