Plugin Author
Chouby
(@chouby)
The current language is obtained by the function pll_current_language
There is no currently API function to get all available languages (I have to improve this). So you need to use Polylang internal function.
global $polylang;
$languages = $polylang->model->get_languages_list();
You thus get an array of PLL_Language objects with properties documented in polylang/include/language.php among those most interesting are ‘slug’ and ‘locale’.
If you are familiar with WPML, you can use ‘icl_get_languages’ too.
What can be the reason for pll_current_language('slug') to return null?
Do I need to do something else first?
Plugin Author
Chouby
(@chouby)
The function does not return any language when the current language has not been set yet.
The current language is set very soon (‘plugins_loaded’ action) when the language is set from url but quite late (‘wp’ action) when it is set from content.
However, you may not need to bother with all the cases as Polylang fires the action ‘pll_language_defined’ when the current language is set.
Thank you, Chouby! With these pointers and a little research I was able to get the Polylang integration in the EU Cookie Law Compliance plugin to work again.
See this topic for what I did…