Last active
August 2, 2016 12:55
-
-
Save tfrommen/29257e5aa001dde90fd569e2bc7d6296 to your computer and use it in GitHub Desktop.
Configure MultilingualPress to only redirect users on the front page
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 # -*- coding: utf-8 -*- | |
add_action( 'inpsyde_mlp_init', function () { | |
remove_action( 'inpsyde_mlp_loaded', 'mlp_feature_redirect' ); | |
} ); | |
add_action( 'mlp_and_wp_loaded', function ( Inpsyde_Property_List_Interface $plugin_data ) { | |
if ( | |
is_admin() | |
|| parse_url( trailingslashit( home_url() ), PHP_URL_PATH ) !== trailingslashit( $_SERVER['REQUEST_URI'] ) | |
|| ( defined( 'DOING_AJAX' ) && DOING_AJAX ) | |
) { | |
return; | |
} | |
$response = new Mlp_Redirect_Response( | |
new Mlp_Language_Negotiation( | |
$plugin_data->get( 'language_api' ), | |
new Mlp_Accept_Header_Parser( | |
new Mlp_Language_Header_Validator() | |
) | |
) | |
); | |
add_action( 'template_redirect', [ $response, 'redirect' ], 1 ); | |
} ); |
This gist is intended to be used when you want to completely deactivate the Redirect feature altogether, and only want to redirect your users from your sites's individual front page.
Using parse_url( home_url(), PHP_URL_PATH ) === $_SERVER['REQUEST_URI']
instead of just '/'
is a very good idea, though. I just made this gist for a customer, assuming a standard subdomain install, not in a subdirectory.
I'll adapt this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work too.