• Resolved nosurs

    (@nosurs)


    Hi,

    awesome plugin! Though after struggeling with ajax & polylang, I may have found an issue.

    Setup:
    Two languages (de,en), default is de.
    Pretty links are on.

    The ajax request:
    admin-ajax.php?action=…&pll_load_front=true&lang=en

    Issue:
    Polylang_Core::curlang after setup_theme() points to ‘de’, so pll_current_language() fails & the wrong lang id is injected to WPs SQL strings.

    What seems to be a solution is to add yours & g100g’s ajax check to the regex switch in Polylang_Core:setup_theme, line 233, so the second regex is triggered.

    http://wordpress.org/extend/plugins/polylang/

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

    (@chouby)

    You are right! I forgot ajax when I rewrote the code for the option “add language code to all urls” 🙁

    I propose to add this at the beginning of the function ‘setup_theme’:

    if (isset($_REQUEST['pll_load_front'])) {
    	$this->curlang =  isset($_REQUEST['lang']) && $_REQUEST['lang'] ? $this->get_language($_REQUEST['lang']) : $this->get_preferred_language();
    	do_action('pll_language_defined');
    	return;
    }

    Then the language is set the same way as it is with the option (language set from content). ‘get_preferred_language’ should return the language defined in the cookie. In this special case, I believe that I should not rely on the language code in the url. What’s your opinion on this?

    Thread Starter nosurs

    (@nosurs)

    Perfect! Works & spares the regex overhead. Many thanks.

    … though this won’t assign $GLOBALS['l10n']['pll_string'] – but I don’t know if this is of any relevance, unless polylang_mo is supposed to hold some user defined strings.

    Again: Thanks a lot!

    Thread Starter nosurs

    (@nosurs)

    In this special case, I believe that I should not rely on the language code in the url.

    Sorry, not my day today, have overlooked this somehow. Yes, you’re right – actually the language code would always be missing in the ajax call.

    BTW: Thanks for clarifying the use of get_preferred_language.

    Plugin Author Chouby

    (@chouby)

    Yes of course you are right, I should assign $GLOBALS['l10n']['pll_string']. That’s in v0.9.8.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Ajax & Polylang_Core::curlang’ is closed to new replies.