hello. i want to modify wpmu's home page. i want language of it is selectable by guest user with GET variable and/or select language from cookie. should i modify core files or can i make separate plug-in? if i must modify then where i should?
hello. i want to modify wpmu's home page. i want language of it is selectable by guest user with GET variable and/or select language from cookie. should i modify core files or can i make separate plug-in? if i must modify then where i should?
now i have found function get_locale() { ... in /wp-includes/l10n.php .
i have found that apply_filters function that is called in get_locale function overwrites $locale variable with "correct" (that is in settings and/or in database).
can i do not call apply_filters ? i checked and have known out that returning $locale (it is like 'en_GB') directly (without passing it through "apply_filters" function) makes the blog change language.
in http://mu.wordpress.org/forums/topic.php?id=2042&page=2#post-67728 "Multi language set up" i have just now said:
"now i have home page quickly can change language this way. i have added "?l=en" like links to multilingual home theme. current language is saved in cookie.
...
i know now that i probably can change $locale with apply_filters."
function get_locale() {
global $locale;
//mod
//error_log($_COOKIE['forum_guest_language']."\r\n",3,'debuglog.txt');
//endmod
//mod
//error_log($locale."\r\n",3,'debuglog.txt');
//error_log(apply_filters( 'locale', $locale )."\r\n",3,'debuglog.txt');
//error_log((isset($locale)?'1':'0')."\r\n",3,'debuglog.txt');
//error_log((isset($locale)?'1':'0').':'.$locale.':'.apply_filters('locale',$locale)."\r\n",3,'debuglog.txt');
//endmod
//mod
if($_SERVER['HTTP_HOST']=='wp.domain.tld'&&!headers_sent()){
if($_GET['l']=='l1'){
$locale='l1_CO';
setcookie('forum_guest_language','Lang1',time()+365*24*60*60,'/','domain.tld');
}elseif($_GET['l']=='l2'){
$locale='l2_CO';
setcookie('forum_guest_language','Lang2',time()+365*24*60*60,'/','domain.tld');
}else{
$cookie_guest_language=$_COOKIE['forum_guest_language'];
if($cookie_guest_language=='Lang1'){$locale='l1_CO';}
elseif($cookie_guest_language=='Lang2'){$locale='l2_CO';}
else{$locale='l1_CO';}
}
return $locale;
}else{
if (isset($locale))
return apply_filters( 'locale', $locale );
}
//endmod
//mod
//if($_GET['l']=='l1'){$locale='l1_CO';}elseif($_GET['l']=='l2'){$locale='l2_CO';}else{$locale='l1_CO';}
//error_log(apply_filters( 'locale', $locale )."\r\n",3,'debuglog.txt');
//error_log($_GET['l']."\r\n",3,'debuglog.txt');
//error_log($locale."\r\n",3,'debuglog.txt');
//return 'l2_CO';
//endmod
//if (isset($locale))
// return apply_filters( 'locale', $locale );
//mod
//if (isset($locale)){
// error_log($locale.':',3,'debuglog.txt');
// $qwert=apply_filters( 'locale', $locale );
// //$qwert=apply_filters( 'locale', '43534' );
// error_log($qwert."\r\n",3,'debuglog.txt');
// return $qwert;
//}
//endmod
//mod
//return $locale;
//endmod
//mod
//error_log('$localewasnotset',3,'debuglog.txt');
//endmod
// WPLANG is defined in wp-config.
if (defined('WPLANG'))
$locale = WPLANG;
//mod
//error_log((isset($locale)?'1':'0').':'.$locale.':'.apply_filters('locale',$locale)."\r\n",3,'debuglog.txt');
//error_log((defined('WPLANG')?'1':'0').':'.$locale.':'.apply_filters('locale',$locale)."\r\n",3,'debuglog.txt');
//endmod
if (empty($locale))
$locale = 'en_US';
$locale = apply_filters('locale', $locale);
return $locale;
}
and in http://mu.wordpress.org/forums/topic.php?id=2042&page=2#post-67728 i have said:
"i have added "?l=en" like links to multilingual home theme. current language is saved in cookie."
but it is hard to modify multilingual home themes, so i want to change single language home themes.
but proper way is http://codex.wordpress.org/Plugin_API i think.
"&&!headers_sent()" is not in correct place in this code. may be it causes wrong language on some pages. it should be there:
if(!headers_sent())setcookie(...);
and it works without them at all.
this code sets multiple cookies.
fix:
global $locale, $flagkukiisset;
if($_GET['l']=='l1'){
$locale='l1_CO';
if($flagkukiisset==0)setcookie('forum_guest_language','Lang1',time()+365*24*60*60,'/','domain.tld');
$flagkukiisset=1;
}elseif($_GET['l']=='l2'){
$locale='l2_CO';
if($flagkukiisset==0)setcookie('forum_guest_language','Lang2',time()+365*24*60*60,'/','domain.tld');
$flagkukiisset=1;
}else{
...
new version of that file to download, with this fix and changes in readme file, but theme files are still 2.65 version: http://tmf.org.ru/download/file.php?id=30 . md5:019a16fdd944ee36dcf0d10835425388, 7z file size:54609bytes.