php – Polylang Bug with pll_get_post..?

I’m not sure if this is a bug or if I’m doing something wrong, but I suppose that there’s something wrong with the polylang plugin function pll_get_post(). The problem is that, when I use a PHP form submit, and at the end of that form submit, I want to redirect using pll_get_post(), this fails if I do the following:

header( 'Location: '. get_the_permalink( pll_get_post( 1234 ) ) );

First, function_exists( 'pll_get_post' ) called in the part of the form submit script returns true, so we have the function available. Then, I checked on the error and discovered that it occurred because pll_get_post() returned null here. According to the doc, this happens if the language it uses to retrieve the specified post could not be found. The doc linked above actually says that the second parameter of pll_get_post() is:

“Language code, defaults to current language”

which means that pll for some reason fails to retrieve the correct locale of the executing page X, if it’s being called in a PHP Form submit script, called via that page X. When I do this in an AJAX script, which in theory is also only indirectly tied to a language-specific page X, which fires the request (just as for the form submit); interestingly everything works. My workaround attempt for this was:

header( 'Location: '. get_the_permalink( pll_get_post( 1234, substr( get_locale(), 0, 2 ) ) ) );

And, by retrieving the locale language code explicitly in this way, the script and redirect worked perfectly. So I suppose that’s a bug which is not supposed to happen? Or does anyone know why this happens, and I’m missing sth out?