| 3271 | * Checks either the current site or a supplied network id against the primary network id |
| 3272 | * to determine if this is the main network. |
| 3273 | * |
| 3274 | * @since 3.7.0 |
| 3275 | * @package WordPress |
| 3276 | * |
| 3277 | * @param string $network_id optional network id to test (default current site) |
| 3278 | * |
| 3279 | * @return bool True if not multisite or if $network_id is the main network |
| 3280 | */ |
| 3281 | function is_main_network( $network_id = '' ) { |
| 3282 | global $current_site, $wpdb; |
| 3283 | |
| 3284 | if ( ! is_multisite() ) |
| 3285 | return true; |
| 3286 | |
| 3287 | if ( ! $network_id ) |
| 3288 | $network_id = $current_site->id; |
| 3289 | |
| 3290 | if ( defined( 'PRIMARY_NETWORK_ID' ) ) |
| 3291 | return $network_id == PRIMARY_NETWORK_ID; |
| 3292 | |
| 3293 | if ( 1 == $current_site->id ) |
| 3294 | return $network_id == $current_site->id; |
| 3295 | |
| 3296 | $primary_network_id = wp_cache_get( 'primary_network_id', 'site-options' ); |
| 3297 | |
| 3298 | if ( $primary_network_id ) |
| 3299 | return $network_id == $primary_network_id; |
| 3300 | |
| 3301 | $primary_network_id = $wpdb->get_var( "SELECT id FROM $wpdb->site ORDER BY id LIMIT 1" ); |
| 3302 | wp_cache_set( 'primary_network_id', $primary_network_id, 'site-options' ); |
| 3303 | |
| 3304 | return $network_id == $primary_network_id; |
| 3305 | } |
| 3306 | |
| 3307 | /** |