wpmu_current_site

The timeline below displays how wordpress function wpmu_current_site has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.6

/**
 * This deprecated function managed much of the site and network loading in multisite.
 *
 * The current bootstrap code is now responsible for parsing the site and network load as
 * well as setting the global $current_site object.
 *
 * @access private
 * @since 3.0.0
 * @deprecated 3.9.0
 *
 * @global WP_Network $current_site
 *
 * @return WP_Network
 */
function wpmu_current_site()
{
    global $current_site;
    _deprecated_function(__FUNCTION__, '3.9.0');
    return $current_site;
}

WordPress Version: 4.6

/**
 * This deprecated function managed much of the site and network loading in multisite.
 *
 * The current bootstrap code is now responsible for parsing the site and network load as
 * well as setting the global $current_site object.
 *
 * @access private
 * @since 3.0.0
 * @deprecated 3.9.0
 *
 * @global object $current_site
 *
 * @return object
 */
function wpmu_current_site()
{
    global $current_site;
    _deprecated_function(__FUNCTION__, '3.9.0');
    return $current_site;
}

WordPress Version: 4.3

/**
 * This deprecated function managed much of the site and network loading in multisite.
 *
 * The current bootstrap code is now responsible for parsing the site and network load as
 * well as setting the global $current_site object.
 *
 * @access private
 * @since 3.0.0
 * @deprecated 3.9.0
 *
 * @global object $current_site
 *
 * @return object
 */
function wpmu_current_site()
{
    global $current_site;
    _deprecated_function(__FUNCTION__, '3.9');
    return $current_site;
}

WordPress Version: 3.9

/**
 * This deprecated function managed much of the site and network loading in multisite.
 *
 * The current bootstrap code is now responsible for parsing the site and network load as
 * well as setting the global $current_site object.
 *
 * @access private
 * @since 3.0.0
 * @deprecated 3.9.0
 *
 * @return object
 */
function wpmu_current_site()
{
    global $current_site;
    _deprecated_function(__FUNCTION__, '3.9');
    return $current_site;
}

WordPress Version: 3.7

/**
 * Sets current_site object.
 *
 * @access private
 * @since 3.0.0
 * @return object $current_site object
 */
function wpmu_current_site()
{
    global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
    if (empty($current_site)) {
        $current_site = new stdClass();
    }
    if (defined('DOMAIN_CURRENT_SITE') && defined('PATH_CURRENT_SITE')) {
        $current_site->id = defined('SITE_ID_CURRENT_SITE') ? SITE_ID_CURRENT_SITE : 1;
        $current_site->domain = DOMAIN_CURRENT_SITE;
        $current_site->path = $path = PATH_CURRENT_SITE;
        if (defined('BLOG_ID_CURRENT_SITE')) {
            $current_site->blog_id = BLOG_ID_CURRENT_SITE;
        } elseif (defined('BLOGID_CURRENT_SITE')) {
            // deprecated.
            $current_site->blog_id = BLOGID_CURRENT_SITE;
        }
        if (DOMAIN_CURRENT_SITE == $domain) {
            $current_site->cookie_domain = $cookie_domain;
        } elseif (substr($current_site->domain, 0, 4) == 'www.') {
            $current_site->cookie_domain = substr($current_site->domain, 4);
        } else {
            $current_site->cookie_domain = $current_site->domain;
        }
        wp_load_core_site_options($current_site->id);
        return $current_site;
    }
    $current_site = wp_cache_get('current_site', 'site-options');
    if ($current_site) {
        return $current_site;
    }
    $sites = $wpdb->get_results("SELECT * FROM {$wpdb->site}");
    // usually only one site
    if (1 == count($sites)) {
        $current_site = $sites[0];
        wp_load_core_site_options($current_site->id);
        $path = $current_site->path;
        $current_site->blog_id = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path));
        $current_site = get_current_site_name($current_site);
        if (substr($current_site->domain, 0, 4) == 'www.') {
            $current_site->cookie_domain = substr($current_site->domain, 4);
        }
        wp_cache_set('current_site', $current_site, 'site-options');
        return $current_site;
    }
    $path = substr($_SERVER['REQUEST_URI'], 0, 1 + strpos($_SERVER['REQUEST_URI'], '/', 1));
    if ($domain == $cookie_domain) {
        $current_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE domain = %s AND path = %s", $domain, $path));
    } else {
        $current_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path));
    }
    if (!$current_site) {
        if ($domain == $cookie_domain) {
            $current_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE domain = %s AND path='/'", $domain));
        } else {
            $current_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path));
        }
    }
    if ($current_site) {
        $path = $current_site->path;
        $current_site->cookie_domain = $cookie_domain;
        return $current_site;
    }
    if (is_subdomain_install()) {
        $sitedomain = substr($domain, 1 + strpos($domain, '.'));
        $current_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE domain = %s AND path = %s", $sitedomain, $path));
        if ($current_site) {
            $current_site->cookie_domain = $current_site->domain;
            return $current_site;
        }
        $current_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE domain = %s AND path='/'", $sitedomain));
    }
    if ($current_site || defined('WP_INSTALLING')) {
        $path = '/';
        return $current_site;
    }
    // Still no dice.
    wp_load_translations_early();
    if (1 == count($sites)) {
        wp_die(sprintf(__('That site does not exist. Please try <a href="%s">%s</a>.'), 'http://' . $sites[0]->domain . $sites[0]->path));
    } else {
        wp_die(__('No site defined on this host. If you are the owner of this site, please check <a href="http://codex.wordpress.org/Debugging_a_WordPress_Network">Debugging a WordPress Network</a> for help.'));
    }
}