Skip Navigation

Resolved by author

Resolved in: Impreza 8.18.5

Topic Tags: Compatibility

Overview of the issue

With the Impreza theme, when using certain widgets like Action box, Icon box, Text, etc., and assigning URLs to them, these URLs appear encoded in WPML’s Advanced Translation Editor, making their translation complicated.

You may see also a similar error:
htmlspecialchars_decode(): Argument #1 ($string) must be of type string, array given .../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 backup of your site before proceeding.

  • Open the …/wp-content/plugins/us-core/plugins-support/wpml.php file.
  • Look for line 42.
  • Replace the code related to the wpml_pb_shortcode_encode_us_link and wpml_pb_shortcode_decode_us_link with:
    if ( ! function_exists( 'wpml_pb_shortcode_encode_us_link' ) ) {
    	/**
    	 * Add support for "link" control
    	 *
    	 * @param string $string
    	 * @param string $encoding
    	 * @param string $original_string
    	 * @return string
    	 */
    	function wpml_pb_shortcode_encode_us_link( $string, $encoding, $original_string ) {
    		if ( 'us_link' === $encoding ) {
    			$output = array();
    			
    			//In translation we can save the new encoding method only i.e. JSON.
    			foreach ( $string as $combined_key => $value ) {
    				$parts = explode( '_', $combined_key );
    				$i = array_pop( $parts );
    				$key = implode( '_', $parts );
    				$cleaned_keys[ $i ][ $key ] = $value;
    			}
    	 
    			foreach ( $cleaned_keys as $subkey ) {
    				foreach ( $subkey as $key => $value ) {
    					$output[$key] = $value;
    				}   
    			}
    	 
    			$string = urlencode(json_encode($output));
    		}
    		return $string; 
    	}
    	add_filter( 'wpml_pb_shortcode_encode', 'wpml_pb_shortcode_encode_us_link', 10, 3 );
    }
    
    if ( ! function_exists( 'wpml_pb_shortcode_decode_us_link' ) ) {
    	/**
    	 * Add support for "link" control
    	 *
    	 * @param string $string
    	 * @param string $encoding
    	 * @param string $original_string
    	 * @return array
    	 */
    	function wpml_pb_shortcode_decode_us_link( $string, $encoding, $original_string ) {
    		if ( 'us_link' === $encoding ) {
    
    			$original_string = urldecode( $original_string );
    			$is_json = true;
    			$strings = json_decode($original_string);
    			$string = [];
    			
    			// There are two types of encoding, the new method uses JSON and old method uses custom encoding.
    			if ($strings === NULL) {
    				$is_json = false;
    				$strings = explode("|", $original_string);
    			}
    			
    			foreach ( $strings as $i => $value ) {
    				if ($is_json) {
    					$rows[][$i] = $value;
    				} else {
    					$item =  explode(":", $value);
    					$key = $item[0];
    					unset($item[0]);
    		
    					$value = implode(":", $item);
    					$row[$key] = $value;
    					$rows[] = $row;
    		
    					unset($row[$key]);
    				}
    				
    			}
    	 
    			foreach ( $rows as $i => $row ) {
    				foreach ( $row as $key => $value ) {
    					if ( $key == 'url'  ) {
    						$string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
    					} else {
    						$string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
    					}
    				}
    			}
    		}
    		return $string; 
    	}
    	add_filter( 'wpml_pb_shortcode_decode', 'wpml_pb_shortcode_decode_us_link', 10, 3 );
    }
    
  • Add a small modification on the original page, then translate it

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>