Home › Forums › ACF PRO › WPML, ACF 5.0.9 and Options Page › Reply To: WPML, ACF 5.0.9 and Options Page
Hi everyone,
I believe I have a more or less decent looking workaround for this issue, based on the same idea JoepR had. It allows you to mark any number of options pages as “global”, i.e. they are not translatable and will always display the options in the default language. All other options pages would remain translatable.
/**
* Create the options page that we will later set "global"
*/
acf_add_options_page(array(
'page_title' => 'Test',
'menu_title' => 'Test',
'menu_slug' => 'test',
));
/**
* Force ACF to use only the default language on some options pages
*/
function cl_set_global_options_pages($current_screen) {
// IDs of admin options pages that should be "global"
$page_ids = array(
"toplevel_page_acf-options-test"
);
if (in_array($current_screen->id, $page_ids)) {
add_filter('acf/settings/current_language', 'cl_acf_set_language', 100);
}
}
add_action( 'current_screen', 'cl_set_global_options_pages' );
function cl_acf_set_language() {
return acf_get_setting('default_language');
}
/**
* Wrapper around get_field() to get the "global" option values.
* This is the function you'll want to use in your templates instead of get_field() for "global" options.
*/
function get_global_option($name) {
add_filter('acf/settings/current_language', 'cl_acf_set_language', 100);
$option = get_field($name, 'option');
remove_filter('acf/settings/current_language', 'cl_acf_set_language', 100);
return $option;
}
I’d appreciate any feedback on the concept. Couldn’t figure out any scenarios where it would break, but maybe I missed something.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
π Weβre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.