From bbe3d18bb3ea7e4af48fb1ee2c7cce4fab560c5e Mon Sep 17 00:00:00 2001 From: Joaquim d'Souza Date: Tue, 7 Nov 2023 16:07:17 +0100 Subject: [PATCH] feat: add field for english user bio --- web/app/themes/awasqa/src/authors.php | 38 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/web/app/themes/awasqa/src/authors.php b/web/app/themes/awasqa/src/authors.php index f3514d9..d725a57 100644 --- a/web/app/themes/awasqa/src/authors.php +++ b/web/app/themes/awasqa/src/authors.php @@ -275,12 +275,31 @@ function handle_update_profile_pic($user_id) function extra_admin_user_fields($user) { + global $wpdb; + $user_id = $user->ID; $meta = get_user_meta($user_id); $image_id = $meta['awasqa_profile_pic_id'][0] ?? 0; $image_url = $image_id ? wp_get_attachment_image_src($image_id) : null; + + $sql = $wpdb->prepare( + 'SELECT id FROM wp_icl_strings WHERE context=%s AND name=%s', + "Authors", + "description_" . $user_id + ); + $cols = $wpdb->get_col($sql); + $string_id = $cols[0] ?? ""; ?>

Awasqa

+ + + + + +
+ + +
@@ -306,6 +325,19 @@ function awasqa_save_admin_user_fields($user_id) { if (current_user_can('edit_user', $user_id)) { handle_update_profile_pic($user_id); + + // Add translated bio + $spanish_description = $_POST['description'] ?? null; + $string_id = $_POST['form-translated-bio-string-id'] ?? null; + $english_description = $_POST['form-translated-bio'] ?? null; + if ($string_id) { + if ($spanish_description) { + icl_add_string_translation($string_id, 'es', $spanish_description, ICL_TM_COMPLETE); + } + if ($english_description) { + icl_add_string_translation($string_id, 'en', $english_description, ICL_TM_COMPLETE); + } + } } } add_action('personal_options_update', 'CommonKnowledge\WordPress\Awasqa\Authors\awasqa_save_admin_user_fields'); @@ -340,7 +372,7 @@ function do_avatar_column($val, $column_name, $user_id) } add_filter('manage_users_custom_column', 'CommonKnowledge\WordPress\Awasqa\Authors\do_avatar_column', 10, 3); -function get_translated_author_bio($author_id) +function get_translated_author_bio($author_id, $lang = null) { global $wpdb; @@ -352,8 +384,8 @@ function get_translated_author_bio($author_id) return $description; } - $lang = get_current_language('es'); + $lang = $lang ?? get_current_language('es'); $translations = icl_get_string_translations_by_id($string_id[0]); return $translations[$lang]['value'] ?? $description; -} \ No newline at end of file +}