Last active
August 29, 2015 14:09
-
-
Save saaiful/59ee84ca4a47a644dca4 to your computer and use it in GitHub Desktop.
Multilingual WP
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 | |
/** | |
* @package Multilingual WP | |
* @version 1.0 | |
*/ | |
/* | |
Plugin Name: Multilingual WP | |
Plugin URI: http://saiul.im/ | |
Description: Multilingual For WordPress. This Plugin Based on Shortcode. (It's a Beta) | |
Author: Saiful Islam | |
Version: 1.0 | |
Author URI: http://saiul.im/ | |
*/ | |
function languageSwitcher( $query ) { | |
if(!isset($_COOKIE['mlang'])) | |
{ | |
setcookie('mlang', 'en', strtotime('+1 day')); | |
wp_redirect( $_SERVER['HTTP_REFERER'] ); | |
} | |
if(isset($_GET['lang'])) | |
{ | |
setcookie('mlang', $_GET['lang'], strtotime('+1 day')); | |
wp_redirect( $_SERVER['HTTP_REFERER'] ); | |
} | |
} | |
add_action( 'pre_get_posts', 'languageSwitcher' ); | |
function current_page_url() { | |
$pageURL = 'http'; | |
if( isset($_SERVER["HTTPS"]) ) { | |
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} | |
} | |
$pageURL .= "://"; | |
if ($_SERVER["SERVER_PORT"] != "80") { | |
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; | |
} else { | |
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; | |
} | |
return $pageURL; | |
} | |
function new_nav_menu_items($items) { | |
$url = current_page_url(); | |
$en = (preg_match("/\?/", $url))? $url.'&lang=en' : $url.'?lang=en'; | |
$bn = (preg_match("/\?/", $url))? $url.'&lang=bn' : $url.'?lang=bn'; | |
$homelink = '<li class="bn"><a href="' . $bn . '">' . __('BN') . '</a></li>'; | |
$homelink .= '<li class="en"><a href="' . $en . '">' . __('EN') . '</a></li>'; | |
$items = $items.$homelink; | |
return $items; | |
} | |
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' ); | |
function mlangDisplay( $atts , $content = null ) { | |
extract( shortcode_atts( | |
array( | |
'lang' => 'en', | |
), $atts ) | |
); | |
if($_COOKIE['mlang']==$atts['lang']) | |
{ | |
echo $content; | |
} | |
} | |
add_shortcode( 'mlang', 'mlangDisplay' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment