Skip Navigation

Open

Reported for: WPML Multilingual CMS 4.6.12

Topic Tags: Compatibility

Overview of the issue

You may encounter an issue where pages are not marked as translated after completing the translation to 100% using WPML with the Divi theme. Additionally, the following error may be logged:

PHP Fatal error:  Uncaught TypeError: htmlspecialchars_decode(): Argument #1 ($string) must be of type string, array given in .../wp-content/plugins/sitepress-multilingual-cms/addons/wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-update-shortcodes-in-content.php:203

Workaround

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

  • Open …/wp-content/plugins/sitepress-multilingual-cms/addons/wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-update-shortcodes-in-content.php file.
  • Look for line 206.
  • Replace:
    		if ( 'allow_html_tags' !== $encoding ) {
    			$translation = htmlspecialchars( htmlspecialchars_decode( $translation ) );
    		}
    
  • With:
    		// Ensure $translation is a string
    		if (is_array($translation)) {
    			// Handle array to string conversion as needed
    			$translation = implode('', $translation);
    		}
    
    		if ( 'allow_html_tags' !== $encoding ) {
    			$translation = htmlspecialchars( htmlspecialchars_decode( $translation ) );
    		}
    

4 Responses to “Divi - PHP 8.2 Fatal error: Uncaught TypeError: htmlspecialchars_decode()...”

  1. Hi,

    I faced same issue and it was solved with the provided code replacement.

    My template is custom template and I have some custom wpbakery elements were added to the translation editor using WPML XML.

    • Hello there,
      I’m glad to know that the code here provided helped. 🙂
      We will keep you updated once it is addressed.

  2. Hi,

    I just want to note that am using the following filter to make some of my custom wpbakery elements translatable:


    add_filter( 'wpml_pb_shortcode_encode', 'wpml_pb_shortcode_encode_urlencoded_json', 10, 3 );
    function wpml_pb_shortcode_encode_urlencoded_json( $string, $encoding, $original_string ) {
    if ( 'urlencoded_json' === $encoding ) {
    $output = array();
    foreach ( $original_string as $combined_key => $value ) {
    $parts = explode( '_', $combined_key );
    $i = array_pop( $parts );
    $key = implode( '_', $parts );
    $output[ $i ][ $key ] = $value;
    }
    $string = urlencode( json_encode( $output ) );
    }
    return $string;
    }

    add_filter( 'wpml_pb_shortcode_decode', 'wpml_pb_shortcode_decode_urlencoded_json', 10, 3 );
    function wpml_pb_shortcode_decode_urlencoded_json( $string, $encoding, $original_string ) {
    if ( 'urlencoded_json' === $encoding ) {
    $rows = json_decode( urldecode( $original_string ), true );
    $string = array();
    foreach ( $rows as $i => $row ) {
    foreach ( $row as $key => $value ) {
    if ( in_array( $key, array( 'text', 'title', 'features', 'substring', 'btn_text', 'label', 'value', 'y_values', 'option_text' ) ) ) {
    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
    } else {
    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
    }
    }
    }
    }
    return $string;
    }

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>