Type
1 week ago
FieldData.php
1 week ago
FieldTemplateLoader.php
1 week ago
FieldTranslator.php
1 week ago
Types.php
1 week ago
FieldTranslator.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FCF\Free\Field; |
| 4 | |
| 5 | use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 6 | |
| 7 | /** |
| 8 | * Supports translating field settings via external plugins. |
| 9 | */ |
| 10 | class FieldTranslator implements Hookable { |
| 11 | |
| 12 | /** |
| 13 | * {@inheritdoc} |
| 14 | */ |
| 15 | public function hooks() { |
| 16 | add_filter( 'flexible_checkout_fields_field_args', [ $this, 'translate_field' ], 10, 2 ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param mixed[] $field_data . |
| 21 | * @param string $field_name . |
| 22 | * |
| 23 | * @return mixed[] |
| 24 | */ |
| 25 | public function translate_field( $field_data, $field_name ) { |
| 26 | if ( isset( $field_data['label'] ) ) { |
| 27 | $field_data['label'] = wpdesk__( $field_data['label'], 'flexible-checkout-fields' ); |
| 28 | } |
| 29 | if ( isset( $field_data['placeholder'] ) ) { |
| 30 | $field_data['placeholder'] = wpdesk__( $field_data['placeholder'], 'flexible-checkout-fields' ); |
| 31 | } |
| 32 | if ( isset( $field_data['default'] ) ) { |
| 33 | $field_data['default'] = wpdesk__( $field_data['default'], 'flexible-checkout-fields' ); |
| 34 | } |
| 35 | if ( isset( $field_data['options'] ) ) { |
| 36 | foreach ( $field_data['options'] as $option_index => $option ) { |
| 37 | $field_data['options'][ $option_index ]['value'] = wpdesk__( $option['value'], 'flexible-checkout-fields' ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return $field_data; |
| 42 | } |
| 43 | } |
| 44 |