Übersicht über das Problem
Wenn Sie das Theme Houzez mit WPML und der String-Übersetzung verwenden, können übersetzte Texte in den Theme-Optionen des Themes nach dem Speichern der Optionen zu einer anderen Websitesprache wechseln, selbst wenn im Panel die richtige Sprache ausgewählt ist. Die Texte, die Sie bei diesem Speichervorgang nicht geändert haben, werden mit ihrer Übersetzung in einer anderen Sprache überschrieben.
Problemumgehung
Bevor Sie beginnen, erstellen Sie ein vollständiges Backup Ihrer Website und Datenbank.
Schritt 1 – Stellen Sie die Texte der Theme-Optionen in der Standardsprache wieder her
- Fügen Sie diesen Code zur Datei functions.php Ihres Themes hinzu:
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' ); }
- Während Sie als Administrator angemeldet sind, öffnen Sie Ihre Startseite mit
?compsupp8287_fix=1am Ende der URL (zum Beispielhttps://example.com/?compsupp8287_fix=1). Warten Sie, bis eine Bestätigungsnachricht angezeigt wird. - Entfernen Sie den Code aus diesem Schritt aus der functions.php.
Schritt 2 – Verhindern Sie das Problem bei den nächsten Speichervorgängen
- Fügen Sie diesen Code zur Datei functions.php Ihres Themes hinzu und behalten Sie ihn dort:
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 ); }