Last active
November 3, 2016 00:48
-
-
Save Biont/a42b228bf1f3d5f8c85e to your computer and use it in GitHub Desktop.
Sets the WordPress locale to MLP's current blog language, allowing custom/different language files to be loaded
This file contains hidden or 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
/** | |
* Plugin Name: MLP Load Language Files | |
* Description: Sets the WP locale to MLP's current blog language so that different language files can be loaded | |
* Author: Inpsyde GmbH | |
* Author URI: http://inpsyde.com | |
* Text Domain: multilingualpress | |
* Domain Path: /languages | |
* License: GPLv3 | |
*/ | |
if ( ! is_admin() ) { | |
add_action( 'inpsyde_mlp_loaded', 'inpsyde_load_mlp_locale_init' ); | |
} | |
/** | |
* Load up the plugin | |
*/ | |
function inpsyde_load_mlp_locale_init() { | |
$load_locale = new Mlp_Addon_Load_Locale(); | |
$load_locale->init(); | |
} | |
class Mlp_Addon_Load_Locale { | |
/** | |
* Initialize this class | |
*/ | |
public function init() { | |
add_filter( 'locale', array( $this, 'load_mlp_locale' ) ); | |
} | |
/** | |
* Replace the WP locale based on MLP's current language | |
* | |
* @param $locale | |
* | |
* @return mixed | |
* @wp-hook locale | |
*/ | |
public function load_mlp_locale( $locale ) { | |
$api = apply_filters( 'mlp_language_api', NULL ); | |
if ( ! ( $api instanceof Mlp_Language_Api_Interface ) ) { // for IDE support | |
return $locale; | |
} | |
$languages = get_site_option( 'inpsyde_multilingual' ); | |
$current_language = $languages[ get_current_blog_id() ]; | |
if ( ! empty( $current_language[ 'lang' ] ) ) { | |
return $current_language[ 'lang' ]; | |
} | |
return $locale; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment