Skip to Content

is_site_live()

An inexact method of detecting if the current website is live, or being developed on an alternate hostname.

PHP June 18, 2017

Usage

PHP
nebula()->is_site_live()

Parameters

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

Examples

PHP
<?php if ( is_site_live() ){
    //Do something if the site is live
} ?>

Additional Notes

This function only works when the Hostnames Nebula option is used. It checks the current hostname to the hostname(s) in Nebula Options to determine if the site is live. It’s useful when development is being done on a different domain/hostname.

Source File

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

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

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

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

            if ( $this->get_option('hostnames') ){
                if ( strpos($this->get_option('hostnames'), $this->url_components('hostname', home_url())) >= 0 ){
                    return true;
                }
                return false;
            }
            return true;
        }

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_site_live', 'my_custom_is_site_live'); 
function my_custom_is_site_live(){ 
    //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_site_live', '__return_false');