Last active
May 17, 2017 08:08
-
-
Save pierre-dargham/5904d48e75a4d859e25f1352e328f187 to your computer and use it in GitHub Desktop.
acf-translate-field-groups.php
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 | |
namespace Globalis\ACF; | |
add_filter('acf/get_field_group', __NAMESPACE__ . '\\acf_translate_field_group'); | |
add_filter('acf/load_field', __NAMESPACE__ . '\\acf_translate_field'); | |
function acf_translate_field_group($field_group) { | |
if(is_acf_admin()) { | |
return $field_group; | |
} | |
$field_group['title'] = __($field_group['title'], 'my-text-domain'); | |
return $field_group; | |
} | |
function acf_translate_field($field) { | |
if(is_acf_admin()) { | |
return $field; | |
} | |
$keys = [ | |
'label', | |
'instructions', | |
'message', | |
'button_label', | |
'placeholder', | |
'prepend', | |
'append', | |
'message', | |
'default_value', | |
]; | |
$arrays = [ | |
'choices', | |
]; | |
foreach($keys as $key) { | |
if(isset($field[$key])) { | |
$field[$key] = __($field[$key], 'my-text-domain'); | |
} | |
} | |
foreach($arrays as $array_name) { | |
if(isset($field[$array_name])) { | |
foreach($field[$array_name] as $key => $value) { | |
$field[$array_name][$key] = __($value, 'my-text-domain'); | |
} | |
} | |
} | |
return $field; | |
} | |
function is_acf_admin() { | |
if(defined('DOING_AJAX') && DOING_AJAX) { | |
return true; | |
} | |
if(isset($_GET['post']) && 'acf-field-group' == get_post_type($_GET['post'])) { | |
return true; | |
} | |
if(isset($_POST['post_type']) && 'acf-field-group' == $_POST['post_type']) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment