تخطي إلى المحتوى تخطي إلى الشريط الجانبي

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using WP User Manager to add custom fields to profiles, you might experience the following issue: options from multi-select custom fields are not translatable in WPML’s String Translation.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

1. Fix the integration plugin (WPUM-WPML)

  • Open the …/wp-content/plugins/wpum-wpml/includes/class-wpum-wpml-fields.php file.
  • Look for line 20.
  • Replace:
    add_action( 'update_wpum_field_meta', array( $this, 'update_meta_strings' ), 10, 4 );
            
  • With:
    add_action( 'updated_wpum_field_meta', array( $this, 'update_meta_strings' ), 10, 4 );
            
  • After that, go to Users > Custom fields, edit at least one of the multi-select field options, then navigate to WPML > String Translation to translate the values.

2. Fix the front-end output in WP User Manager

  • Open the …/wp-content/plugins/wp-user-manager/includes/fields/types/class-wpum-field-multiselect.php file.
  • Look for line .
  • Replace the entire get_formatted_output() function with:
    	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 );
    
    	}
            

اترك ردًا

الرجاء البقاء في الموضوع واحترام الآخرين. إذا كنت بحاجة إلى مساعدة في مشكلات غير متعلقة بهذا المنشور، استخدم منتدى الدعم الخاص بنا لبدء محادثة أو تقديم تذكرة.

يمكنك استخدام هذه الوسوم:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>