Open constip opened 5 years ago
Alternatively it might be a good idea to prefix the languages. Ex.: options_de_DE
becomes options__bea_de_DE
. This way it can easily be matched by __bea_.+
without risking wrong matches.
Hi @constip, thx for the issue.
To answer your both remarks :
Finally, to to be sure, are you facing any bug ?
@MaximeCulea yes. The problem is I use the language de_DE_formal
(but there would also be the same problem with many other languages, ex. af). Since your regex (the one you have linked again) only matches some languages, the language is not correctly removed. So in my example I get options_formal
. This is a problem when getting the defaults and this has messed up my site. That is why I opened this ticket.
I have only tested this with options-pages but my first solution seemed to work there...
Hi
I realize this is quite old issue, but especially concerning the latest updates in ACF, this is still relevant.
ACF 5.11.2 introduced the following change: _"get_field() and thefield() functions now are only able to access site options which are ACF fields"
This causes problems with languages that doesn't follow the standard language_COUNTRY -convention in locale. For example in our case Finnish locale is just fi
and the regex doesn't work for that. Thus ACF doesn't recognise that get_field()
call is for valid acf-field and returns null
.
For example we have one site with three languages (fi, sv_SE and enGB). Also we have set the data only in …&lang=all -page. So the fields in …&lang=fi, …&lang=sv and …&lang=en_ -pages are empty. get_field( 'option_name', 'options' )
returns data in _svSE and _enGB languages, but not for fi. We fixed the issue by saving the fi-options with empty values. Thus ACF will save option keys to the database and after that accept that get_field( 'option_name', 'options' )
is valid request for valid acf-field and returns the value.
Even though the fix was quite easy in our case, I think this bug should be fixed in the plugin. It can cause problems in the future, since the regex is so selective for the format of locale. Polylang has the list of different locales, so maybe you can use that one instead of preg_replace( '/(_[a-z]{2}_[A-Z]{2})/', '', $post_id )
🤔
We have noticed that Options are not properly retrieved in certain languages and I am confident I have narrowed it down to this line:
$_post_id = preg_replace( '/(_[a-z]{2}_[A-Z]{2})/', '', $post_id );
inclasses/main.php#61
BEA\ACF_Options_For_Polylang\Main::get_default_reference
Updating the regex to
sprintf( '/(_%s)/', pll_current_language( 'locale' ) )
should do the trick. This properly removes the current language, however it also means that the default can only be reached from the current language which might not be ideal...