Panoramica del problema
Quando usi il tema Houzez con WPML e Traduzione stringhe, i testi tradotti nelle Theme Options del tema possono cambiare in un’altra lingua del sito dopo aver salvato le opzioni, anche quando nel pannello è selezionata la lingua corretta. I testi che non hai modificato in quel salvataggio vengono sovrascritti con la loro traduzione in un’altra lingua.
Soluzione alternativa
Prima di iniziare, esegui un backup completo del tuo sito e del database.
Passaggio 1 – Ripristina i testi nella lingua predefinita delle opzioni del tema
- Aggiungi questo codice al file functions.php del tuo tema:
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' ); }
- Dopo aver effettuato l’accesso come amministratore, apri la tua homepage con
?compsupp8287_fix=1alla fine dell’URL (ad esempiohttps://example.com/?compsupp8287_fix=1). Attendi finché non viene visualizzato un messaggio di conferma. - Rimuovi il codice di questo passaggio da functions.php.
Passaggio 2 – Previeni il problema nei salvataggi successivi
- Aggiungi questo codice al file functions.php del tuo tema e mantienilo:
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 ); }