Support » Plugin: WP Multilang » Removing the backslash (\) from JSON

  • Breaks the unicode escape sequence in JSON by removing the backslash (\) from them.
    I use the plugin Block Lab. When saving HTML in the fields of the block, the backslash is removed for all languages except the one being edited.
    Example: \u003c -> u003c

    Temporarily wrote a very bad code. Sorry about that ^_^

    In the existing function of the plugin added:

    
    function wpm_translate_string( $string, $language = '' ) {
    
    	$string = bad_fix_wpml_save_post_srt( $string );
    ...
    

    And

    function bad_fix_wpml_save_post_srt($str) {
    	// Find all occurrences of uXXYY,
    	// Where XX - numbers, YY - numbers and/or letters (otherwise you can hit the entries of words like "upload"), before which there is no backslash
    	// we are interested in < / > " =
    	// respectively \u003c \u002f \u003e \u0022 \u003d
    	$pattern1 = '/([^\\\])(u[0-9]{2}[A-Za-z0-9]{2})/u';
    	$replacement1 = '$1'.'\\\\'.'$2';
    	$str = preg_replace( $pattern1, $replacement1, $str );
    
    	$pattern2 = '/(u[0-9]{2}[a-zA-Z0-9]{2})(nt+|n)/u';
    	$replacement2 = '$1';
    	$str = preg_replace( $pattern2, $replacement2, $str );
    
    	$str = str_replace(
            array('***n', 'n***', '::n', 'u0026bsp;', ''),
            array('***', '***', '::', 'u0026nbsp;', ''),
    		$str
        );
    
    	return $str;
    }
    
  • The topic ‘Removing the backslash (\) from JSON’ is closed to new replies.