I am working on some plugin in wordpress and I have following array and foreach loop with function in it.
Problem is that somehow I always getting $locale_key variable same as $code when $locale_key variable is inside function.
Please help.
$languages = array(
array('af', 'af', 'Afrikaans'),
array('ar', 'ar', 'العربية', 'rtl'),
array('az', 'az', 'Azərbaycan'),
array('be', 'bel', 'Беларуская мова'),
array('bg', 'bg_BG', 'български'),
array('bs', 'bs_BA', 'Bosanski'),
array('ca', 'ca', 'Català'),
array('cs', 'cs_CZ', 'Čeština'));
$lang = $_SESSION['lang'];
foreach ($languages as $key => $value) {
$locale_key = $languages[$key][1];
$code = $languages[$key][0];
echo $locale_key; // Here i get for example "bs_BA"
add_shortcode( $code, function($atts, $content = null, $locale_key) {
global $lang;
echo $locale_key; // And then here i get "bs"
if ($lang == $locale_key) {
return $content;
}
});
}
add_shortcode()your created function?