WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Ajax & Polylang_Core::curlang (5 posts)

  1. nosurs
    Member
    Posted 1 year ago #

    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/

  2. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    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?

  3. nosurs
    Member
    Posted 1 year ago #

    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!

  4. nosurs
    Member
    Posted 1 year ago #

    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.

  5. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags