Skip to content

Backgrounds

How-to Guides

Technical References

Multisites /

Multiple domains

By default, the VIP Platform enforces the use of a single domain per site in a WordPress multisite (notably, this is not exactly the same as core multisite, which will cause a domain not associated with any site in the network to resolve to site_id 1.) Some VIPs have found it useful to allow multiple domains to resolve to a single site in the network either temporarily or permanently. In the below example from client-sunrise.php, this multi-domain configuration is limited to REST API requests, but it could be more general, or differently targeted.

// Allow REST API requests to be served on one of several domains.
$clientslug_custom_sunrise_domains = array( 'example.com', 'example.blog', 'example.go-vip.net' );

// Cause each of these domains to load `site_id` 1.
$clientslug_custom_sunrise_site_id = 1;

if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] )
	 && in_array( $_SERVER['HTTP_HOST'], $clientslug_custom_sunrise_domains, true )
	 && 0 === strpos( $_SERVER['REQUEST_URI'], '/wp-json' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, this is safe here.
) {
	// These domains are each associated with `site_id` 1 of network 1.
	$current_blog = get_site( $clientslug_custom_sunrise_site_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

	// This should always be 1, unless you are running multiple WordPress networks.
	$current_site = get_network( 1 ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}

Other uses of client-sunrise.php might include logic around redirects (that don’t require database lookups) or other manipulation of fundamental WordPress constants or globals based on the request.

Last updated: September 05, 2021