WPML

问题概述

当使用 WP User Manager 向个人资料添加自定义字段时,您可能会遇到以下问题:自定义字段的多选选项在 WPML 的字符串翻译中不可翻译。

临时解决方法

请在继续操作前确保已创建完整的网站备份。

1. 修复集成插件 (WPUM-WPML)

  • 打开 …/wp-content/plugins/wpum-wpml/includes/class-wpum-wpml-fields.php 文件。
  • 找到第 20 行。
  • 将:
    PHP
    add_action( 'update_wpum_field_meta', array( $this, 'update_meta_strings' ), 10, 4 );
  • 替换为:
    PHP
    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 文件。
  • 找到第 56 行。
  • 将整个 get_formatted_output() 函数替换为:
    PHP
    public function get_formatted_output( $field, $value ) {
    
        $stored_field_options = $field->get_meta( 'dropdown_options' );
        $stored_options       = array();
        $stored_index         = array();
    
        // Keep the plugin's own guard.
        if ( ! is_array( $stored_field_options ) ) {
            return '';
        }
    
        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();
    
        // Keep the plugin's (array) cast.
        foreach ( (array) $value as $user_stored_value ) {
            if ( ! isset( $stored_options[ $user_stored_value ] ) ) {
                continue;
            }
    
            $label = $stored_options[ $user_stored_value ];
            $index = isset( $stored_index[ $user_stored_value ] ) ? $stored_index[ $user_stored_value ] : 0;
    
            $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 );
    }

所有已知问题

需要有关此问题的帮助?

提出支持问题,我们将与您一起调查。