domainer = $wpdb->base_prefix . 'domainer';
// Setup the registry
Registry::load();
// Register the Installer stuff
Installer::register_hooks();
// Register global hooks
self::register_hooks();
// Register the hooks of the subsystems
Frontend::register_hooks();
Backend::register_hooks();
Manager::register_hooks();
Documenter::register_hooks();
}
/**
* Notify the user that Domainer is useless without Multisite.
*
* @since 1.0.1
*/
public static function no_multisite_notice() {
?>
domain_id );
// If the domain is found and is not a redirect, skip
if ( $domain && $domain->type !== 'redirect' ) {
return;
}
}
// Find a primary domain for this site
if ( $domain = Registry::get_primary_domain( $current_blog->blog_id ) ) {
// Use the current path as the prefix, get the true one if it exists
$path = $current_blog->path;
if ( property_exists( $current_blog, 'true_path' ) ) {
$path = $current_blog->true_path;
}
self::redirect( $domain->fullname(), $path );
}
}
/**
* Redirect to the domain with/out www if applicable.
*
* @since 1.1.2 Use property_exists() to check if domain_id exists on blog object.
* @since 1.0.0
*
* @global \WP_Site $current_blog The current site object.
*/
public static function maybe_redirect_to_www() {
global $current_blog;
// Skip if Domainer didn't rewrite anything
if ( ! DOMAINER_REWRITTEN ) {
return;
}
// Skip if unable to find the domain
if ( ! property_exists( $current_blog, 'domain_id' ) || ! ( $domain = Registry::get_domain( $current_blog->domain_id ) ) ) {
return;
}
// Skip if the the domains rule is upheld
if ( $domain->www == 'auto' || ( $domain->www == 'always' && DOMAINER_USING_WWW ) || ( $domain->www == 'never' && ! DOMAINER_USING_WWW ) ) {
return;
}
self::redirect( $domain->fullname() );
}
// =========================
// ! Domain Rewriting
// =========================
/**
* Filter the URL to replace the domain name.
*
* @since 1.0.0
*
* @param string $url The URL to rewrite.
*
* @return string The filtered URL.
*/
public static function rewrite_domain_in_url( $url ) {
$url = str_replace( get_true_url(), get_current_url(), $url );
return $url;
}
/**
* Filter the content to replace the domain name.
*
* @since 1.0.0
*
* @param string $url The content to filter.
*
* @return string The filtered content.
*/
public static function rewrite_domain_in_content( $content ) {
// Only replace instances prefixed with a double slash, to prevent it affecting email addresses
$content = str_replace( '//' . get_true_url(), '//' . get_current_url(), $content );
return $content;
}
/**
* Filter the upload_dir array to replace the domain name.
*
* @since 1.0.0
*
* @param array $upload_dir The array to filter.
*
* @return array The filtered array.
*/
public static function rewrite_domain_in_upload_dir( $upload_dir ) {
$upload_dir['baseurl'] = self::rewrite_domain_in_url( $upload_dir['baseurl'] );
$upload_dir['url'] = self::rewrite_domain_in_url( $upload_dir['url'] );
return $upload_dir;
}
// =========================
// ! Admin UI Tweaks
// =========================
/**
* Add a Domains item to the Network Admin menu.
*
* @since 1.0.0
*
* @param \WP_Admin_Bar $wp_admin_bar The admin bar object.
*/
public static function add_domains_item( $wp_admin_bar ) {
$wp_admin_bar->add_node( array(
'id' => 'network-admin-domainer',
'title' => __( 'Domains', 'domainer' ),
'parent' => 'network-admin',
'href' => network_admin_url( 'admin.php?page=domainer' ),
) );
}
// =========================
// ! Blog Switching
// =========================
/**
* Modify the $current_blog global to reflect the switch.
*
* This will allow domain rewrite handling to work during switch_to_blog().
*
* @since 1.1.0
*
* @param int $blog_id The ID of the blog being switched to.
*/
public static function rewrite_current_blog_object( $blog_id ) {
global $current_blog, $current_site;
// Get the new blog
$new_blog = \WP_Site::get_instance( $blog_id );
// Get the requested domain if on the original blog, otherwise the primary
if ( defined( 'DOMAINER_REQUESTED_BLOG' ) && DOMAINER_REQUESTED_BLOG === $blog_id ) {
$domain = Registry::get_domain( DOMAINER_REQUESTED_DOMAIN );
} else {
$domain = Registry::get_primary_domain( $blog_id );
}
if ( $new_blog ) {
// Replace current blog
$current_blog = $new_blog;
if ( $domain ) {
// Store the true domain/path, along with the requested domain's ID
$current_blog->true_domain = $current_blog->domain;
$current_blog->true_path = $current_blog->path;
$current_blog->domain_id = $domain->id;
// Rewrite the domain/path
$current_blog->domain = $domain->fullname();
$current_blog->path = '/';
}
}
}
}