Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom field translation #950

Merged
merged 30 commits into from
May 6, 2020
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
06ca6c7
Added Custom Fields Translation fields and saved them to wp_options
micahmills Apr 21, 2020
acff445
added the translations to the default key
micahmills Apr 21, 2020
60a3783
use the translation that matches the users locale if available
micahmills Apr 21, 2020
2b4ecc0
cleaned up the Admin UI
micahmills Apr 21, 2020
e9a3402
changed most front end label usage to use the translated label
micahmills Apr 21, 2020
ed01de7
Merge branch 'upstream-master' into custom-field-translation
micahmills Apr 21, 2020
a822e3e
added translation fields to Field Settings.
micahmills Apr 22, 2020
ae8243b
Revert "changed most front end label usage to use the translated label"
micahmills Apr 27, 2020
60363a0
change the label or name to use the Custom translation based on users…
micahmills Apr 27, 2020
5a8dce6
removes errant dt_write_log statment
micahmills Apr 27, 2020
10a865d
Fixed Field Settings translations saving
micahmills Apr 27, 2020
786a56e
fixed for the translation Admin UI
micahmills Apr 27, 2020
28f3e8e
code styling bug
micahmills Apr 27, 2020
876c90b
Merge branch 'upstream-master' into custom-field-translation
micahmills Apr 27, 2020
37c3fdd
Merge branch 'upstream-master' into custom-field-translation
micahmills May 1, 2020
2dec6c3
Added English to the Translation langauges list and got rid of an lef…
micahmills May 1, 2020
277bc0f
adds a check to see if the page is an admin page. If not it does not …
micahmills May 1, 2020
4c3ebaa
Adds English to the languages so that an english translation if there…
micahmills May 1, 2020
7cda524
Merge branch 'upstream-master' into custom-field-translation
micahmills May 1, 2020
467ef39
did an npm install to fix Travis issues
micahmills May 1, 2020
37df031
addded translations to Custom Tile Names
micahmills May 1, 2020
919c856
aligned Custom Tile Name UI with Custom Fields UI
micahmills May 1, 2020
dbcd608
made the + button toggle when clicked
micahmills May 1, 2020
00993c3
adds custom translations for Contact Channels
micahmills May 4, 2020
55c9af9
fixed a bug that kept the english translation for custom fields wasn'…
micahmills May 4, 2020
dbfa098
Added English to the dt_get_available_lanuages function and removed t…
micahmills May 5, 2020
5061c18
nested everything under a translation key
micahmills May 5, 2020
94ec028
Created a central location for post hook. Moved the custom translatio…
corsacca May 6, 2020
0ff1aec
Added translations for field keys in groups and custom post types
micahmills May 6, 2020
fa0a757
Moved field key names under a translation key, and fixed a bug that c…
micahmills May 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added Custom Fields Translation fields and saved them to wp_options
  • Loading branch information
micahmills committed Apr 21, 2020
commit 06ca6c732d384e52a464ad65c84f54aea05a88fa
36 changes: 30 additions & 6 deletions dt-core/admin/menu/tabs/tab-custom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function content( $tab ) {
return;
}
$post_submission = [];

foreach ( $_POST as $key => $value ){
$post_submission[sanitize_text_field( wp_unslash( $key ) )] = sanitize_text_field( wp_unslash( $value ) );
}
Expand Down Expand Up @@ -216,6 +217,7 @@ private function edit_field( $field_key, $post_type ){
}

$field_options = $field["default"];

$first = true;
$tile_options = dt_get_option( "dt_custom_tiles" );
$sections = apply_filters( 'dt_details_additional_section_ids', [], $post_type );
Expand Down Expand Up @@ -310,6 +312,7 @@ private function edit_field( $field_key, $post_type ){
</thead>
<tbody>
<?php foreach ( $field_options as $key => $option ) :

if ( !( isset( $option["deleted"] ) && $option["deleted"] == true ) ):
$label = $option["label"] ?? "";
$in_defaults = isset( $defaults[$field_key]["default"][$key] );
Expand All @@ -333,6 +336,17 @@ private function edit_field( $field_key, $post_type ){
<button type="submit" name="delete_option" value="<?php echo esc_html( $key ) ?>" class="button small" ><?php esc_html_e( "Hide", 'disciple_tools' ) ?></button>
<?php endif; ?>
</td>
<td>
<?php
$langs = dt_get_available_languages();
foreach ( $langs as $lang => $val ) : ?>
<div class="<?php echo esc_html( $val['language'] )?>">
<label for="field_option_<?php echo esc_html( $key )?>_translation_<?php echo esc_html( $val['language'] )?>"><?php echo esc_html( $val['native_name'] )?>
<input name="field_option_<?php echo esc_html( $key )?>_translation_<?php echo esc_html( $val['language'] )?>" type="text" value="<?php echo esc_html( $custom_fields[$post_type][$field_key][$key][$val['language']] ?? "" );?>"/>
</label>
</div>
<?php endforeach; ?>
</td>
</tr>
<?php $first = false;
endif;
Expand Down Expand Up @@ -376,7 +390,6 @@ private function process_edit_field( $post_submission ){
//save values
$post_type = $post_submission["post_type"];
$post_fields = $this->get_post_fields( $post_type );

$field_customizations = dt_get_option( "dt_field_customizations" );
$field_key = $post_submission["field_key"];
if ( isset( $post_submission["delete"] ) ){
Expand Down Expand Up @@ -408,12 +421,23 @@ private function process_edit_field( $post_submission ){
if ( $field["type"] === 'multi_select' || $field["type"] === "key_select" ){
foreach ( $post_submission as $key => $val ){
if ( strpos( $key, "field_option_" ) === 0 ){
$option_key = substr( $key, 13 );
if ( isset( $field_options[$option_key]["label"] ) ){
if ( $field_options[$option_key]["label"] != $val ){
$custom_field["default"][$option_key]["label"] = $val;
if ( strpos( $key, 'translation' ) !== false ) {
$option_key = substr( $key, 13, strpos( $key, 'translation' ) - 14 );
$translation_langcode = substr( $key, -5 );
if ( strpos( $translation_langcode, '_' ) !== false ) {
$translation_langcode = substr( $translation_langcode, 3 );
}

$field_options[$option_key][$translation_langcode] = $val;
$custom_field[$option_key][$translation_langcode] = $val;
} else {
$option_key = substr( $key, 13 );
if ( isset( $field_options[$option_key]["label"] ) ){
if ( $field_options[$option_key]["label"] != $val ){
$custom_field[$option_key]["label"] = $val;
}
$field_options[$option_key]["label"] = $val;
}
$field_options[$option_key]["label"] = $val;
}
}
}
Expand Down