Last active
February 16, 2017 17:23
-
-
Save apermo/b127d530a758ecfcbae45df92fc16a73 to your computer and use it in GitHub Desktop.
WordPress Multisite Domain Mapping & Visual Composer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! class_exists( 'MultsiteComposer' ) ) { | |
class MultsiteComposer { | |
public static function init() { | |
if ( isset( $_GET['vc_action'] ) || isset( $_GET['vc_editable'] ) ) { | |
if ( defined( 'DOMAIN_MAPPING' ) ) { | |
remove_filter( 'plugins_url', 'domain_mapping_plugins_uri', 1 ); | |
remove_filter( 'theme_root_uri', 'domain_mapping_themes_uri', 1 ); | |
remove_filter( 'pre_option_siteurl', 'domain_mapping_siteurl' ); | |
remove_filter( 'pre_option_home', 'domain_mapping_siteurl' ); | |
remove_filter( 'the_content', 'domain_mapping_post_content' ); | |
remove_action( 'wp_head', 'remote_login_js_loader' ); | |
remove_action( 'login_head', 'redirect_login_to_orig' ); | |
remove_action( 'wp_logout', 'remote_logout_loader', 9999 ); | |
remove_filter( 'stylesheet_uri', 'domain_mapping_post_content' ); | |
remove_filter( 'stylesheet_directory', 'domain_mapping_post_content' ); | |
remove_filter( 'stylesheet_directory_uri', 'domain_mapping_post_content' ); | |
remove_filter( 'template_directory', 'domain_mapping_post_content' ); | |
remove_filter( 'template_directory_uri', 'domain_mapping_post_content' ); | |
remove_filter( 'plugins_url', 'domain_mapping_post_content' ); | |
} else { | |
remove_filter( 'admin_url', 'domain_mapping_adminurl', 10 ); | |
} | |
remove_action( 'admin_init', 'dm_redirect_admin' ); | |
if ( isset( $_GET['dm'] ) ) { | |
remove_action( 'template_redirect', 'remote_login_js' ); | |
} | |
remove_action( 'template_redirect', 'redirect_to_mapped_domain' ); | |
remove_action( 'delete_blog', 'delete_blog_domain_mapping', 1 ); | |
remove_filter( 'wpmu_blogs_columns', 'ra_domain_mapping_columns' ); | |
remove_action( 'manage_blogs_custom_column', 'ra_domain_mapping_field', 1 ); | |
remove_action( 'manage_sites_custom_column', 'ra_domain_mapping_field', 1 ); | |
} else { | |
if ( ! is_admin() ) { | |
add_action( 'init', array( __CLASS__, 'init_buffer' ), 100 ); | |
} | |
} | |
add_filter( 'vc_get_inline_url', array( __CLASS__, 'vc_admin_url_filter' ) ); | |
} | |
public static function vc_admin_url_filter( $url ) { | |
return str_replace( get_option( 'siteurl' ), get_original_url( 'siteurl' ), $url ); | |
} | |
public static function init_buffer() { | |
ob_start( array( __CLASS__, 'buffer_callback' ) ); | |
} | |
public static function buffer_callback( $buffer ) { | |
//Some unmapped URLs appear, leading to missing fonts and other things. Lets replace them | |
$urls['ori'] = get_original_url( 'siteurl' ) . '/wp-content/'; | |
$urls['mapped'] = get_option( 'siteurl' ) . '/wp-content/'; | |
$buffer = str_replace( $urls['ori'], $urls['mapped'], $buffer ); | |
$urls = str_replace( array( 'http://', 'https://' ), '//', $urls ); | |
$buffer = str_replace( $urls['ori'], $urls['mapped'], $buffer ); | |
return $buffer; | |
} | |
} | |
MultsiteComposer::init(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using a filter for editing the VC Edit URLs instead of a regex.