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 : mixed
- $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.
- set_properties() : mixed
- 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() : void
- Change the URLs for the blog.
- update_all_blogs() : void
- Updates all blogs in the database to set the domain for the current site.
Properties
$addon
public
object
$addon
$has_domain_mismatch
public
bool
$has_domain_mismatch
= \false
true if the current site url does not match domain
$myslp
public
MySLP
$myslp
$slplus
public
SLPlus
$slplus
$slug
protected
mixed
$slug
$uses_myslp
protected
bool
$uses_myslp
= \true
$uses_slplus
protected
mixed
$uses_slplus
= \false
$site_domain
private
string
$site_domain
the domain for the site url
$site_url
private
string
$site_url
the full URL for MySLP Install blog #1
$wpdb
private
WPDB
$wpdb
Methods
__construct()
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
__get()
public
__get(string $property) : SLPlus_BaseClass_Object
Parameters
- $property : string
Return values
SLPlus_BaseClass_Object__isset()
public
__isset(string $property) : bool
Parameters
- $property : string
Return values
boolget_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
staticperformUserBlogUpdates()
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.
set_properties()
Set our properties.
public
set_properties([array<string|int, mixed> $options = array() ]) : mixed
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
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() : void
Assume switch_to_blog() for the user has already been performed.
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.