Last active
November 24, 2020 18:08
-
-
Save timotheemoulin/262f829ced8eacfb1da499cee432e87e to your computer and use it in GitHub Desktop.
Force ACF fields loaded over JSON fiels to be translated though gettext
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 | |
/** | |
* Force ACF fields loaded over JSON fiels to be translated though gettext | |
*/ | |
add_filter( 'acf/load_field', | |
/** | |
* Force ACF to try to translate fields even when they come from JSON. | |
* | |
* @param array $field | |
* | |
* @return array | |
*/ | |
function ( array $field ): array { | |
$field['label'] = __( $field['label'] ?? '', 'custom-domain' ); | |
$field['instructions'] = __( $field['instructions'] ?? '', 'custom-domain' ); | |
$field['default_value'] = __( $field['default_value'] ?? '', 'custom-domain' ); | |
$field['placeholder'] = __( $field['placeholder'] ?? '', 'custom-domain' ); | |
$field['prepend'] = __( $field['prepend'] ?? '', 'custom-domain' ); | |
$field['append'] = __( $field['append'] ?? '', 'custom-domain' ); | |
return $field; | |
} | |
); | |
add_filter( 'acf/load_field_group', | |
/** | |
* Force ACF to try to translate groups even when they come from JSON. | |
* | |
* @param array $group | |
* | |
* @return array | |
*/ | |
function ( array $group ): array { | |
$group['title'] = __( $group['title'], 'custom-domain' ); | |
$group['description'] = __( $group['description'], 'custom-domain' ); | |
return $group; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment