is_main_network

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

WordPress Version: 6.1

/**
 * Determines whether a network is the main network of the Multisite installation.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running Multisite.
 */
function is_main_network($network_id = null)
{
    if (!is_multisite()) {
        return true;
    }
    if (null === $network_id) {
        $network_id = get_current_network_id();
    }
    $network_id = (int) $network_id;
    return get_main_network_id() === $network_id;
}

WordPress Version: 5.4

/**
 * Determine whether a network is the main network of the Multisite installation.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running Multisite.
 */
function is_main_network($network_id = null)
{
    if (!is_multisite()) {
        return true;
    }
    if (null === $network_id) {
        $network_id = get_current_network_id();
    }
    $network_id = (int) $network_id;
    return get_main_network_id() === $network_id;
}

WordPress Version: 4.9

/**
 * Determine whether a network is the main network of the Multisite installation.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running Multisite.
 */
function is_main_network($network_id = null)
{
    if (!is_multisite()) {
        return true;
    }
    if (null === $network_id) {
        $network_id = get_current_network_id();
    }
    $network_id = (int) $network_id;
    return $network_id === get_main_network_id();
}

WordPress Version: 4.7

/**
 * Determine whether a network is the main network of the Multisite install.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running Multisite.
 */
function is_main_network($network_id = null)
{
    if (!is_multisite()) {
        return true;
    }
    if (null === $network_id) {
        $network_id = get_current_network_id();
    }
    $network_id = (int) $network_id;
    return $network_id === get_main_network_id();
}

WordPress Version: 4.3

/**
 * Determine whether a network is the main network of the Multisite install.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running Multisite.
 */
function is_main_network($network_id = null)
{
    if (!is_multisite()) {
        return true;
    }
    $current_network_id = (int) get_current_site()->id;
    if (null === $network_id) {
        $network_id = $current_network_id;
    }
    $network_id = (int) $network_id;
    return $network_id === get_main_network_id();
}

WordPress Version: 4.0

/**
 * Determine whether a network is the main network of the Multisite install.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running Multisite.
 */
function is_main_network($network_id = null)
{
    global $wpdb;
    if (!is_multisite()) {
        return true;
    }
    $current_network_id = (int) get_current_site()->id;
    if (!$network_id) {
        $network_id = $current_network_id;
    }
    $network_id = (int) $network_id;
    if (defined('PRIMARY_NETWORK_ID')) {
        return $network_id === (int) PRIMARY_NETWORK_ID;
    }
    if (1 === $current_network_id) {
        return $network_id === $current_network_id;
    }
    $primary_network_id = (int) wp_cache_get('primary_network_id', 'site-options');
    if ($primary_network_id) {
        return $network_id === $primary_network_id;
    }
    $primary_network_id = (int) $wpdb->get_var("SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1");
    wp_cache_add('primary_network_id', $primary_network_id, 'site-options');
    return $network_id === $primary_network_id;
}

WordPress Version: 3.8

/**
 * Whether a network is the main network of the multisite install.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running multisite.
 */
function is_main_network($network_id = null)
{
    global $wpdb;
    if (!is_multisite()) {
        return true;
    }
    $current_network_id = (int) get_current_site()->id;
    if (!$network_id) {
        $network_id = $current_network_id;
    }
    $network_id = (int) $network_id;
    if (defined('PRIMARY_NETWORK_ID')) {
        return $network_id === (int) PRIMARY_NETWORK_ID;
    }
    if (1 === $current_network_id) {
        return $network_id === $current_network_id;
    }
    $primary_network_id = (int) wp_cache_get('primary_network_id', 'site-options');
    if ($primary_network_id) {
        return $network_id === $primary_network_id;
    }
    $primary_network_id = (int) $wpdb->get_var("SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1");
    wp_cache_add('primary_network_id', $primary_network_id, 'site-options');
    return $network_id === $primary_network_id;
}

WordPress Version: 3.7

/**
 * Whether a network is the main network of the multisite install.
 *
 * @since 3.7.0
 *
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
 * @return bool True if $network_id is the main network, or if not running multisite.
 */
function is_main_network($network_id = null)
{
    global $current_site, $wpdb;
    if (!is_multisite()) {
        return true;
    }
    $current_network_id = (int) $current_site->id;
    if (!$network_id) {
        $network_id = $current_network_id;
    }
    $network_id = (int) $network_id;
    if (defined('PRIMARY_NETWORK_ID')) {
        return $network_id === (int) PRIMARY_NETWORK_ID;
    }
    if (1 === $current_network_id) {
        return $network_id === $current_network_id;
    }
    $primary_network_id = (int) wp_cache_get('primary_network_id', 'site-options');
    if ($primary_network_id) {
        return $network_id === $primary_network_id;
    }
    $primary_network_id = (int) $wpdb->get_var("SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1");
    wp_cache_add('primary_network_id', $primary_network_id, 'site-options');
    return $network_id === $primary_network_id;
}