WPML

Overview of the Issue

When using the Houzez theme with WPML and String Translation, translated texts in the theme’s Theme Options can change to another site language after you save the options, even when the correct language is selected in the panel. The texts you did not change in that save are overwritten with their translation in another language.

Workaround

Before you start, make a full backup of your site and database.

Step 1 – Restore the default-language texts of the Theme Options

  1. Add this code to your theme’s functions.php file:
    PHP
    // WPML workaround for compsupp-8287
    if ( ! function_exists( 'compsupp8287_restore_houzez_options' ) ) {
    	function compsupp8287_restore_houzez_options() {
    		if ( ! isset( $_GET['compsupp8287_fix'] ) || ! current_user_can( 'manage_options' ) ) {
    			return;
    		}
    
    		global $wpdb;
    
    		$default_language = apply_filters( 'wpml_default_language', null );
    
    		$rows = $wpdb->get_results(
    			$wpdb->prepare(
    				"SELECT s.id, s.name, s.value AS current_value, t.value AS correct_value
    				 FROM {$wpdb->prefix}icl_strings s
    				 JOIN {$wpdb->prefix}icl_string_translations t
    				   ON t.string_id = s.id AND t.language = %s
    				 WHERE s.context = 'admin_texts_houzez_options'
    				   AND s.value <> t.value",
    				$default_language
    			)
    		);
    
    		if ( empty( $rows ) ) {
    			wp_die( 'No corrupted fields found. Nothing to fix.' );
    		}
    
    		$raw_option = $wpdb->get_var(
    			"SELECT option_value FROM {$wpdb->options} WHERE option_name = 'houzez_options'"
    		);
    		$options = maybe_unserialize( $raw_option );
    
    		if ( ! is_array( $options ) ) {
    			wp_die( 'Could not read houzez_options. No changes made.' );
    		}
    
    		$changed = 0;
    
    		foreach ( $rows as $row ) {
    			if ( ! preg_match( '/^[houzez_options](.+)$/', $row->name, $m ) ) {
    				continue;
    			}
    
    			$field = $m[1];
    
    			if ( ( $options[ $field ] ?? null ) !== $row->correct_value ) {
    				$options[ $field ] = $row->correct_value;
    				$changed++;
    			}
    
    			$wpdb->update(
    				"{$wpdb->prefix}icl_strings",
    				array( 'value' => $row->correct_value ),
    				array( 'id' => $row->id )
    			);
    		}
    
    		update_option( 'houzez_options', $options );
    		delete_option( 'houzez_options-transients' );
    
    		wp_die( 'Restored ' . $changed . ' field(s). You may now remove this code from functions.php.' );
    	}
    	add_action( 'init', 'compsupp8287_restore_houzez_options' );
    }
  2. While logged in as an administrator, open your homepage with ?compsupp8287_fix=1 at the end of the URL (for example https://example.com/?compsupp8287_fix=1). Wait until a confirmation message shows.
  3. Remove the code of this step from functions.php.

Step 2 – Prevent the issue on the next saves

  1. Add this code to your theme’s functions.php file and keep it:
    PHP
    // WPML workaround for compsupp-8287
    // Prevents Theme Options translations from being overwritten with the wrong language on save.
    if ( ! function_exists( 'compsupp8287_skip_houzez_options_translation_filter' ) ) {
    	function compsupp8287_skip_houzez_options_translation_filter( $skip, $option_key ) {
    		if ( 'houzez_options' !== $option_key ) {
    			return $skip;
    		}
    
    		$is_redux_save_action = isset( $_REQUEST['action'] )
    			&& 'houzez_options_ajax_save' === $_REQUEST['action'];
    
    		if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && $is_redux_save_action ) {
    			return true;
    		}
    
    		return $skip;
    	}
    	add_filter( 'wpml_skip_admin_options_filters', 'compsupp8287_skip_houzez_options_translation_filter', 10, 2 );
    }

All known issues

Need Help with This Issue?

Ask a support question and we’ll look into it with you.