diff --git a/wordpress/wp-includes/functions.php b/wordpress/wp-includes/functions.php
index 0a8e1a0..eeabec9 100644
--- a/wordpress/wp-includes/functions.php
+++ b/wordpress/wp-includes/functions.php
@@ -3660,32 +3660,51 @@
  * @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() )
+	// Always return true if not a multisite installation
+	if ( ! is_multisite() ) {
 		return true;
+	}
 
 	$current_network_id = (int) get_current_site()->id;
 
-	if ( ! $network_id )
+	if ( null === $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 );
+	}
 
-	if ( 1 === $current_network_id )
-		return $network_id === $current_network_id;
+	return ( $network_id === get_primary_network_id() );
+}
 
-	$primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' );
+/**
+ * Get the primary network ID
+ *
+ * @global wpdb $wpdb
+ * @return int  
+ */
+function get_primary_network_id() {
+	global $wpdb;
 
-	if ( $primary_network_id )
-		return $network_id === $primary_network_id;
+	// Use constant if explicitly set
+	if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
+		$primary_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' );
+	// Fallback on cached value, queried from sites table
+	} else {
+		$primary_network_id = wp_cache_get( 'primary_network_id', 'site-options' );
 
-	return $network_id === $primary_network_id;
+		if ( false === $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 (int) apply_filters( 'get_primary_network_id', $primary_network_id );
 }
 
 /**
