• Resolved soerenhahnert

    (@soerenhahnert)


    Hey, i guess i find a little bug in includes/core.php

    I called set_post_language in an own plugin an always got an error, that $lang is not set in core.php on 228.

    i saw that you check if lang is false and if yes return the preferred language.
    So, it’s not pain to change

    function pll_get_current_language($lang) {
    		return !$lang ? $this->get_preferred_language() : $lang;
    	}

    to

    function pll_get_current_language($lang = false) {
    		return !$lang ? $this->get_preferred_language() : $lang;
    	}

    Cheers!

    https://www.ads-software.com/extend/plugins/polylang/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Chouby

    (@chouby)

    The function ‘pll_get_current_language’ is not intended for other use than internal one. This is a default filter for the hook of the same name and always receive a parameter.
    If you want to get the current language, you should use the function ‘pll_current_language’ (without ‘get’) from the API. You can also use the standard functions of WordPress such as ‘get_locale’ or ‘bloginfo’.

    Thread Starter soerenhahnert

    (@soerenhahnert)

    Read again please! I’m not using get_current_language. I’m using set_post_language.

    Plugin Author Chouby

    (@chouby)

    Sorry, I missed that point. But which parameter do you use for the language in ‘set_post_language’ ? This function does not know the current language and is expecting that you specify it.

    Thread Starter soerenhahnert

    (@soerenhahnert)

    Ok, my fault so far. I saw it in the moment i postet my line of code. Mixed up the file versions.

    Plugin Author Chouby

    (@chouby)

    So we come back to my first answer ??
    try:

    $polylang->set_post_language($post_id, pll_current_language());

    NB: take care to “when” the current language is defined:
    in ‘plugins_loaded’ hook if you have the language code in all urls.
    in ‘wp’ hook if the language is set from content.

    Thread Starter soerenhahnert

    (@soerenhahnert)

    pll_current_language works fine.

    Thread Starter soerenhahnert

    (@soerenhahnert)

    ***SOLVED***

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Little Bug in core.php’ is closed to new replies.