Created
December 9, 2020 12:07
-
-
Save Langmans/58dfa4390e231825a3355a93d9c3b9b5 to your computer and use it in GitHub Desktop.
Advanced custom fields: make option pages with a custom post_id translatable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('acf/pre_load_post_id', | |
/** | |
* Fix all ACF option pages. acf-pro translates the default "options" page, but not option pages with a custom post_id | |
* | |
* @param string|null $return | |
* @param string|int $post_id | |
* | |
* @return null|string | |
* @see acf_get_valid_post_id | |
* @see acf_add_options_page | |
* @see acf_add_options_sub_page | |
*/ | |
static function ($return, $post_id) { | |
if ($return !== null) { | |
return $return; | |
} | |
$current_language_iso_code = acf_get_setting('current_language'); | |
$default_language_iso_code = acf_get_setting('default_language'); | |
if ($current_language_iso_code && $current_language_iso_code !== $default_language_iso_code) { | |
$pages = acf_get_options_pages(); | |
if (!is_array($pages)) { | |
$pages = []; | |
} | |
$option_pages_post_ids = array_map('strval', array_column($pages, 'post_id')); | |
if (in_array((string)$post_id, $option_pages_post_ids, true)) { | |
$return = $post_id . '_' . $current_language_iso_code; | |
//var_dump('acf/pre_load_post_id', compact('post_id', 'default_language_iso_code', 'current_language_iso_code', 'return')); | |
} | |
} | |
return $return; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment