- 状态
- 等待作者
- 相关插件/主题
- WP User Manager
- 主题标签
- Compatibility
问题概述
当使用 WP User Manager 向个人资料添加自定义字段时,您可能会遇到以下问题:自定义字段的多选选项在 WPML 的字符串翻译中不可翻译。
临时解决方法
请在继续操作前确保已创建完整的网站备份。
1. 修复集成插件 (WPUM-WPML)
- 打开 …/wp-content/plugins/wpum-wpml/includes/class-wpum-wpml-fields.php 文件。
- 找到第 20 行。
- 将:
add_action( 'update_wpum_field_meta', array( $this, 'update_meta_strings' ), 10, 4 );
- 替换为:
add_action( 'updated_wpum_field_meta', array( $this, 'update_meta_strings' ), 10, 4 );
- 之后,转到用户 > 自定义字段,编辑至少一个多选字段选项,然后导航至 WPML > 字符串翻译以翻译这些值。
2. 修复 WP User Manager 中的前端输出
- 打开 …/wp-content/plugins/wp-user-manager/includes/fields/types/class-wpum-field-multiselect.php 文件。
- 找到对应的行。
- 将整个
get_formatted_output()函数替换为:
public function get_formatted_output( $field, $value ) { $stored_field_options = $field->get_meta( 'dropdown_options' ); $stored_options = array(); $stored_index = array(); // Build lookup maps: value => label and value => original index foreach ( $stored_field_options as $key => $stored_option ) { $val = isset( $stored_option['value'] ) ? $stored_option['value'] : $key; $lbl = isset( $stored_option['label'] ) ? $stored_option['label'] : ''; $stored_options[ $val ] = $lbl; $stored_index[ $val ] = $key; } $values = array(); foreach ( $value as $user_stored_value ) { if ( ! isset( $stored_options[ $user_stored_value ] ) ) { continue; } $label = $stored_options[ $user_stored_value ]; // Determine original index for this option so we can match textdomain package $index = isset( $stored_index[ $user_stored_value ] ) ? $stored_index[ $user_stored_value ] : 0; // Translation via WPML. $translated_label = apply_filters( 'wpml_translate_single_string', $label, 'wpum-fields-wpum-field-' . $field->get_ID(), 'wpum-field-dropdown_options_' . $index ); $values[] = $translated_label; } return implode( ', ', $values ); }