Skip to content

Commit 41db0b2

Browse files
committed
Refactor the population of the WordPress current network object
As of WordPress 3.9, `wpmu_current_site()` was deprecated and not left with a full, working replacement. We know that this environment relies on a single multisite network and can populate a network object accordingly. If for some reason multiple networks are used in the future, check to make sure the populated site object matches the network as expected.
1 parent f5df91c commit 41db0b2

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

sunrise.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<?php
2+
// This is a single network configuration and the network is defined in config.php
3+
if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
4+
$current_site = new stdClass;
5+
$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
6+
$current_site->blog_id = defined( 'BLOG_ID_CURRENT_SITE' ) ? BLOG_ID_CURRENT_SITE : 1;
7+
$current_site->cookie_domain = defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '.jquery.com';
8+
$current_site->domain = DOMAIN_CURRENT_SITE;
9+
$current_site->path = PATH_CURRENT_SITE;
10+
$current_site->site_name = 'jQuery';
11+
}
212

313
if ( isset( $blog_id ) ) {
4-
$current_site = wpmu_current_site();
5-
if ( ! is_object( $current_site ) )
6-
$current_site = new stdClass;
7-
if ( ! isset( $current_site->site_name ) )
8-
$current_site->site_name = 'jQuery';
914
$current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
1015

16+
// If for some reason this became a multi-network configuration, populate the site's network.
17+
if ( is_object( $current_blog ) && $current_blog->site_id != $current_site->id ) {
18+
$current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * from $wpdb->site WHERE id = %d LIMIT 0,1", $current_blog->site_id ) );
19+
$current_site->site_name = 'jQuery';
20+
}
21+
1122
// Can't find the site in the DB:
1223
if ( ! is_object( $current_blog ) ) {
1324
$current_blog = new stdClass;

0 commit comments

Comments
 (0)