Skip to Content

is_dev()

Check if the current visitor is a developer by using their IP address or their WordPress user email domain (if they are logged in).

PHP April 27, 2017

Usage

PHP
nebula()->is_dev($strict)

Parameters

$strict
(Optional) (Boolean) User must be logged in
Default: false

Parameter Notes

Passing $strict as true bypasses the IP address condition and requires the user to be logged in and a developer.

Request or provide clarification »

Examples

PHP
<?php if ( is_dev() ){
    //Something for developers only.
} ?>

Additional Notes

Developers and clients IP addresses and email domains can be added in Nebula Options under the Administration tab.

Source File

Located in /libs/Utilities/Utilities.php on line 182.

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

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

PHP
        public function is_dev($strict=false){
            $override = apply_filters('pre_is_dev', null, $strict);
            if ( isset($override) ){return $override;}

            if ( empty($strict) ){
                $devIPs = explode(',', $this->get_option('dev_ip'));
                if ( !empty($devIPs) ){
                    foreach ( $devIPs as $devIP ){
                        $devIP = wp_privacy_anonymize_ip(trim($devIP));

                        if ( !empty($devIP) && $devIP[0] !== '/' && $devIP === $this->get_ip_address() ){
                            return true;
                        }

                        if ( !empty($devIP) && $devIP[0] === '/' && preg_match($devIP, $this->get_ip_address()) ){
                            return true;
                        }
                    }
                }
            }

            //Check if the current user's email domain matches any of the dev email domains from Nebula Options
            if ( is_user_logged_in() ){
                $current_user = wp_get_current_user();
                if ( !empty($current_user->user_email) ){
                    list($current_user_email, $current_user_domain) = explode('@', $current_user->user_email);

                    $devEmails = explode(',', $this->get_option('dev_email_domain'));
                    foreach ( $devEmails as $devEmail ){
                        if ( trim($devEmail) === $current_user_domain ){
                            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_is_dev', 'my_custom_is_dev', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_is_dev($null, $strict){ //$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_is_dev', '__return_false');