SLPĀ® phpDocs

MySLP_DomainSwitcher extends SLPlus_BaseClass_Object
in package

Handles switching the domain for MySLP installations.

This class includes methods for initializing and configuring the domain, ensuring that all blogs in the database reflect the correct domain based on the environment.

Table of Contents

Properties

$addon  : object
$has_domain_mismatch  : bool
$myslp  : MySLP
$slplus  : SLPlus
$slug  : mixed
$uses_myslp  : bool
$uses_slplus  : bool
$site_domain  : string
$site_url  : string
$wpdb  : WPDB

Methods

__construct()  : mixed
__get()  : SLPlus_BaseClass_Object
__isset()  : bool
get_instance()  : static
Return an instance of the object which is also registered to the slplus global less the SLP_ part.
performUserBlogUpdates()  : void
Perform updates for a user's blog.
repairUserBlogDomain()  : bool
Repair a specific customer's URLs without redirecting or relying on the current site's mismatch.
set_properties()  : void
Set our properties.
updateUserBlogDomain()  : void
Rather than reload the entire DB to swap domains, let's use SUNRISE, the WP override, and this method to tweak it as needed.
initialize()  : void
Initializes the class properties including domain, site URL, and site domain.
change_blog_domain_in_json_options()  : void
Run through a set of known options containing JSON keys and replace the domain name.
change_blog_urls_if_needed()  : bool
Change the URLs for the blog.
get_requested_customer_blog_id()  : int
Resolve the customer site being viewed by a super admin from the request path.
update_all_blogs()  : void
Updates all blogs in the database to set the domain for the current site.

Properties

$has_domain_mismatch

public bool $has_domain_mismatch = \false

true if the current site url does not match domain

Methods

__construct()

public __construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
$options : array<string|int, mixed> = array()

get_instance()

Return an instance of the object which is also registered to the slplus global less the SLP_ part.

public static get_instance([bool $no_global = false ][, mixed $params = array() ]) : static
Parameters
$no_global : bool = false

set to true to skip assigning object to SLP global as a property.

$params : mixed = array()

object init params

Return values
static

performUserBlogUpdates()

Perform updates for a user's blog.

public performUserBlogUpdates(int $user_blog_id) : void
Parameters
$user_blog_id : int

The ID of the user's blog.

repairUserBlogDomain()

Repair a specific customer's URLs without redirecting or relying on the current site's mismatch.

public repairUserBlogDomain(int $user_blog_id) : bool

User switching calls this before changing authentication cookies or calculating redirects.

Parameters
$user_blog_id : int

The target customer's primary blog ID.

Return values
bool —

Whether the stored URLs were repaired.

set_properties()

Set our properties.

public set_properties([array<string|int, mixed> $options = array() ]) : void
Parameters
$options : array<string|int, mixed> = array()

updateUserBlogDomain()

Rather than reload the entire DB to swap domains, let's use SUNRISE, the WP override, and this method to tweak it as needed.

public updateUserBlogDomain() : void

This allows the production DB to be copied to staging or development without running a massive search-replace, instead of doing it as needed.

$mask_domain gets the requested domain as suggested in WordPress examples for sunrise.php. We mimic that here.

Tags
used-by

MySLP_Addon::initialize

initialize()

Initializes the class properties including domain, site URL, and site domain.

protected initialize() : void

Performs additional updates for all blogs if not on the production domain.

change_blog_domain_in_json_options()

Run through a set of known options containing JSON keys and replace the domain name.

private change_blog_domain_in_json_options(mixed $old_domain, mixed $new_domain) : void
Parameters
$old_domain : mixed
$new_domain : mixed

change_blog_urls_if_needed()

Change the URLs for the blog.

private change_blog_urls_if_needed() : bool

Assume switch_to_blog() for the user has already been performed.

Return values
bool —

Whether the stored site URL was repaired.

get_requested_customer_blog_id()

Resolve the customer site being viewed by a super admin from the request path.

private get_requested_customer_blog_id() : int

The content URL must identify the same site before its options are changed.

Return values
int

update_all_blogs()

Updates all blogs in the database to set the domain for the current site.

private update_all_blogs() : void

The method retrieves a count of all sites, excluding those with the domain of the current site. If no sites are found, the method returns. Otherwise, it updates the blogs table to set the domain value.

On this page

Search results