Skip to content

Instantly share code, notes, and snippets.

@tfrommen
Last active August 2, 2016 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfrommen/29257e5aa001dde90fd569e2bc7d6296 to your computer and use it in GitHub Desktop.
Save tfrommen/29257e5aa001dde90fd569e2bc7d6296 to your computer and use it in GitHub Desktop.
Configure MultilingualPress to only redirect users on the front page
<?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 );
} );
@thefuxia
Copy link

thefuxia commented Aug 2, 2016

This should work too.

add_filter ( 'mlp_redirect_url', function( $redirect ) {

    return parse_url( home_url(), PHP_URL_PATH ) === $_SERVER['REQUEST_URI'] 
        ? $redirect : false;
});

@tfrommen
Copy link
Author

tfrommen commented Aug 2, 2016

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