This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to translate and display user custom fields created with Toolset types.

Solution:

For anyone, who landed here with the exact same problem. Here the steps for adding Types custom-user-fields to WPMLS string-translation:

1) Put this filter into functions.php and add ALL user-fields, which should be translated:

add_filter( 'wpml_translatable_user_meta_fields', 'add_usermeta', 99);
function add_usermeta( $fields ) {
    $fields = array('description','wpcf-my-custom-field');
    return $fields;
} 

2) Add the shortcode for displaying the user-fields in functions.php

add_shortcode( 'user-meta', 'user_meta_func');
function user_meta_func($atts) {
  $key = $atts['key'];
  $id =  $atts['id'];
  return get_the_author_meta($key, $id);
}

3) Add the shortcode in Toolset (Settings > Frontend > Shortcode-Arguments)
4) Add the shortcode wherever your fields should appear (in View, Layout, Page ...)

[user-meta id="[wpv-user field='ID']" key="description"]
[user-meta id="[wpv-user field='ID']" key="wpcf-my-custom-field"]

Relevant Documentation:

This topic contains 22 replies, has 2 voices.

Last updated by Yvette 1 year, 11 months ago.

Assigned support staff: Yvette.

Author Posts
May 10, 2017 at 9:52 am #1272579

Diana

Hello Yvette! Please note my last question as the first one – my second one follows:

In the meanwhile I got help from the Toolsets forum. They gave me the custom code for a shortcode to place the user-fields. And this works out for the custom-user-fields – they are showing up in the right language now. But not for the standard-WP-user-fields – they are still in my standard language.

I already tried to unmark and remark these standard-WP-strings as "translation finished". Didn't work. So I deleted some of them and wanted to translate them again. But after deleting the strings they didn't come back for translation (wether in the domain "authors" nor in any other). For bringing back the strings, I already tried to:
* save the user with different inputs in these fields
* saved the view again, where these fields are shown
* unchecked and rechecked the role "editor" for translation
* unchecked and rechecked the domain "authors" for "auto-marking for translation"
* scanned the themes for strings

Nothing helped to bring back these strings. Any ideas?

And here the shortcode for those, who are searching for a way to place the custom-user-meta:

add_shortcode( 'get_user_meta', 'get_user_meta_func');
function get_user_meta_func($atts) {
  $key = $atts['key'];
  $id =  $atts['id'];
  return get_the_author_meta($key, $id);
}

And the shortcode has to be placed in this way:

[get_user_meta id="[wpv-user field='ID']" key="first_name"]
[get_user_meta id="[wpv-user field='ID']" key="wpcf-MYCOSTOMFIELD"]

First one for standard-WP user-fields, second one for custom-user-fields which are created by Toolset Types.

May 10, 2017 at 4:09 pm #1273039

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Hi there,

I got an internal message today from Christian with this same news! Great - I´m afraid you got caught in that grey area between the two products which in fact should not exist.

My responses to your questions:
1. So that isn't a supported feature as well for the WP-default-user-fields?
Answer: yes normally but I am going to double check now.

2. Or in which way do I have to include the fields in my Views. Which shortcode does the trick for these fields?
You might have to consult Christian again on this point. I can check about the automatic registration and aviailability of the default user-meta for translation but my know-ow on views is not where you need it to be (unfortunately).

3. Making the strings appear again.
I will be looking at this now.

May 11, 2017 at 8:42 am #1273551

Diana

Hey Yvette,
yes, please check 3) I now updated the site which you have credentials for and deleted the WP-standard-user-fields for my user with ID 10. These fields are:

* display_name_10
* description_10
* nickname_10
* last_name_10
* first_name_10

I can't get them back to string-translation. (In my last post you can read, what I already did to try to bring them back ...) Hope you can find a solution for that.

Christian on the Toolsets Forum tried the shortcode for both types of user-fields, the custom ones and the WP-standard ones. And it should work. So I assume, the problem here is in WPML. If we could bring these strings back in the string-translation, I hope, my problem would be solved ... Thanks for checking!

May 12, 2017 at 12:17 am #1274346

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Ok. Sorry this took so long.

I had to temporarily change the WPML default language to "EN" and then once again select the "Apply" to register the user options on the String Translation screen (see image)

This finally added the deleted strings again.

May 12, 2017 at 9:25 am #1274589

Diana

Sorry, Yvette, but this didn't work for me.

First of all: You brought back most of the standard-fields, but not the "description_10". This field (and the description-fields of all other new users) is missing yet.

And the second issue: I saw, that the field "first_name_10" was wrong in the default language. So I tried to edit this field in the users-page. Normally the edited content should show off automatically in the string-translation with the new content and the translation should be marked as "not finished" automatically. Am I right? That's not what happened.

So I again had to delete this string "first_name_10" and wanted to bring the new string back in again. I tried to set the WPML-default-language to "EN" and un- and remarked the role editor with "apply" (as shown in your screenshot). But the string doesn't reappear. Tried to unmark the role, edited the user afterwards and then marked the role again. Didn't reappear.

I'm wondering if there isn't an easier way to let these fields appear automatically?
Is there a filter for the standard-user fields, where I can declare the needed fields?
Something similar to:

add_filter( 'wpml_translatable_user_STANDARD_fields', function( $fields ) {
    $fields = array('first_name', 'description');
    return $fields;
} );
May 12, 2017 at 10:22 am #1274668

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Hmmm.

On my test system this is very straightforward :

1. I only have to select the "Apply" button for deleted strings to reappear
2. New strings are automatically added / changed in the String Translation table when changes are made to the user profiles.

This is the expected behaviour. So, I changed your active theme temporarily to Twenty Fourteen and selected the "Apply" button and the fields appeared automatically.

Conclusion: This seems to be a theme compatibility issue. Last night, I had been using a standard Wodpress theme to troubleshoot and did not realise it was also signalling a compatibility issue with your normal theme.

I will need to test on my test system if having the default language <> EN also interferes with the automatic updating of the Author domain with user-meta information. If it does, then this is a bug or not-so-nice feature (depending on how developers want to handle). If it does not, then it is also a theme compatibility issue.

I wait for your comments

May 13, 2017 at 9:23 am #1275274

Diana

Thanks Yvette,
for your investigation. I did a few tests and you are right, the problem is with my template. It was within the custom filter for the translatable custom-user-fields. On the Toolsets Forum I was told to not add the standard-wp-user-fields in this code, just the custom-user-fields. But this broke the string-translation for the standard-wp-user-fields.

I had to add all user-fields to the filter – now they are reappearing again and are marked as "translation has to be updated", whenever a field changes. Everything works fine now!

And finally this did the trick also for my Frontend.
Now both types of user-fields are translated in Frontend also!

For anyone, who landed here with the exact same problem. Here the steps for adding Types custom-user-fields to WPMLS string-translation:

1) Put this filter into functions.php and add ALL user-fields, which should be translated:

add_filter( 'wpml_translatable_user_meta_fields', 'add_usermeta', 99);
function add_usermeta( $fields ) {
    $fields = array('description','wpcf-my-custom-field');
    return $fields;
} 

2) Add the shortcode for displaying the user-fields in functions.php

add_shortcode( 'user-meta', 'user_meta_func');
function user_meta_func($atts) {
  $key = $atts['key'];
  $id =  $atts['id'];
  return get_the_author_meta($key, $id);
}

3) Add the shortcode in Toolset (Settings > Frontend > Shortcode-Arguments)
4) Add the shortcode wherever your fields should appear (in View, Layout, Page ...)

[user-meta id="[wpv-user field='ID']" key="description"]
[user-meta id="[wpv-user field='ID']" key="wpcf-my-custom-field"]

Thanks again, Yvette, for your help!
You can mark this thread as solved now!
Best regards from Vienna, Diana

May 15, 2017 at 1:12 pm #1276159

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

THANK YOU SO MUCH. I am sure this summary will help other clients.