Skip to Content

is_client()

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

PHP April 27, 2017

Usage

PHP
nebula()->is_client($strict)

Parameters

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

Parameter Notes

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

Request or provide clarification »

Examples

PHP
<?php if ( is_client() ){
    //Something for clients only.
} ?>

Additional Notes

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

For clarification, “client” in this context means the person or business for whom this website is being made. Any stakeholder who is not a developer should be added as a client in Nebula Options.

Source File

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

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

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

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

            if ( empty($strict) ){
                $clientIPs = explode(',', $this->get_option('client_ip'));
                if ( !empty($clientIPs) ){
                    foreach ( $clientIPs as $clientIP ){
                        $clientIP = wp_privacy_anonymize_ip(trim($clientIP));

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

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

            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);

                    //Check if the current user's email domain matches any of the client email domains from Nebula Options
                    $clientEmails = explode(',', $this->get_option('client_email_domain'));
                    foreach ( $clientEmails as $clientEmail ){
                        if ( trim($clientEmail) === $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_client', 'my_custom_is_client', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_is_client($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_client', '__return_false');