Skip to content

Instantly share code, notes, and snippets.

@JustThomas
Last active August 29, 2015 14:13
Show Gist options
  • Save JustThomas/75072b693535f7abac39 to your computer and use it in GitHub Desktop.
Save JustThomas/75072b693535f7abac39 to your computer and use it in GitHub Desktop.
Workaround for redirects with WordPress HTTPS and WordPress MU Domain Mapping
<?php
/*
Plugin Name: Workaround for HTTPS with Domain Mapping
Description: Disables redirect from MU Domain Mapping Plugin on SSL-secured pages
Author: Thomas Ulrich
Author URI: https://github.com/JustThomas
Version: 0.1
*/
function tu_wordpress_https_workaround() {
if( is_ssl() && class_exists('WordPressHTTPS') && function_exists('domain_mapping_siteurl') ) {
global $wordpress_https;
if( is_a( $wordpress_https, 'WordPressHTTPS' ) ) {
/*
* The page has been requested through HTTPS, the
* WordPress HTTPS plugin is active and a SSL host is
* set in the plugin settings
* Therefore, prevent the Domain Mapping plugin from
* redirecting to the primary domain.
*/
if ( remove_action( 'template_redirect', 'redirect_to_mapped_domain' ) ) {
// Redirect to HTTPS using WordPress HTTPS
$wordpress_https->redirect('https');
}
}
}
}
/*
* 'priority' parameter has to be smaller than 10. Otherwise, the
* domain mapping redirect will fire before this workaround kicks in
*/
add_action( 'template_redirect', 'tu_wordpress_https_workaround', 9);
function tu_remove_dm_admin_redirect() {
if( is_ssl() && class_exists('WordPressHTTPS') && function_exists('domain_mapping_siteurl') ) {
global $wordpress_https;
if( is_a( $wordpress_https, 'WordPressHTTPS' ) ) {
remove_action('admin_init', 'dm_redirect_admin');
}
}
}
add_action( 'admin_init', 'tu_remove_dm_admin_redirect', 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment