Skip Navigation

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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Bruno Kos 1 year, 9 months ago.

Assisted by: Bruno Kos.

Author Posts
September 11, 2023 at 3:55 pm #14377977

Gauvain

Hello,

For a plugin that I develop, I need to get the description of a user in all active languages.
For the moment I loop through all the languages and I use this filter to get the desired translated description :

$languages = apply_filters( 'wpml_active_languages', NULL ); // Get all active languages
foreach ( $languages as $language ) {
$translated_description = apply_filters( 'wpml_translate_single_string', $user_description, 'Authors', 'description_' . $userID, $language['language_code'] );
}

The problem is, if the description is empty, this returns the description in the default language (like it is explained in the documentation of this filter).
If the description is empty in a certain language, I just want an empty string, not the default language one.

Is there a better solution for my problem or do I need to add something ?

September 12, 2023 at 3:18 pm #14385071

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

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

Hi,

Thank you for contacting WPML support!

There is no such option with that function. Perhaps you can code a condition to check if the passed value is the same as the returned one, basically you could use the hook to get the default language and then also compare the strings.

https://wpml.org/wpml-hook/wpml_default_language/, e.g.

$my_default_lang = apply_filters('wpml_default_language', NULL ); //get default language
$languages = apply_filters( 'wpml_active_languages', NULL ); // Get all active languages
foreach ( $languages as $language ) {
$translated_description = apply_filters( 'wpml_translate_single_string', $user_description, 'Authors', 'description_' . $userID, $language['language_code'] );
if ($user_description === $translated_description && $language !== $my_default_lang ){
$translated_description = "";
}

}

Additionally, you can always reach out our https://wpml.org/contractors/ for such work.

Regards,
Bruno Kos

September 13, 2023 at 8:10 am #14387771

Gauvain

Thanks, that was one of the solutions I had in mind, but if there is no other native solution for the moment it's ok that will suffice !